Views¶
-
class
ajaxviews.views.AjaxDetailView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.GenericBaseView,django.views.generic.detail.DetailViewThe detail view can be displayed in bootstrap modals. Simply add
.modal-linkto an html link tag with a href that points to a view that inherits from this view. Or you can callView.requestModalpassing in the url of the detail view.If a
ajaxviews.forms.GenericModelFormis opened in a modal and saved, the underlying detail view is reloaded automatically to display the changes.
-
class
ajaxviews.views.AjaxListView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.GenericBaseView,django.views.generic.list.ListViewThe list view can be updated by calling
View.requestView()from the client side view class.If you have assigned the
ajaxviews.queries.AjaxQuerySetas manager to the model class, you can set afilter_fieldsattribute to the view class to specify filter parameters. It contains a list of field paths that are automatically applied as filters for all requests whereget_querysetis called.The index of the
filter_fieldslist is passed between requests to control the filter and sorting mechanism. Add a table in your templates with the following markup to activate generic filters fromFilterView.<tr class="filter-header"> <th data-filter-index="0"> <span>Column Header Name</span> {% include 'ajaxviews/_table_sort.html' with index=0 %} </th> <th data-filter-index="1"> <span>Column Header Name</span> {% include 'ajaxviews/_table_sort.html' with index=1 %} </th> </tr>
The
.filter-headeris only necessary if you want to use the built-in view styles to style the popover which displays the filter values of the current filter index.Field options for
filter_fields:A string only
'<field_path>'will filter it’s path by theselected_filter_valuespassed in thejson_cfg. This is usually a list of pk’s or the fields values.using a tuple refines the query
('<field_path>', 'date')Filter by date range('<field_path>', 'set', <set_of_tuples>)Filter by first element of tuple('<field_path>', 'exclude')Ignore filter, useexclude_filterorexclude_sortto only ignore one of these.
The
filter_indexandsort_indexparameters can be applied independently on different fields.Variables: - filter_fields (list) – List of fields to be filtered when a
selected_filter_indexandselected_filter_valuesare passed in the request. The index matches the order of the list. - filter_user (bool) – Whether to filter objects the authenticated user has access to. Default is False.
- paginate_by (int) – Number of results by which to paginate.
- filter_search_input_by (int) – Number of results in list view filters by which to display a search input.
- search_field (int) – Name of the autocomplete class that’s registered with
django-autocomplete-ligth.
-
class
ajaxviews.views.BaseFormSetView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.GenericBaseViewThis view renders a formset using the
ModelFormSetViewclass fromdjango-extra-views.The
success_urlis passed on to the formset and a message is displayed on successful form save ifsuccess_messagehas been added to the view class.-
formset_class¶ alias of
ModelFormSet
-
-
class
ajaxviews.views.BaseFormView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.GenericBaseViewThis is the base view for normal and preview forms.
The
modelandsuccess_messageattributes from the form meta are automatically added to the view class.related_obj_idsare used to pass on object pk’s from the calling view to the requested view through url kwargs. This is useful if a model has relations (e.g. fk, m2m) it is depending on to be saved.If
form_cfgis passed in the post request (by default as hidden input field), it’s accessible through the formscleaned_form_cfgproperty.The
auto_select_fieldcoming from a GET request is used to update a select field when an element has been added by usingadd_fieldsin the forms meta class.There are multiple ways to set a success url for the form view. This is the order of precedence for
success_url:request.POST→form_cfg→form.Meta(if create view) →view class→get_absolute_urlVariables:
-
class
ajaxviews.views.CreateFormSetView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.BaseFormSetView,ajaxviews.views.FormSet view used to create multiple model objects. Inherits functionality from
BaseFormSetView.Variables: headline_prefix (str) – The prefix to prepend to the headline. Default: Add
-
class
ajaxviews.views.CreateFormView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.BaseFormView,django.views.generic.edit.CreateViewForm view used to create model objects. Inherits functionality from
BaseFormView.Assign django-guardian’s object permissions if
assign_permattribute has been added to the class.Variables:
-
class
ajaxviews.views.GenericBaseView(*args, **kwargs)[source]¶ Bases:
objectThis is the base view which establishes communication with the client side
App.It merges the query string from the GET request with the keyword arguments retrieved from Django’s URL conf into
json_cfg.You can control the behaviour of your views by extending from this view and setting the
pluginclass attribute.Variables: - plugin (object) – Process the request using the
ViewFactory. - ajax_view (bool) – Set to True if you have created a client side module associated with the view class that’s inheriting from this view.
- json_cfg (dict) – Data parsed from incoming requests and returned in each response.
- page_size (str) – Define the width of the view.
- plugin (object) – Process the request using the
-
class
ajaxviews.views.PreviewCreateView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.BaseFormView,django.views.generic.edit.CreateViewPreview for model forms to confirm actions.
- Stages:
- 0 - GET: display model form
- 1 - POST: submitted model form and render preview form (process_preview)
- 2 - POST: submitted preview form and save model form (done)
Parameters:
-
class
ajaxviews.views.PreviewUpdateView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.BaseFormView,django.views.generic.edit.UpdateViewWorks the same as
PreviewCreateViewexcept for updating model objects.
-
class
ajaxviews.views.UpdateFormSetView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.BaseFormSetView,ajaxviews.views.FormSet view used to update multiple model objects. Inherits functionality from
BaseFormSetView.Variables: headline_prefix (str) – The prefix to prepend to the headline. Default: Update
-
class
ajaxviews.views.UpdateFormView(*args, **kwargs)[source]¶ Bases:
ajaxviews.views.BaseFormView,django.views.generic.edit.UpdateViewForm view used to update model objects. Inherits functionality from
BaseFormView.Variables: - headline_prefix (str) – The prefix to prepend to the headline which is specified in the form meta.
Default:
Update - auto_delete_url (bool) – Wheter or not to use
AUTO_DELETE_URL. Default:True - delete_url (str) – Parse delete url for the current view using a naming convention.
View name:
edit_<name>→delete_<name>Default:True
- headline_prefix (str) – The prefix to prepend to the headline which is specified in the form meta.
Default:
-
class
ajaxviews.views.ViewFactory(*args)[source]¶ Bases:
objectTo reduce the use of multiple inheritance in django views, this class creates a plugin instance which controls the behavior of the view. Using composition instead, each method of Django’s class based views is called only once and the plugin takes care of processing the request.
- Supported plugins:
- list
- detail
- form (create, update)
- formset (create, update)
- formpreview (create, update)
- delete
Variables: