def handle_new_definition(self, request, form): if form.submitted(request): model = Bunch( title=None, definition=None, type='custom', meta={}, content={} ) form.update_model(model) # forms added online are always custom forms new_form = self.definitions.add( title=model.title, definition=model.definition, type='custom', meta=model.meta, content=model.content ) request.success(_("Added a new form")) return morepath.redirect(request.link(new_form)) layout = FormEditorLayout(self, request) layout.breadcrumbs = [ Link(_("Homepage"), layout.homepage_url), Link(_("Forms"), request.link(self)), Link(_("New Form"), request.link(self, name='neu')) ] return { 'layout': layout, 'title': _("New Form"), 'form': form, 'form_width': 'large', }
def handle_edit_definition(self, request, form): if form.submitted(request): self.title = form.title.data if self.type == 'custom': self.definition = form.definition.data form.update_model(self) request.success(_("Your changes were saved")) return morepath.redirect(request.link(self)) else: form.title.data = self.title form.definition.data = self.definition form.apply_model(self) collection = FormCollection(request.app.session()) layout = FormEditorLayout(self, request) layout.breadcrumbs = [ Link(_("Homepage"), layout.homepage_url), Link(_("Forms"), request.link(collection)), Link(self.title, request.link(self)), Link(_("Edit"), request.link(self, name='bearbeiten')) ] return { 'layout': layout, 'title': self.title, 'form': form, 'form_width': 'large', }