Exemple #1
0
 def create_user_schedule(self, user):
     """Create user schedule directly from db"""
     user_schedule = UserSchedule(user_id=user.id)
     for item in self.schedule_items:
         user_schedule.add_schedule_item(**item)
     user_schedule.save()
     return user_schedule
Exemple #2
0
def save_user_schedule(user_id):
    data = request.json
    user_schedule = UserSchedule(user_id=user_id)
    for item in data['schedule_items']:
        user_schedule.add_schedule_item(**item)
    user_schedule.save()

    return (jsonify({
        'id': str(user_schedule.id),
    }), 201)
Exemple #3
0
def edit_user_schedule(user_id, user_schedule_id):
    user_schedule = UserSchedule.objects(id=user_schedule_id).first()
    # If the schedule doesn't exist or the user is mismatched,
    # create a new one with the same items.
    if user_schedule is None:
        user_schedule = UserSchedule(user_id=user_id)
    elif str(user_schedule.user_id.id) != user_id:
        name = f'{user_schedule.name} (copied)'
        user_schedule = UserSchedule(user_id=user_id, name=name)
    data = request.json
    user_schedule.clear_schedule_item()
    for editedScheduleItem in data['schedule_items']:
        user_schedule.add_schedule_item(**editedScheduleItem)
    user_schedule.save()

    return (jsonify({'user_schedule': user_schedule.serialize()}), 200)
    def test_add_schedule_item_should_increase_the_schedule_item(self):
        user_schedule = UserSchedule(user_id=self.generate_random_user_item(),
                                     name="User Schedule A")
        assert len(user_schedule.schedule_items) == 0

        inserted_schedule = user_schedule.add_schedule_item(name="Schedule A",
                                                            day="Day A",
                                                            room="Room A",
                                                            start="Start",
                                                            end="End")

        assert len(user_schedule.schedule_items) == 1
        assert inserted_schedule.name == "Schedule A"
        assert inserted_schedule.day == "Day A"
        assert inserted_schedule.room == "Room A"
        assert inserted_schedule.start == "Start"
        assert inserted_schedule.end == "End"