viewhelpers.formview.formview — Form views¶
-
class
WithinRoleFormView
(**kwargs)¶ Bases:
django_cradmin.javascriptregistry.viewmixin.WithinRoleViewMixin
,django_cradmin.viewhelpers.formview.formviewmixin.FormViewMixin
,django_cradmin.viewhelpers.mixins.CommonCradminViewMixin
,django.views.generic.edit.FormView
Form view with the correct context data and sane base template for views where we have a cradmin role.
Uses
django.views.generic.edit.FormView
withdjango_cradmin.viewhelpers.formview.formviewmixin.FormViewMixin
anddjango_cradmin.javascriptregistry.viewmixin.WithinRoleViewMixin
.Note
You should import this class with
from django_cradmin import viewhelpers
, and refer to it usingviewhelpers.formview.WithinRoleFormView
.Examples
Minimalistic example:
from django import forms from django.http import HttpResponseRedirect from django_cradmin import viewhelpers class MyForm(forms.Form): first_name = forms.CharField(max_length=50) last_name = forms.CharField(max_length=50) class MyFormView(viewhelpers.formview.WithinRoleFormView): template_name = 'myapp/myview.django.html' form_class = MyForm def get_form_renderable(self): return uicontainer.layout.AdminuiPageSectionTight( children=[ uicontainer.form.Form( form=self.get_form(), children=[ uicontainer.fieldwrapper.FieldWrapper( fieldname='first_name', # Override field renderable to set autofocus field_renderable=uicontainer.field.Field(autofocus=True) ), uicontainer.fieldwrapper.FieldWrapper('last_name'), uicontainer.button.SubmitPrimary(text='Save') ] ) ] ).bootstrap() def form_valid(self, form): # ... do something with the form ... return HttpResponseRedirect('/some/view')
Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
-
get_context_data
(**kwargs)¶ Insert the form into the context dict.
-
-
class
StandaloneFormView
(**kwargs)¶ Bases:
django_cradmin.javascriptregistry.viewmixin.StandaloneBaseViewMixin
,django_cradmin.viewhelpers.formview.formviewmixin.FormViewMixin
,django_cradmin.viewhelpers.mixins.CommonCradminViewMixin
,django.views.generic.edit.FormView
Form view with the correct context data and sane base template for views where we do not have a cradmin role.
Note
You should import this class with
from django_cradmin import viewhelpers
, and refer to it usingviewhelpers.formview.StandaloneFormView
.Constructor. Called in the URLconf; can contain helpful extra keyword arguments, and other things.
-
get_context_data
(**kwargs)¶ Insert the form into the context dict.
-