def submit(self, instance, own_view=False): """Generate the submits elements to be added to the model form. """ if instance: sb = [input(value=self._form_save, name="_save")] if self._submit_as_new: sb.append(input(value=self._submit_as_new, name="_save_as_new")) else: sb = [input(value=self._form_add, name="_save")] if own_view: if self._form_continue: sb.append(input(value=self._form_continue, name="_save_and_continue")) if self._submit_cancel: sb.append(input(value=self._submit_cancel, name="_cancel")) return sb
def get_form(self, djp, all = True, url = None, initial = None, **kwargs): '''Get the contentblock editing form This form is composed of two parts, one for choosing the plugin type, and one for setting the plugin options ''' if url: initial = initial if initial is not None else {} initial['url'] = url else: initial = None uni = super(ChangeContentView,self).get_form(djp, initial = initial, **kwargs) if all: instance = djp.instance pform,purl = self.get_plugin_form(djp, instance.plugin) id = instance.pluginid('options') if pform: layout = getattr(pform,'layout',None) or FormLayout() layout.id = id pform.layout = layout uni.add(pform) else: # No plugin uni.add('<div id="%s"></div>' % id) sub = input(value = "edit", name = 'edit_content').render() id = instance.pluginid('edit') cl = '' if purl else ' class="djphide"' uni.inputs.append('<span id="{0}"{1}>{2}</span>'.format(id,cl,sub)) return uni
def render(self, djp, wrapper, prefix, for_model=None, ajax=False, method="get", **kwargs): appmodel, ok = app_model_from_ct(for_model) if not ok: return appmodel filters = appmodel.search_fields if not filters: return u"" request = djp.request search_url = appmodel.searchurl(request) if not search_url: return u"" model = appmodel.model initial = dict((request.GET or request.POST).items()) form = forms.modelform_factory(model, appmodel.form, fields=filters, exclude=[]) form.layout = FormLayout() f = UniForm(form(initial=initial), method=method, action=search_url) if ajax: f.addClass(djp.css.ajax) f.inputs.append(input(value="filter", name="_filter")) return f.render()
def get_form(djp, form_class, method = 'POST', initial = None, prefix = None, addinputs = None, withdata = True, instance = None, model = None, form_withrequest = None, template = None, form_ajax = False, withinputs = False): '''Comprehensive method for building a :class:`djpcms.utils.uniforms.UniForm` instance: :parameter djp: instance of :class:`djpcms.views.DjpResponse`. :parameter form_class: required form class. :parameter method: optional string indicating submit method. Default ``POST``. :parameter initial: If not none, a dictionary of initial values. :parameter prefix: Optional prefix string to use in the form. :parameter addinputs: An optional function for creating inputs. If available, it is called if the available form class as no inputs associated with it. Default ``None``. ''' from djpcms.utils.uniforms import UniForm request = djp.request own_view = djp.own_view() data = request.POST if request.method == 'POST' else request.GET prefix = data.get('_prefixed',None) save_as_new = data.has_key('_save_as_new') initial = update_initial(request, form_class, initial, own_view = own_view) inputs = getattr(form_class,'submits',None) if inputs: inputs = [input(value = val, name = nam) for val,nam in inputs] elif addinputs: inputs = addinputs(instance, own_view) if not prefix: prefix = gen_unique_id() inputs.append(input(value = prefix, name = '_prefixed', type = 'hidden')) f = form_class(**form_kwargs(request = request, initial = initial, instance = instance, prefix = prefix, withdata = withdata, withrequest = form_withrequest, method = method, own_view = own_view, save_as_new = save_as_new, inputs = inputs if withinputs else None)) wrap = UniForm(f, request = request, instance = instance, action = djp.url, inputs = inputs, template = template, save_as_new = save_as_new) if form_ajax: wrap.addClass(djp.css.ajax) wrap.is_ajax = request.is_ajax() if model: wrap.addClass(str(model._meta).replace('.','-')) return wrap
def submit(self, *args, **kwargs): return [input(value = "save", name = '_save')]