Exemplo n.º 1
0
    def test_user_and_room_with_many_schedules(self):
        new_user = User(name="Luiza")
        db.session.add(new_user)

        new_room = Room(name="Room")
        db.session.add(new_room)

        first_schedule = Schedule(date=datetime(2018, 10, 12),
                                  user=new_user,
                                  room=new_room)
        db.session.add(first_schedule)

        second_schedule = Schedule(date=datetime(2018, 10, 13),
                                   user=new_user,
                                   room=new_room)
        db.session.add(second_schedule)

        db.session.commit()

        user = User.query.one()
        room = Room.query.one()

        self.assertEqual(len(user.schedules), 2)
        self.assertEqual(len(room.schedules), 2)

        self.assertEqual(user.schedules[0].date, datetime(2018, 10, 12).date())
        self.assertEqual(user.schedules[1].date, datetime(2018, 10, 13).date())

        self.assertEqual(room.schedules[0].date, datetime(2018, 10, 12).date())
        self.assertEqual(room.schedules[1].date, datetime(2018, 10, 13).date())
Exemplo n.º 2
0
    def post(self):
        args = get_args()

        if check_schedule(args):
            return response("There is a conflict in schedule", 409)

        schedule = Schedule()
        fill_schedule(schedule, args)
        schedule.active = True
        schedule.lastUpdate = datetime.now()
        schedule.update()
        return schema.dump(schedule).data, 201
Exemplo n.º 3
0
    def test_common(self):
        new_user = User(name="Luiza")
        db.session.add(new_user)

        new_room = Room(name="Room")
        db.session.add(new_room)

        new_schedule = Schedule(date=datetime(2018, 10, 12),
                                user=new_user,
                                room=new_room)
        db.session.add(new_schedule)

        db.session.commit()

        schedule = Schedule.query.one()
        self.assertEqual(schedule.date, datetime(2018, 10, 12).date())
        self.assertEqual(schedule.user.name, "Luiza")
        self.assertEqual(schedule.room.name, "Room")
Exemplo n.º 4
0
def create_schedule(cid):
    course = Course.query.filter_by(cid=cid).first_or_404()
    form = ScheduleCreateForm().validate_for_api()
    with db.auto_commit():
        schedule = Schedule(week=form.week.data,
                            topic=form.topic.data,
                            reference=form.reference.data,
                            course_id=course.cid,
                            additional_info=form.additional_info.data,
                            datetime=form.datetime.data)
        resources = CourseResource.query.filter(
            CourseResource.id.in_(form.resource_ids.data)).all()
        schedule.resources = resources
        assignments = Assignment.query.filter(
            Assignment.id.in_(form.assignment_ids.data)).all()
        schedule.assignments = assignments
        db.session.add(schedule)
    return Success()
Exemplo n.º 5
0
def schedule_create():
    jsonData = request.get_json()

    with db.auto_commit():
        schedule = Schedule()
        schedule.league_id = jsonData['league_id']
        schedule.schedule_process = jsonData['schedule_process']
        schedule.schedule_team_a = jsonData['schedule_team_a']
        schedule.schedule_team_b = jsonData['schedule_team_b']
        schedule.schedule_support_a = jsonData['schedule_support_a']
        schedule.schedule_support_b = jsonData['schedule_support_b']
        schedule.schedule_score_a = jsonData['schedule_score_a']
        schedule.schedule_score_b = jsonData['schedule_score_b']
        schedule.schedule_location = jsonData['schedule_location']
        schedule.schedule_time = jsonData['schedule_time']
        schedule.schedule_judge = jsonData['schedule_judge']
        schedule.schedule_status = jsonData['schedule_status']
        schedule.schedule_turn_name = jsonData['schedule_turn_name']
        db.session.add(schedule)
    return Success(msg='新增赛事成功')
Exemplo n.º 6
0
    def post(self, cleaner_id):

        # Validate cleaner
        if Cleaner.get_by_id(cleaner_id) is None:
            abort(404, 'Cleaner not found')

        # Create new schedule
        args = self.parser_post.parse_args()
        if args['year'] is None:
            args['year'] = date.today().year

        schedule = Schedule(cleaner_id=cleaner_id,
                            year=args['year'],
                            week=args['week'],
                            day_of_week=args['day_of_week'],
                            start_time=args['start_time'],
                            end_time=args['end_time'])

        # Persist and return schedule
        schedule.persist()
        return schedule, 201
Exemplo n.º 7
0
 def create(self, payloads):
     self.model_schedule = Schedule()
     self.model_schedule.stage_id = payloads['stage_id']
     self.model_schedule.event_id = payloads['event_id']
     self.model_schedule.time_start = datetime.datetime.strptime(
         payloads['time_start'], "%Y-%m-%d %H:%M:%S.%f")
     self.model_schedule.time_end = datetime.datetime.strptime(
         payloads['time_end'], "%Y-%m-%d %H:%M:%S.%f")
     db.session.add(self.model_schedule)
     try:
         db.session.commit()
         data = self.model_schedule
         included = self.get_includes(data)
         return {
             'error': False,
             'data': data.as_dict(),
             'included': included
         }
     except SQLAlchemyError as e:
         data = e.orig.args
         return {'error': True, 'data': data}
Exemplo n.º 8
0
    def create_schedule(self, date, user_name, room_name, description):
        current_app.logger.info("Trying to create a new schedule to date: {}.".format(str(date)))
        try:
            date = datetime.strptime(date, "%Y-%m-%d")
        except ValueError as error:
            current_app.logger.warning(
                "Problem with date parser when create a new schedule. The date is: {} ".format(str(date))
            )
            raise error

        user = self.user_controller.get_user_by_name(user_name)
        if not user:
            current_app.logger.warning("User {} not found when trying to create a new schedule.".format(user_name))
            raise UserNotFoundError()
        room = self.room_controller.get_room_by_name(room_name)
        if not room:
            current_app.logger.warning("Room {} not found when trying to create a new schedule.".format(room_name))
            raise RoomNotFoundError()

        schedule = Schedule(date=date, user=user, room=room, description=description)
        db.session.add(schedule)
        db.session.commit()
        current_app.logger.info("Schedule create.")
Exemplo n.º 9
0
User.query.delete()

user = User(name="uName",
            email="*****@*****.**",
            uid="000000000",
            userType=UserTypesEnum.PROFESSOR)
user.add(user)
print("User ID {}\n".format(user.id))

room = Room()
room.name = "E003"

roomUser = RoomUser()
roomUser.user = user

room.users.append(roomUser)
room.active = True
room.add(room)
print("Room ID {}\n".format(room.id))

schedule = Schedule()
schedule.room = room
schedule.userType = UserTypesEnum.PROFESSOR
schedule.dayOfWeek = DaysOfWeekEnum.MONDAY
schedule.beginTime = datetime.now().hour
schedule.endTime = datetime.now().hour
schedule.lastUpdate = datetime.now()
schedule.active = True
schedule.add(schedule)
print("Schedule ID {}\n".format(schedule.id))