Package: django-utensils
A collection of reusable components to help build Django projects.InstallationTo install the latest stable release:pip install django-utensilsTo get the latest dev version, install directly form GitHub like so:pip install -e git://github.com/code-kitchen/django-utensils.git#egg=django-utensilsMany of the template tags require therequestobject. You need to
add ‘django.template.context_processors.request’ (Django 1.6 and 17) or
‘django.template.context_processors.request’ (Django 1.8) to the
template context processors in your settings.To use theAddressedModelyou will need to addcountries_plusto
yourINSTALLED_APPSsetting.FormsSearchFormGeneric search form that can be used on any page.Used byviewmixins.SearchFormMixin.UniqueModelFieldsMixinMixin that enforces unique fields on ModelForm form fields.Must be left of ModelForm when defining the form class (seehttps://code.djangoproject.com/ticket/13075).There are two ways to list your unique fields depending on whether or
not you want case insensitivity.unique_fields=['name','username']unique_fields=['name',{'field':'username','case_insensitive':True}]MiddlewareHidden siteBy addingutensils.middleware.HiddenSiteMiddlewareto yourMIDDLEWARE_CLASSESyou can prevent people from viewing your site
unless they use a query string parameter. The parameter is not needed
for subsequent visits (unless cookies are cleared). This is a quick and
simple method to keep prying eyes off your staging server for example.
Provide the parameter name in the settings variableHIDDEN_SITE_SECRET.For example:MIDDLEWARE_CLASSES+=('utensils.middleware.HiddenSiteMiddleware',)HIDDEN_SITE_SECRET='whisky'Using the built-in development server browsing tohttp://localhost/will
give the message “ACCESS DENIED”. Browing tohttp://localhost/?whiskywill succeed. Subsequent visits tohttp://localhost/(no?whisky)
with the same browser will succeed until cookies are cleared or the
cookie expires (currently set to a year).View mixinsCollection of mixins for class-based views.List view paginationThePaginateMixinreturns the paginate by setting used by the
pagination template tag{% pagination %}so the DjangoListViewfunctions can use it.You will need to addutensils.context_processors.paginationto your
context processors for the template tag to work. Setsettings.PAGINATION_PAGE_SIZESto control the page size, if not set
the default[20, 50, 100]is used.List view orderingTheOrderByMixinallows easy ordering of list views. By including it
the template tag ({% order_by 'field_name' %}) is given sorting
context variables to work with.get_querysetis overidden to make
use of these and order the object list.Generic single-field searchTheSearchFormMixinprovides a handy way to add search to list
views. Add thesearch_formmanually in your template or use the
included fragment{% include 'fragments/_search.html' %}.Specify the fields you wish to search on, and how, by including asearch_fieldsdictionary on your view like so:classCustomerListView(SearchFormMixin,ListView):model=Customersearch_fields={'user__email':'icontains','first_name':'icontains','last_name':'icontains','postal_code':'icontains',}MessageMixinBy including and providingsuccess_messageand/orerror_messageattributes on your view class, messages will be added automatically to
the request objects on events suchs as valid and invalid forms and
formsets, object deletion etc.PermissionRequiredMixinThis mixin verfies the user is logged in and has the required
permissions to access the view. It’s a modified version of the
django-braces mixin with an added bypass. Settingpermission_required = Falseallows you to skip the check whilst
keeping the mixin in a base view used across a project, for example.Settings:permission_required- the permission to check for or False to
skip checklogin_url- the login url of siteredirect_field_name- defaults to “next”raise_exception- defaults to False - raise 403 if set to TrueRedirectToNextMixinIf anextquery string parameter is preset on apost()call it
is assigned to the instancesuccess_url.StaffViewMixinCombinesMessageMixin,RedirectToNextMixin,StaffuserRequiredMixin(from django-brances),PermissionRequiredMixinto create a useful mixin that can be used on
all staff views.ViewsBaseListViewThis view combines the pagination, order by and search mixins and adds
an optional query set filter description that your templates can use.classActiveCustomerList(BaseListView):filter_description=u"Active"queryset=Customer.active.all(){% block content %}<h2>{% if filter_description %}
      {{ filter_description|title }} customers
    {% else %}
      Customers
    {% endif %}</h2><!-- more template -->{% end block %}Yields:<h2>Active customers<h2><!-- more template -->SetModelFieldViewThis view can be used to set the value of a field on a model instance.
GET will display a template (and should be used as a confirmation page)
and the value will be set on POST. The view usesdjango.views.generic.detail.BaseDetailViewto provideget_object().classCustomerInactiveView(SetModelFieldView):"""
    Ask the user if they're sure they want to make the customer inactive. If
    they confirm by submitting the form set is_active to False and save.
    """model=Customerfield='is_active'value=Falsetemplate_name="customers/customer_inactive.html"If you require more control and want to introduce some logic when
selecting the value or field to alter you can overrideget_field()andget_value()instead of setting thefieldandvalueclass
attributes.StorageS3Thestoragemodules provides a way to easily store static or media
files on Amazon S3.To use you will need to update yoursettingswith the appropriate
configuration, something like this:AWS={'STATIC':{'location':'static',# AWS_LOCATION'querystring_auth':False,# AWS_QUERYSTRING_AUTH'default_acl':'public-read',# AWS_DEFAULT_ACL},'MEDIA':{'location':'media',# AWS_LOCATION'querystring_auth':True,# AWS_QUERYSTRING_AUTH'default_acl':'private',# AWS_DEFAULT_ACL},}AWS_ACCESS_KEY_ID='XXXXXXXXXXXXXXXXXXXX'AWS_SECRET_ACCESS_KEY='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'AWS_STORAGE_BUCKET_NAME='bucket'AWS_PRELOAD_METADATA=TrueAWS_S3_SECURE_URLS=FalseSTATICFILES_STORAGE='utensils.storage.StaticRootS3BotoStorage'DEFAULT_FILE_STORAGE='utensils.storage.MediaRootS3BotoStorage'Miscellaneous utilsThere are utility functions in theutilsmodule that deal with a
range of things. Some are used by other parts of the library.