def _set_fields(self, form): setattr(form, 'day', SelectField(_(u'Day'), choices=get_days_of_the_week())) setattr(form, 'start_time', SelectField(_(u'Start Time'), choices=get_time_list(), coerce=int)) setattr(form, 'end_time', SelectField(_(u'End Time'), choices=get_time_list(), coerce=int, validators=[custom_validators.StartTimeAfterEndTime('start_time', message=_('End time must be after start time'))]))
def render_schedule(self, provider, schedule_form=None, **kw): sq = provider.get_schedules() schedules = sq.fetch() days = time.get_days_of_the_week() times = time.get_time_list() schedule_mapmap = util.create_schedule_dict(schedules) if not schedule_form: schedule_form = ProviderScheduleForm().get_form() self.render_template('provider/schedule.html', provider=provider, schedules=schedule_mapmap, times=times, days=days, schedule_form=schedule_form, **kw)
def get(self, vanity_url=None, operation=None, key=None, day=None, start_time=None): provider = db.get_provider_from_vanity_url(vanity_url) kwargs = {} if key: schedule_key = ndb.Key(urlsafe=key) if operation == 'add': logging.info("(ProviderEducationHandler.get) Add schedule key=%s" % key) #new_schedule.end_time = new_schedule.start_time + 4 schedule_form = ProviderScheduleForm().get_form() schedule_form.day.data = day schedule_form.start_time.data = int(start_time) end_time = int(start_time) + 4 max_time = max([k[0] for k in time.get_time_list()]) if end_time > max_time: end_time = max_time schedule_form.end_time.data = int(end_time) kwargs['schedule_form'] = schedule_form kwargs['add'] = 'add' self.render_schedule(provider, **kwargs) elif operation == 'delete': logging.info( "(ProviderEducationHandler.get) Delete schedule key=%s" % key) schedule_key.delete() # log the event self.log_event(user=provider.user, msg="Schedule delete") self.redirect('/provider/schedule/%s' % provider.vanity_url) elif operation == 'edit': logging.info( "(ProviderEducationHandler.get) Edit schedule key=%s" % key) # get the object obj = schedule_key.get() # populate the form kwargs['schedule_form'] = ProviderScheduleForm().get_form(obj=obj) kwargs['edit_key'] = key self.render_schedule(provider, **kwargs) else: self.render_schedule(provider, **kwargs)
def get(self, vanity_url=None, operation=None, key=None, day=None, start_time=None): provider = db.get_provider_from_vanity_url(vanity_url) kwargs = {} if key: schedule_key = ndb.Key(urlsafe=key) if operation == 'add': logging.info("(ProviderEducationHandler.get) Add schedule key=%s" % key) #new_schedule.end_time = new_schedule.start_time + 4 schedule_form = ProviderScheduleForm().get_form() schedule_form.day.data = day schedule_form.start_time.data = int(start_time) end_time = int(start_time) + 4 max_time = max([k[0] for k in time.get_time_list()]) if end_time > max_time: end_time = max_time schedule_form.end_time.data = int(end_time) kwargs['schedule_form'] = schedule_form kwargs['add'] = 'add' self.render_schedule(provider, **kwargs) elif operation == 'delete': logging.info("(ProviderEducationHandler.get) Delete schedule key=%s" % key) schedule_key.delete() # log the event self.log_event(user=provider.user, msg="Schedule delete") self.redirect('/provider/schedule/%s' % provider.vanity_url) elif operation == 'edit': logging.info("(ProviderEducationHandler.get) Edit schedule key=%s" % key) # get the object obj = schedule_key.get() # populate the form kwargs['schedule_form'] = ProviderScheduleForm().get_form(obj=obj) kwargs['edit_key'] = key self.render_schedule(provider, **kwargs) else: self.render_schedule(provider, **kwargs)