def get_form(self, djp): request = djp.request page = djp.page data = dict(request.POST.items()) if data.get('_child',None) == 'create': return get_form(djp, NewChildForm, instance = djp.page) else: return get_form(djp, ShortPageForm, instance = djp.page)
def extra_content(self, djp, c): page = djp.page request = djp.request page_url = self.page_url(djp.request) ed = { 'page_form': get_form(djp, ShortPageForm, instance = page, withinputs=True).render(djp,validate=True), 'new_child_form': get_form(djp, NewChildForm, instance = page, withinputs=True).render(djp,validate=True), 'page_url': self.page_url(djp.request)} bd = loader.render_to_string(self.edit_template,ed) c.update({'page_url':page_url, 'edit_page':box(hd = "Edit Page Layout", bd = bd, collapsed=True)})
def get_form( self, djp, form_class, addinputs=True, form_withrequest=None, form_ajax=None, forceform=False, instance=None, **kwargs ): """Build a form. This method is called by editing/adding views. It can be overridden to twick its behaviour. :parameter djp: instance of :class:`djpcms.views.response.DjpResponse`. :parameter form_class: form class to use. :parameter addinputs: boolean flag indicating if submit inputs should be added. Default ``True``. :parameter form_withrequest: if form_class requires the request object to be passed to its constructor. Default ``None``. :parameter form_ajax: if form uses AJAX. Default ``False``. :parameter instance: Instance of model or ``None`` or ``False``. If ``False`` no instance will be passed to the form constructor. If ``None`` the instance will be obtained from ``djp``. Default ``None``. """ template = self.form_template if callable(template): template = template(djp) if instance == False: instance = None else: instance = instance or djp.instance if instance: model = instance.__class__ else: model = kwargs.pop("model", None) if not model: model = getattr(self, "model", None) request = djp.request form_withrequest = form_withrequest if form_withrequest is not None else self.form_withrequest form_ajax = form_ajax if form_ajax is not None else self.form_ajax form_class = form_class or self.form or forms.ModelForm if isinstance(form_class, type): if forceform or not hasattr(form_class, "_meta"): mform = form_class else: if form_class._meta.model == model: mform = form_class else: mform = forms.modelform_factory(model, form_class) return get_form( djp, mform, instance=instance, addinputs=self.submit if addinputs else None, model=model, form_ajax=form_ajax, form_withrequest=form_withrequest, template=template, **kwargs )