Internals

The documentation below details some of the internal workings of django-userextensions and its components. This documentation is automatically generated from the source code. See the source code in github for full details.

https://github.com/davidslusser/django-handyhelpers

GUI Views

class handyhelpers.views.gui.HandyHelperGenericBaseView(**kwargs)
Generic view used to set the base_template variable. This extends django.view.generic.View and will use the base
template defined in the BASE_TEMPLATE settings variable or use handyhelpers/handyhelpers_base.htm if not provided.
class parameters:
base_template - base template used for rendering page; defaults to: handyhelpers_base.htm args - additional args to pass into the template kwargs - additional kwargs to pass into the template
class handyhelpers.views.gui.HandyHelperGenericBaseItemizedView(**kwargs)

Generic view to include shared variables used in views itemized views, such as index and action views.

class parameters:
base_template - base template used for rendering page; defaults to: handyhelpers_base.htm args - additional args to pass into the template kwargs - additional kwargs to pass into the template title - page title to use; will display in a H1 element subtitle - subtitle to use; will display in a H5 element (None if not provided) item_list - list of items/actions to display (one per card) protected_item_list - list of items/action only visible to members of protected_group_name protected_group_name - name of group to show protected_item_list items to
class handyhelpers.views.gui.HandyHelperGenericBaseListView(**kwargs)

Generic list view used to set the base_template, template, title, table, and modal variables. This extends django.view.generic.ListView and will use the base template defined in the BASE_TEMPLATE settings variable or use handyhelpers/handyhelpers_base.htm if not provided. This view also includes the handyhelpers.mixins.view_mixins.FilterByQueryParamsMixin mixin to allow filtering by query parameters.

class parameters:
base_template - base template used for rendering page; defaults to: handyhelpers_base.htm template_name - template used when rendering page; defaults to: handyhelpers/generic/generic_list.html title - title to use in template table - htm file rendering the queryset to be included in the generic_list template modals - htm file rendering additional modals to be included in the generic_list template
class handyhelpers.views.gui.HandyHelperActionView(**kwargs)

Action page with actions/options listed as ‘zoom-cards’ in flex-box container(s)

class parameters:
base_template - base template used for rendering page; defaults to: handyhelpers_base.htm args - additional args to pass into the template kwargs - additional kwargs to pass into the template template_name - template used when rendering page; defaults to: handyhelpers/generic/generic_action.html title - page title to use; will display in a H1 element subtitle - subtitle to use; will display in a H5 element (None if not provided) item_list - list of items/actions to display (one per card) protected_item_list - list of items/action only visible to members of protected_group_name protected_group_name - name of group to show protected_item_list items to form_list - list of django forms used in page
class handyhelpers.views.gui.HandyHelperAboutView(**kwargs)

Generic view to render an ‘about’ page.

class parameters:
base_template - base template used for rendering page; defaults to: handyhelpers_base.htm args - additional args to pass into the template kwargs - additional kwargs to pass into the template template_name - template used when rendering page; defaults to: handyhelpers/generic/generic_about.html title - page title to use (‘About’ if not provided) subtitle - subtitle to use (None if not provided) version - version to display (None if not provided) details - any specific details to display (None if not provided) source - link to source code repository (None if not provided) contact - any desired contact information (None if not provided) links - list of dictionary containing links; ex. [{‘some reference’: ‘www.somewebsite.com}, …]
class handyhelpers.views.gui.HandyHelperSingletonView(**kwargs)

View for rendering a page based on a SingletonModel

class parameters:
base_template - base template used for rendering page; defaults to: handyhelpers_base.htm args - additional args to pass into the template kwargs - additional kwargs to pass into the template template_name - template used when rendering page model - singleton model
class handyhelpers.views.gui.HandyHelperListView(**kwargs)

A reusable generic base view to render a ListView where the child view will provide a html table.

class parameters:
base_template - base template used for rendering page; defaults to: handyhelpers_base.htm template_name - template used when rendering page; defaults to: handyhelpers/generic/generic_list.html args - additional args to pass into the template kwargs - additional kwargs to pass into the template queryset - queryset to be rendered on the page title - title to use in template page_description - subtitle to use in template table - htm file rendering the queryset to be included in the generic_list template modals - htm file rendering additional modals to be included in the generic_list template
example:
class ListProjects(HandyHelperBaseListView):
queryset = Project.objects.all() title = ‘Projects’ page_description = ‘my cool projects’ table = ‘table/table_projects.htm’ modals = ‘project_modals.htm’
class handyhelpers.views.gui.HandyHelperListPlusCreateView(**kwargs)

A reusable generic base view to render a ListView where the child view will provide a html table and create form.

class parameters:

base_template - base template used for rendering page; defaults to: handyhelpers_base.htm template_name - template used when rendering page; defaults to: handyhelpers/generic/generic_list.html args - additional args to pass into the template kwargs - additional kwargs to pass into the template queryset - queryset to be rendered on the page title - title to use in template page_description - subtitle to use in template table - htm file rendering the queryset to be included in the generic_list template modals - htm file rendering additional modals to be included in the generic_list template allow_create_groups - comma separated list of groups that are allowed to create a new record

create_form_obj - form object create_form_url - url the form (action) should post to create_form_title - title to use on the create form modal (can be html) create_form_modal - name of modal for the create form create_form_modal_size - bootstrap modal size class (such as modal-lg) create_form_modal_backdrop - optional data-backdrop value(such as data-backdrop=”static”) create_form_link_title - text used for the link opening the create form create_form_tool_tip - text to use for the tooltip create_form_autocomplete - autocomplete parameter to use in form tag (on/off)

example:
class ListProjects(HandyHelperBaseCreateListView):

queryset = Project.objects.all() title = ‘Projects’ page_description = ‘my cool projects’ table = ‘table/table_projects.htm’

create_form_obj = ProjectForm create_form_url = ‘/hostmgr/create_project/’ create_form_title = ‘<b>Add Project: </b><small> </small>’ create_form_modal = ‘add_project’ create_form_modal_size = ‘modal-lg’ create_form_modal_backdrop = ‘static’ create_form_link_title = ‘add project’ create_form_tool_tip = ‘add project’

class handyhelpers.views.gui.HandyHelperListPlusFilterView(**kwargs)

A reusable generic base view to render a ListView where the child view will provide a html table and filter form.

class parameters:

base_template - base template used for rendering page; defaults to: handyhelpers_base.htm template_name - template used when rendering page; defaults to: handyhelpers/generic/generic_list.html args - additional args to pass into the template kwargs - additional kwargs to pass into the template queryset - queryset to be rendered on the page title - title to use in template page_description - subtitle to use in template table - htm file rendering the queryset to be included in the generic_list template modals - htm file rendering additional modals to be included in the generic_list template

filter_form_obj - form object filter_form_url - url the form (action) should post to filter_form_title - title to use on the filter form modal (can be html) filter_form_modal - name of modal for the filter form filter_form_modal_size - bootstrap modal size class (such as modal-lg) filter_form_modal_backdrop - optional data-backdrop value(such as data-backdrop=”static”) filter_form_link_title - text used for the link opening the filter form filter_form_tool_tip - text to use for the tooltip filter_form_undo - True filter_form_autocomplete - autocomplete parameter to use in form tag (on/off)

example:
class ListProjects(HandyHelperListPlusFilterView):

queryset = Project.objects.all() title = ‘Projects’ page_description = ‘my cool projects’ table = ‘table/table_projects.htm’

filter_form_obj = ProjectForm filter_form_url = ‘/hostmgr/filter_project/’ filter_form_title = ‘<b>Filter Projects: </b><small> </small>’ filter_form_modal = ‘filter_project’ filter_form_modal_size = ‘modal-lg’ filter_form_modal_backdrop = ‘static’ filter_form_link_title = ‘filter project’ filter_form_tool_tip = ‘filter project’

class handyhelpers.views.gui.HandyHelperListPlusCreateAndFilterView(**kwargs)

A reusable generic base view to render a ListView where the child view will provide a html table and and a create form and a filter form.

class parameters:

base_template - base template used for rendering page; defaults to: handyhelpers_base.htm template_name - template used when rendering page; defaults to: handyhelpers/generic/generic_list.html args - additional args to pass into the template kwargs - additional kwargs to pass into the template queryset - queryset to be rendered on the page title - title to use in template page_description - subtitle to use in template table - htm file rendering the queryset to be included in the generic_list template modals - htm file rendering additional modals to be included in the generic_list template allow_create_groups - comma separated list of groups that are allowed to create a new record

create_form_obj - create form object create_form_url - url the create form (action) should post to create_form_title - title to use on the create form modal (can be html) create_form_modal - name of modal for the create form create_form_modal_size - bootstrap modal size class (such as modal-lg) create_form_modal_backdrop - optional data-backdrop value(such as data-backdrop=”static”) create_form_link_title - text used for the link opening the create form create_form_tool_tip - text to use for the create form link tooltip create_form_autocomplete - autocomplete parameter to use in form tag (on/off)

filter_form_obj - filter form object filter_form_url - url the filter form (action) should post to filter_form_title - title to use on the filter form modal (can be html) filter_form_modal - name of modal for the filter form filter_form_modal_size - bootstrap modal size class (such as modal-lg) filter_form_modal_backdrop - optional data-backdrop value(such as data-backdrop=”static”) filter_form_link_title - text used for the link opening the filter form filter_form_tool_tip - text to use for the filter form link tooltip filter_form_undo - include an undo icon to clear applied filters filter_form_autocomplete - autocomplete parameter to use in form tag (on/off)

example:
class ListProjects(HandyHelperBaseCreateListView):

queryset = Project.objects.all() title = ‘Projects’ page_description = ‘my cool projects’ table = ‘table/table_projects.htm’

create_form_obj = ProjectForm create_form_url = ‘/hostmgr/create_project/’ create_form_title = ‘<b>Add Project: </b><small> </small>’ create_form_modal = ‘add_project’ create_form_modal_backdrop = ‘static’ create_form_link_title = ‘add project’ create_form_tool_tip = ‘add project’

filter_form_obj = ProjectForm filter_form_url = ‘/hostmgr/filter_project/’ filter_form_title = ‘<b>Filter Projects: </b><small> </small>’ filter_form_modal = ‘filter_projects’ filter_form_modal_backdrop = ‘static’ filter_form_link_title = ‘filter projects’ filter_form_tool_tip = ‘filter projects’ filter_form_undo = True

Export Views

class handyhelpers.views.export.CsvExportView(**kwargs)

View to dump a queryset to a csv file

class parameters:
queryset - queryset to be rendered on the page filename - filename for the output file created; model name used if not provided
class handyhelpers.views.export.ExcelExportView(**kwargs)

View to dump a queryset to a xls file

class parameters:
queryset - queryset to be rendered on the page filename - filename for the output file created; model name used if not provided

View Mixins

class handyhelpers.mixins.view_mixins.FilterByQueryParamsMixin

Mixin used to evaluate query parameters provided in the URL and update a queryset accordingly. This is typically used on list views. Query parameters passed must be valid model fields. Invalid parameters are ignored.

class parameters:
request - request object queryset - django queryset page_description - optional parameter used to describe page; typically used as a page subtitle distinct - optional parameter to make queryset include only distinct results
example usage:
class HandyHelperGenericBaseListView(FilterByQueryParamsMixin, ListView)
filter_by_query_params()
Description:
Filters a queryset by query_params in the URL
Returns:
filtered queryset

Viewset Mixins

class handyhelpers.mixins.viewset_mixins.InvalidLookupMixin

A mixin for Django Rest Framework viewsets to check query parameters and return an error if any query parameter is not a included in defined in a filter_class (typically defined in your filterset), and element of filter_fields (typically set in your viewset), or a valid model field. Order of precedence is: filter_class, filterset_fields, filter_fields, model field.

class parameters:
request - request object (as provided by Viewset) model - django model (as provided by Viewset) queryset - django queryset (as provided by Viewset) filterset_class - optional filterset_class (as provided by Viewset) filter_class - optional filter_class (as provided by Viewset) filterset_fields - optional filterset_fields (as provided by Viewset) filter_fields - optional filter_fields (as provided by Viewset)
example usage:
class MyModelViewSet(InvalidLookupMixin, viewsets.ReadOnlyModelViewSet):
get_lookup_expression(fs_filter, related_field=None, lookup_expression_list=None)

get lookup expressions as defined in a FilterSet filter

Args:
fs_filter: list of filters as defined in the filterset related_field: related field as defined in filterset lookup_expression_list: list of lookup expressions as defined for a field in a filterset
Returns:
list of filtered lookup expressions
class handyhelpers.mixins.viewset_mixins.PaginationControlMixin

A mixin for Django Rest Framework viewsets that allows pagination to be disabled by including a specific query parameter. Default query parameter for disabling pagination is ‘disable_pagination’ and this can be modified by setting the PAGINATION_CONTROL_PARAMETER variable to the desired value in django settings.

Permission Mixins

Description:
Collection of helpers to assist with permissions on views
How to use:

Add in your view as a mixin and define groups per method in permission_dict. Example:

class MyView(InAnyGroup, View):
permission_dict = {‘POST’: [‘superusers’],
‘GET’: [‘operators’] }
class handyhelpers.permissions.InAllGroups
Description:
Restrict access based on request method and user group; user must be in ALL required groups
Usage:
add as mixin to class definition and put the following in your viewset:
permission_dict = {‘POST’: [‘site_operators’, ‘site_admins’],
‘GET’: [‘site_operators’],

}

to restrict POST, but allow GET for all users use the following:
permission_dict = {‘POST’: [‘site_admins’],
‘GET’: [],

}

class handyhelpers.permissions.InAnyGroup
Description:
Restrict access based on request method and user group; user can be in ANY required group
Usage:
add as mixin to class definition and put the following in your viewset:
permission_dict = {‘POST’: [‘site_admins’],
‘GET’: [‘site_admins’, ‘site_operators’],

}

to restrict POST, but allow GET for all users use the following:
permission_dict = {‘POST’: [‘site_admins’],
‘GET’: [],

}

DRF Permission Mixins

Permissions classes used with DRF APIs

class handyhelpers.drf_permissions.IsInAllGroups
Description:
Restrict access based on request method and user group; user must be in ALL required groups
Usage:
put the following in your viewset:

permission_classes = (IsInAllGroups,) required_groups = {‘POST’: [‘site_admins’],

‘PATCH’: [‘site_admins’], ‘PUT’: [‘site_admins’], ‘DELETE’: [‘site_admins’, ‘site_managers’],

}

has_permission(request, view)

Return True if permission is granted, False otherwise.

class handyhelpers.drf_permissions.IsInAnyGroup
Description:
Restrict access based on request method and user group; user can be in ANY required group
Usage:
put the following in your viewset:

permission_classes = (IsInAnyGroup,) required_groups = {‘POST’: [‘site_admins’],

‘PATCH’: [‘site_admins’], ‘PUT’: [‘site_admins’], ‘DELETE’: [‘site_admins’, ‘superusers’],

}

has_permission(request, view)

Return True if permission is granted, False otherwise.