Exemple #1
0
 def _process(self):
     defaults = self._get_form_defaults(location_parent=self.session)
     form = SessionBlockEntryForm(obj=defaults, **self._get_form_params())
     if form.validate_on_submit():
         with track_time_changes(auto_extend=True, user=session.user) as changes:
             entry = create_session_block_entry(self.session, form.data)
         notifications = get_time_changes_notifications(changes, tzinfo=self.event_new.tzinfo, entry=entry)
         return jsonify_data(entry=serialize_entry_update(entry), notifications=notifications, flash=False)
     self.commit = False
     return jsonify_form(form, fields=form._display_fields, disabled_until_change=False)
Exemple #2
0
 def _process(self):
     defaults = self._get_form_defaults(location_parent=self.parent_session)
     form = SessionBlockEntryForm(obj=defaults, **self._get_form_params())
     if form.validate_on_submit():
         with track_time_changes(auto_extend=True, user=session.user) as changes:
             entry = create_session_block_entry(self.parent_session, form.data)
         notifications = get_time_changes_notifications(changes, tzinfo=self.event.tzinfo, entry=entry)
         return jsonify_data(update=serialize_entry_update(entry, session_=self.session),
                             notifications=notifications, flash=False)
     self.commit = False
     return jsonify_form(form, fields=form._display_fields, disabled_until_change=False)
Exemple #3
0
 def _process(self):
     form = None
     parent_session_block = self.entry.parent.object if self.entry.parent else None
     if self.entry.contribution:
         contrib = self.entry.contribution
         tt_entry_dt = self.entry.start_dt.astimezone(self.event.tzinfo)
         form = ContributionEntryForm(obj=FormDefaults(contrib, time=tt_entry_dt.time()),
                                      event=self.event, contrib=contrib, to_schedule=False,
                                      day=tt_entry_dt.date(), session_block=parent_session_block)
         if form.validate_on_submit():
             with track_time_changes(auto_extend=True, user=session.user) as changes:
                 with flash_if_unregistered(self.event, lambda: contrib.person_links):
                     update_contribution(contrib, *get_field_values(form.data))
             notifications = get_time_changes_notifications(changes, tzinfo=self.event.tzinfo, entry=self.entry)
             return jsonify_data(update=serialize_entry_update(self.entry, session_=self.session),
                                 notifications=notifications)
         elif not form.is_submitted():
             handle_legacy_description(form.description, contrib)
         return jsonify_template('events/contributions/forms/contribution.html', form=form,
                                 fields=form._display_fields)
     elif self.entry.break_:
         break_ = self.entry.break_
         tt_entry_dt = self.entry.start_dt.astimezone(self.event.tzinfo)
         form = BreakEntryForm(obj=FormDefaults(break_, time=tt_entry_dt.time()), event=self.event,
                               day=tt_entry_dt.date(), session_block=parent_session_block)
         if form.validate_on_submit():
             with track_time_changes(auto_extend=True, user=session.user) as changes:
                 update_break_entry(break_, form.data)
             notifications = get_time_changes_notifications(changes, tzinfo=self.event.tzinfo, entry=self.entry)
             return jsonify_data(update=serialize_entry_update(self.entry, session_=self.session),
                                 notifications=notifications, flash=False)
     elif self.entry.session_block:
         if self.edit_session:
             session_ = self.entry.session_block.session
             form = SessionForm(obj=FormDefaults(session_), event=self.event)
             if form.validate_on_submit():
                 update_session(session_, form.data)
                 return jsonify_data(update=serialize_entry_update(self.entry, session_=self.session), flash=False)
         else:
             block = self.entry.session_block
             tt_entry_dt = self.entry.start_dt.astimezone(self.event.tzinfo)
             form = SessionBlockEntryForm(obj=FormDefaults(block, time=tt_entry_dt.time()),
                                          event=self.event, session_block=block, to_schedule=False,
                                          day=tt_entry_dt.date())
             if form.validate_on_submit():
                 with track_time_changes(auto_extend=True, user=session.user) as changes:
                     update_session_block(block, form.data)
                 notifications = get_time_changes_notifications(changes, tzinfo=self.event.tzinfo,
                                                                entry=self.entry)
                 return jsonify_data(update=serialize_entry_update(self.entry, session_=self.session),
                                     notifications=notifications, flash=False)
     self.commit = False
     return jsonify_form(form, fields=getattr(form, '_display_fields', None))
Exemple #4
0
 def _process(self):
     form = None
     parent_session_block = self.entry.parent.object if self.entry.parent else None
     if self.entry.contribution:
         contrib = self.entry.contribution
         tt_entry_dt = self.entry.start_dt.astimezone(self.event_new.tzinfo)
         form = ContributionEntryForm(obj=FormDefaults(
             contrib, time=tt_entry_dt.time()),
                                      event=self.event_new,
                                      contrib=contrib,
                                      to_schedule=False,
                                      day=tt_entry_dt.date(),
                                      session_block=parent_session_block)
         if form.validate_on_submit():
             with track_time_changes(auto_extend=True,
                                     user=session.user) as changes:
                 update_contribution(contrib, *_get_field_values(form.data))
             notifications = get_time_changes_notifications(
                 changes, tzinfo=self.event_new.tzinfo, entry=self.entry)
             return jsonify_data(
                 entries=[serialize_entry_update(contrib.timetable_entry)],
                 notifications=notifications,
                 flash=False)
         return jsonify_template(
             'events/contributions/forms/contribution.html',
             form=form,
             fields=form._display_fields)
     elif self.entry.break_:
         break_ = self.entry.break_
         tt_entry_dt = self.entry.start_dt.astimezone(self.event_new.tzinfo)
         form = BreakEntryForm(obj=FormDefaults(break_,
                                                time=tt_entry_dt.time()),
                               event=self.event_new,
                               day=tt_entry_dt.date(),
                               session_block=parent_session_block)
         if form.validate_on_submit():
             with track_time_changes(auto_extend=True,
                                     user=session.user) as changes:
                 update_break_entry(break_, form.data)
             notifications = get_time_changes_notifications(
                 changes, tzinfo=self.event_new.tzinfo, entry=self.entry)
             return jsonify_data(
                 entries=[serialize_entry_update(break_.timetable_entry)],
                 notifications=notifications,
                 flash=False)
     elif self.entry.session_block:
         if self.edit_session:
             session_ = self.entry.session_block.session
             form = SessionForm(obj=FormDefaults(session_),
                                event=self.event_new)
             if form.validate_on_submit():
                 update_session(session_, form.data)
                 return jsonify_data(entries=[
                     serialize_entry_update(x.timetable_entry)
                     for x in session_.blocks
                 ],
                                     flash=False)
         else:
             block = self.entry.session_block
             tt_entry_dt = self.entry.start_dt.astimezone(
                 self.event_new.tzinfo)
             form = SessionBlockEntryForm(obj=FormDefaults(
                 block, time=tt_entry_dt.time()),
                                          event=self.event_new,
                                          session_block=block,
                                          to_schedule=False,
                                          day=tt_entry_dt.date())
             if form.validate_on_submit():
                 with track_time_changes(auto_extend=True,
                                         user=session.user) as changes:
                     update_session_block(block, form.data)
                 notifications = get_time_changes_notifications(
                     changes,
                     tzinfo=self.event_new.tzinfo,
                     entry=self.entry)
                 return jsonify_data(entries=[
                     serialize_entry_update(block.timetable_entry)
                 ],
                                     notifications=notifications,
                                     flash=False)
     self.commit = False
     return jsonify_form(form,
                         fields=getattr(form, '_display_fields', None))