def config_schedule(area_name, shift_name, schedule_name): area = Area.query.filter_by(name=area_name).first() shift = Shift.query.filter_by(name=shift_name).first() form = CreateScheduleForm(original_name=schedule_name, area=area, shift=shift) if form.validate_on_submit(): s = Schedule.query.filter_by(name=schedule_name, id_shift=shift.id).first() if not s: s = Schedule(name=form.name.data) db.session.add(s) s.add_area(area) s.add_shift(shift) s.name = form.name.data s.make_times_list(start1=form.start1.data, start2=form.start2.data, start3=form.start3.data, start4=form.start4.data, end1=form.end1.data, end2=form.end2.data, end3=form.end3.data, end4=form.end4.data) db.session.commit() flash('Successfully added {} schedule for {} {}'.format( form.name.data, area.name, shift.name)) return redirect( url_for('main.area_schedules', area_name=area_name, shift_name=shift_name)) elif request.method == 'GET': if schedule_name != 'new': s = Schedule.query.filter_by(name=schedule_name, id_area=area.id, id_shift=shift.id).first() if s: form.name.data = s.name form.start1.data = s.start1 form.start2.data = s.start2 form.start3.data = s.start3 form.start4.data = s.start4 form.end1.data = s.end1 form.end2.data = s.end2 form.end3.data = s.end3 form.end4.data = s.end4 return render_template(tempdir + 'config_schedule.html', title='Edit Schedule', area=area, shift=shift, form=form)
def assemble(name): schedule = Schedule() schedule.name = name return schedule