コード例 #1
0
ファイル: test_main.py プロジェクト: blurey8/susunjadwal
 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
コード例 #2
0
ファイル: main.py プロジェクト: jonathanfilbert/susunjadwal
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)
コード例 #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)