def create_view(self): """ Create model view """ return_url = get_redirect_target() or url_for('.index_view') if not self.can_create: return redirect(return_url) form = self.create_form() if validate_form_on_submit(form): if self.create_model(form): if '_add_another' in request.form: flash(gettext('Model was successfully created.')) return redirect(url_for('.create_view', url=return_url)) else: return redirect(return_url) form_opts = FormOpts(widget_args=self.form_widget_args, form_rules=self._form_create_rules) return self.render(self.create_template, form=form, form_opts=form_opts, return_url=return_url)
def __init__(self, form, session, model, prop, inline_view, **kwargs): """ Default constructor. :param form: Form for the related model :param session: SQLAlchemy session :param model: Related model :param prop: Related property name :param inline_view: Inline view """ self.form = form self.session = session self.model = model self.prop = prop self.inline_view = inline_view self._pk = get_primary_key(model) # Generate inline form field form_opts = FormOpts(widget_args=getattr(inline_view, 'form_widget_args', None), form_rules=inline_view._form_rules) form_field = self.form_field_type(form, self._pk, form_opts=form_opts) super(InlineModelFormList, self).__init__(form_field, **kwargs)
def detail_view(self): id = get_mdict_item_or_list(request.args, 'id') return_url = get_mdict_item_or_list(request.args, 'return_url') if id is None: return redirect(return_url) model = self.get_one(id) if model is None: return redirect(return_url) if self.detail_list is None: data = model else: data = OrderedDict((x, model.get(x, '')) for x in self.detail_list) self.format(data) form_opts = FormOpts(widget_args=self.form_widget_args, form_rules=self._form_edit_rules) return self.render( self.detail_template, model=model, data=data, )
def edit_view(self): """ Edit model view """ return_url = get_redirect_target() or self.get_url('.index_view') if not self.can_edit: return redirect(return_url) id = get_mdict_item_or_list(request.args, 'id') if id is None: return redirect(return_url) model = self.get_one(id) if model is None: return redirect(return_url) form = self.edit_form(obj=model) if self.validate_form(form): if self.update_model(form, model): if '_continue_editing' in request.form: flash(gettext('Model was successfully saved.')) return redirect(request.url) else: return redirect(return_url) form_widget_args = self.form_widget_args if hasattr(self, 'edit_form_widget_args'): form_widget_args = self.edit_form_widget_args form_opts = FormOpts(widget_args=form_widget_args, form_rules=self._form_edit_rules) return self.render(self.edit_template, model=model, form=form, form_opts=form_opts, return_url=return_url)