Esempio n. 1
0
    def _process(self):
        step = int(request.form.get('step', 1))
        form = self._form_for_step(step, set_defaults=True)
        prev_form = self._form_for_step(step - 1)

        if prev_form and not prev_form.validate():
            form = prev_form
            step = step - 1

        elif step > 2:
            # last step - perform actual cloning
            form = ImportContentsForm(self.source_event, self.event)

            if form.validate_on_submit():
                updated_event = clone_into_event(self.source_event, self.event,
                                                 set(form.selected_items.data))
                flash(_('Import successful!'), 'success')
                return jsonify_data(redirect=url_for(
                    'event_management.settings', updated_event),
                                    flash=False)
            else:
                # back to step 2, since there's been an error
                step = 2
        dependencies = {
            c.name: {
                'requires': list(c.requires_deep),
                'required_by': list(c.required_by_deep)
            }
            for c in EventCloner.get_cloners(self.event)
        }
        return jsonify_template('events/management/import_event.html',
                                event=self.event,
                                step=step,
                                form=form,
                                cloner_dependencies=dependencies)
Esempio n. 2
0
 def _form_for_step(self, step, set_defaults=True):
     if step == 1:
         return ImportSourceEventForm()
     elif step == 2:
         return ImportContentsForm(self.source_event, self.event, set_defaults=set_defaults)
     else:
         return None