Views

class ajaxviews.views.AjaxDetailView(*args, **kwargs)[source]

Bases: ajaxviews.views.GenericBaseView, django.views.generic.detail.DetailView

The detail view can be displayed in bootstrap modals. Simply add .modal-link to an html link tag with a href that points to a view that inherits from this view. Or you can call View.requestModal passing in the url of the detail view.

If a ajaxviews.forms.GenericModelForm is 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.ListView

The list view can be updated by calling View.requestView() from the client side view class.

If you have assigned the ajaxviews.queries.AjaxQuerySet as manager to the model class, you can set a filter_fields attribute to the view class to specify filter parameters. It contains a list of field paths that are automatically applied as filters for all requests where get_queryset is called.

The index of the filter_fields list 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 from FilterView.

<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-header is 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 the selected_filter_values passed in the json_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, use exclude_filter or exclude_sort to only ignore one of these.

The filter_index and sort_index parameters can be applied independently on different fields.

Variables:
  • filter_fields (list) – List of fields to be filtered when a selected_filter_index and selected_filter_values are 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.GenericBaseView

This view renders a formset using the ModelFormSetView class from django-extra-views.

The success_url is passed on to the formset and a message is displayed on successful form save if success_message has been added to the view class.

formset_class

alias of ModelFormSet

class ajaxviews.views.BaseFormView(*args, **kwargs)[source]

Bases: ajaxviews.views.GenericBaseView

This is the base view for normal and preview forms.

The model and success_message attributes from the form meta are automatically added to the view class.

related_obj_ids are 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_cfg is passed in the post request (by default as hidden input field), it’s accessible through the forms cleaned_form_cfg property.

The auto_select_field coming from a GET request is used to update a select field when an element has been added by using add_fields in 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.POSTform_cfgform.Meta (if create view) → view classget_absolute_url

Variables:
  • template_name (str) – The template to render the form. Default: 'ajaxviews/generic_form.html'
  • success_message (str) – Message to display on successful form save. Default: ''
  • form_actions_template (str) – Action buttons rendered at the bottom of the form. Default: 'ajaxviews/_form_controls.html'
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.CreateView

Form view used to create model objects. Inherits functionality from BaseFormView.

Assign django-guardian’s object permissions if assign_perm attribute has been added to the class.

Variables:
  • headline_prefix (str) – The prefix to prepend to the headline which is specified in the form meta. Default: Add
  • assign_perm (bool) – Save object permissions for new model instance of authenticated user. Default: False
class ajaxviews.views.GenericBaseView(*args, **kwargs)[source]

Bases: object

This 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 plugin class 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.
class ajaxviews.views.PreviewCreateView(*args, **kwargs)[source]

Bases: ajaxviews.views.BaseFormView, django.views.generic.edit.CreateView

Preview 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:
  • preview_template_name (str) – Template to use to render the preview. Default: 'ajaxviews/generic_form.html'
  • preview_form_class (object) – Form class to use for preview stage e.g. SimpleForm.
class ajaxviews.views.PreviewUpdateView(*args, **kwargs)[source]

Bases: ajaxviews.views.BaseFormView, django.views.generic.edit.UpdateView

Works the same as PreviewCreateView except 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.UpdateView

Form 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
class ajaxviews.views.ViewFactory(*args)[source]

Bases: object

To 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:
  • first arg (str) – Name of one of the supported plugins. If not specified the base plugin will be used.
  • second arg (str) – Optionally specify the type of the plugin if available.