def context(self, context): helper = FormHelper() helper.form_tag = False context.update({ 'addform': self.add_view.form_obj, 'addhelper': helper, 'addurl': self.add_view.model_admin_url('add'), 'model': self.model })
def setup(self): helper = FormHelper() helper.form_tag = False self.helper = helper self.id = self.cleaned_data['id'] self.title = self.cleaned_data['title'] or self.base_title if not (self.user.is_superuser or self.has_perm()): raise PermissionDenied
def context(self, context): helper = FormHelper() helper.form_tag = False context.update( { "addform": self.add_view.form_obj, "addhelper": helper, "addurl": self.add_view.model_admin_urlname("add"), "model": self.model, } )
def get_form_helper(self): helper = FormHelper() helper.form_tag = False helper.add_layout(self.get_form_layout()) # deal with readonly fields readonly_fields = self.get_readonly_fields() if readonly_fields: detail = self.get_model_view(DetailAdminUtil, self.model, self.form_obj.instance) for field in readonly_fields: helper[field].wrap(ReadOnlyField, detail) return helper
def instance_form(self, **kwargs): formset = self.get_formset(**kwargs) attrs = { 'instance': self.model_instance, 'queryset': self.queryset() } if self.request_method == 'post': attrs.update({ 'data': self.request.POST, 'files': self.request.FILES, 'save_as_new': "_saveasnew" in self.request.POST }) instance = formset(**attrs) instance.view = self helper = FormHelper() helper.form_tag = False style = style_manager.get_style('one' if self.max_num == 1 else self.style)(self, instance) if len(instance): layout = copy.deepcopy(self.form_layout) if layout is None: layout = Layout(*instance[0].fields.keys()) elif type(layout) in (list, tuple) and len(layout) > 0: layout = Layout(*layout) rendered_fields = [i[1] for i in layout.get_field_names()] layout.extend([f for f in instance[0].fields.keys() if f not in rendered_fields]) helper.add_layout(layout) style.update_layout(helper) # replace delete field with Dynamic field, for hidden delete field when instance is NEW. helper[DELETION_FIELD_NAME].wrap(DeleteField) instance.helper = helper instance.style = style return instance
def get_form_helper(self): helper = FormHelper() helper.form_tag = False layout = self.get_form_layout() replace_field_to_value(layout, self.get_field_result) helper.add_layout(layout) helper.filter(basestring, max_level=20).wrap(ShowField, admin_view=self) return helper
def do_action(self, queryset): if not self.has_change_permission(): raise PermissionDenied form_class = self.get_change_form() if self.request.POST.get('post'): self.form_obj = form_class(data=self.request.POST, files=self.request.FILES) return None else: self.form_obj = form_class() helper = FormHelper() helper.form_tag = False # 默认不需要 crispy 生成 form_tag helper.add_layout(Layout(Container( Fieldset("", *self.form_obj.fields.keys(), css_class="unsort no_title"), css_class="form-horizontal" ))) self.form_obj.helper = helper if len(queryset) == 1: objects_name = force_unicode(self.opts.verbose_name) else: objects_name = force_unicode(self.opts.verbose_name_plural) context = self.get_context() context.update({ "title": _("Change %s") % objects_name, 'form': self.form_obj, 'queryset': queryset, "opts": self.opts, "app_label": self.app_label, 'action_checkbox_name': ACTION_CHECKBOX_NAME, }) return TemplateResponse(self.request, self.batch_change_form_template or \ self.get_template_list('batch_change_form.html'), context, current_app=self.admin_site.name)