Beispiel #1
0
 def _process(self):
     defaults = self._get_form_defaults(location_parent=self.session_block)
     form = ContributionEntryForm(obj=defaults,
                                  to_schedule=True,
                                  **self._get_form_params())
     if form.validate_on_submit():
         contrib = Contribution()
         with track_time_changes(auto_extend=True,
                                 user=session.user) as changes:
             with flash_if_unregistered(self.event_new,
                                        lambda: contrib.person_links):
                 contrib = create_contribution(
                     self.event_new,
                     form.data,
                     session_block=self.session_block,
                     extend_parent=True)
         entry = contrib.timetable_entry
         notifications = get_time_changes_notifications(
             changes, tzinfo=self.event_new.tzinfo, entry=entry)
         return jsonify_data(
             entries=[serialize_entry_update(entry, session_=self.session)],
             notifications=notifications)
     self.commit = False
     return jsonify_template('events/contributions/forms/contribution.html',
                             form=form,
                             fields=form._display_fields)
Beispiel #2
0
 def _process(self):
     contrib_form_class = make_contribution_form(self.event)
     custom_field_values = {
         'custom_{}'.format(x.contribution_field_id): x.data
         for x in self.contrib.field_values
     }
     parent_session_block = (
         self.contrib.timetable_entry.parent.session_block if
         (self.contrib.timetable_entry
          and self.contrib.timetable_entry.parent) else None)
     form = contrib_form_class(obj=FormDefaults(
         self.contrib,
         start_date=self.contrib.start_dt,
         **custom_field_values),
                               event=self.event,
                               contrib=self.contrib,
                               session_block=parent_session_block)
     if form.validate_on_submit():
         with track_time_changes(), flash_if_unregistered(
                 self.event, lambda: self.contrib.person_links):
             update_contribution(self.contrib, *get_field_values(form.data))
         flash(
             _("Contribution '{}' successfully updated").format(
                 self.contrib.title), 'success')
         tpl_components = self.list_generator.render_list(self.contrib)
         if tpl_components['hide_contrib']:
             self.list_generator.flash_info_message(self.contrib)
         return jsonify_data(flash=(request.args.get('flash') == '1'),
                             **tpl_components)
     elif not form.is_submitted():
         handle_legacy_description(form.description, self.contrib)
     self.commit = False
     return jsonify_template('events/contributions/forms/contribution.html',
                             form=form)
Beispiel #3
0
 def _process(self):
     inherited_location = self.event.location_data
     inherited_location['inheriting'] = True
     default_duration = contribution_settings.get(self.event,
                                                  'default_duration')
     contrib_form_class = make_contribution_form(self.event)
     form = contrib_form_class(obj=FormDefaults(
         location_data=inherited_location, duration=default_duration),
                               event=self.event)
     if form.validate_on_submit():
         # Create empty contribution so it can be compared to the new one in flash_if_unregistered
         contrib = Contribution()
         with flash_if_unregistered(self.event,
                                    lambda: contrib.person_links):
             contrib = create_contribution(self.event,
                                           *get_field_values(form.data))
         flash(
             _("Contribution '{}' created successfully").format(
                 contrib.title), 'success')
         tpl_components = self.list_generator.render_list(contrib)
         if tpl_components['hide_contrib']:
             self.list_generator.flash_info_message(contrib)
         return jsonify_data(**tpl_components)
     return jsonify_template('events/contributions/forms/contribution.html',
                             form=form)
Beispiel #4
0
 def _process(self):
     form = self.form_class(obj=self.event, event=self.event)
     if form.validate_on_submit():
         with flash_if_unregistered(self.event, lambda: self.event.person_links):
             update_event(self.event, **form.data)
         return self.jsonify_success()
     self.commit = False
     return self.render_form(form)
Beispiel #5
0
 def _process(self):
     form = self.form_class(obj=self.event, event=self.event)
     if form.validate_on_submit():
         with flash_if_unregistered(self.event, lambda: self.event.person_links):
             update_event(self.event, **form.data)
         return self.jsonify_success()
     self.commit = False
     return self.render_form(form)
Beispiel #6
0
 def _process(self):
     form = EventPersonLinkForm(obj=self.event_new, event=self.event_new, event_type=self.event_new.type)
     if form.validate_on_submit():
         with flash_if_unregistered(self.event_new, lambda: self.event_new.person_links):
             update_event(self.event_new, form.data)
         tpl = get_template_module('events/management/_event_person_links.html')
         return jsonify_data(html=tpl.render_event_person_links(self.event_new.type, self.event_new.person_links))
     self.commit = False
     return jsonify_form(form)
Beispiel #7
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))
Beispiel #8
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:
                 with flash_if_unregistered(self.event_new, lambda: contrib.person_links):
                     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(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_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(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_new)
             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_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(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))
Beispiel #9
0
 def _process(self):
     defaults = self._get_form_defaults(location_parent=self.session_block)
     form = ContributionEntryForm(obj=defaults, to_schedule=True, **self._get_form_params())
     if form.validate_on_submit():
         contrib = Contribution()
         with track_time_changes(auto_extend=True, user=session.user) as changes:
             with flash_if_unregistered(self.event_new, lambda: contrib.person_links):
                 contrib = create_contribution(self.event_new, form.data, session_block=self.session_block,
                                               extend_parent=True)
         entry = contrib.timetable_entry
         notifications = get_time_changes_notifications(changes, tzinfo=self.event_new.tzinfo, entry=entry)
         return jsonify_data(entries=[serialize_entry_update(entry, session_=self.session)],
                             notifications=notifications)
     self.commit = False
     return jsonify_template('events/contributions/forms/contribution.html', form=form, fields=form._display_fields)
Beispiel #10
0
 def _process(self):
     inherited_location = self.event_new.location_data
     inherited_location['inheriting'] = True
     contrib_form_class = make_contribution_form(self.event_new)
     form = contrib_form_class(obj=FormDefaults(location_data=inherited_location), event=self.event_new)
     if form.validate_on_submit():
         # Create empty contribution so it can be compared to the new one in flash_if_unregistered
         contrib = Contribution()
         with flash_if_unregistered(self.event_new, lambda: contrib.person_links):
             contrib = create_contribution(self.event_new, *get_field_values(form.data))
         flash(_("Contribution '{}' created successfully").format(contrib.title), 'success')
         tpl_components = self.list_generator.render_list(contrib)
         if tpl_components['hide_contrib']:
             self.list_generator.flash_info_message(contrib)
         return jsonify_data(**tpl_components)
     return jsonify_template('events/contributions/forms/contribution.html', form=form)
Beispiel #11
0
 def _process(self):
     contrib_form_class = make_contribution_form(self.event)
     custom_field_values = {'custom_{}'.format(x.contribution_field_id): x.data for x in self.contrib.field_values}
     parent_session_block = (self.contrib.timetable_entry.parent.session_block
                             if (self.contrib.timetable_entry and self.contrib.timetable_entry.parent) else None)
     form = contrib_form_class(obj=FormDefaults(self.contrib, start_date=self.contrib.start_dt,
                                                **custom_field_values),
                               event=self.event, contrib=self.contrib, session_block=parent_session_block)
     if form.validate_on_submit():
         with track_time_changes(), flash_if_unregistered(self.event, lambda: self.contrib.person_links):
             update_contribution(self.contrib, *get_field_values(form.data))
         flash(_("Contribution '{}' successfully updated").format(self.contrib.title), 'success')
         tpl_components = self.list_generator.render_list(self.contrib)
         if tpl_components['hide_contrib']:
             self.list_generator.flash_info_message(self.contrib)
         return jsonify_data(flash=(request.args.get('flash') == '1'), **tpl_components)
     elif not form.is_submitted():
         handle_legacy_description(form.description, self.contrib)
     self.commit = False
     return jsonify_template('events/contributions/forms/contribution.html', form=form)