django_adminlte_2.templatetags package
Subpackages
Submodules
django_adminlte_2.templatetags.adminlte_filters module
Django AdminLTE2 Template Filters
Various filters that can be used to work with a django form to add missing attributes that the user would like the form fields to have.
- django_adminlte_2.templatetags.adminlte_filters.dictionary(field)
Return the result of calling __dict__ on an object.
- Parameters
field – Form field to run __dict__ on.
- Returns
__dict__ of the field passed in.
- django_adminlte_2.templatetags.adminlte_filters.directory(field)
Return the result of calling dir on an object.
- Parameters
field – Form field to run dir on.
- Returns
dir of the field passed in.
- django_adminlte_2.templatetags.adminlte_filters.fieldtype(field)
Get a string representation of what fieldtype a given field is.
- Parameters
field – Form Field to get the type of.
- Returns
String representation of form field type.
- django_adminlte_2.templatetags.adminlte_filters.unslugify(field)
Return a string that converts dash to spaces and capitalizes first letter.
- Parameters
field – Form field to unslugify.
- Returns
dir of the field passed in.
- django_adminlte_2.templatetags.adminlte_filters.unsnake(field)
Return a string that converts underscore to spaces and capitalizes first letter.
- Parameters
field – Form field to unsnake.
- Returns
unsnaked string of the field passed in.
- django_adminlte_2.templatetags.adminlte_filters.with_attrs(field, attrs_as_json=None)
Add generic attributes to a form field and return the form field so filters can be chained.
- Parameters
field – Form field to add attributes to.
attrs_as_json – The attrs to add to the field. Must be in the form of json. Defaults to None.
- Returns
Field that was passed in with attrs added.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|with_attrs:'{"attribute-1":"value-1", "attribute-2":"value-2"}' %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="text" name="field" attribute-1="value-1" attribute-2="value-2" id="id_field" />
- django_adminlte_2.templatetags.adminlte_filters.with_class(field, class_name='')
Add a class attribute to a form field and return the form field so filters can be chained.
- Parameters
field – Form field to add attributes to.
class_name – Class name to add to add to the field. Defaults to blank string.
- Returns
Field that was passed in with classes added.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|with_class:'my-added-class' %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="text" name="field" class="my-added-class" id="id_field" />
- django_adminlte_2.templatetags.adminlte_filters.with_data(field, data_attrs_json=None)
Add data attributes to a form field and return the form field so filters can be chained.
- Parameters
field – Form field to add data attributes to.
data_attrs_json – The data fields to add. Must be in the form of json. Defaults to None.
- Returns
Field that was passed in with data attributes added.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|with_data:'{"attribute-1":"value-1", "attribute-2":"value-2"}' %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="text" name="field" data-attribute-1="value-1" data-attribute-2="value-2" id="id_field" />
- django_adminlte_2.templatetags.adminlte_filters.with_input_type(field, new_type)
Change widget input_type to passed value.
- Parameters
field – Form field to change type on.
- Returns
Field that was passed in with input_type changed to passed value.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|as_input_type:'date' %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="date" name="field" id="id_field" />
- django_adminlte_2.templatetags.adminlte_filters.with_inputmask(field, inputmask=None)
Add inputmask to a form field and return the form field so filters can be chained. Depending on the complexity of inputmask, the Django template engine may not be able to handle parsing the mask. If this is the case, the inputmask will need to be stored in a variable where the variable can be sent to the filter.
- Parameters
field – Form field to add attributes to.
inputmask – The inputmask pattern to use. Defaults to “(999) 999-9999” if value not passed.
- Returns
Field that was passed in with a inputmask data attribute added.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|with_inputmask:'(999) 999-9999' %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="tel" name="field" data-inputmask="'mask':'(999) 999-9999'" id="id_field" />
- django_adminlte_2.templatetags.adminlte_filters.with_list(field, name=None)
Add list attribute to a form field and return the form field so filters can be chained. This will not automatically create the datalist elements. It will only add the list attribute to the element with name provided.
- Parameters
field – Form field to add attributes to.
name – The datalist name. Defaults to ‘_list’ appended to end of field name.
- Returns
Field that was passed in with list attribute added.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|with_list:"my_awesome_list" %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="text" name="field" list="my_awesome_list" id="id_field" />
- django_adminlte_2.templatetags.adminlte_filters.with_max(field, max_val=None)
Add max attribute to a form field and return the form field so filters can be chained.
- Parameters
field – Form field to add attributes to.
max_val – The max value to use. Defaults to 100 if value not passed.
- Returns
Field that was passed in with max attribute added.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|with_max:9 %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="range" name="field" max="9" id="id_field" />
- django_adminlte_2.templatetags.adminlte_filters.with_min(field, min_val=None)
Add min attribute to a form field and return the form field so filters can be chained.
- Parameters
field – Form field to add attributes to.
min_val – The min value to use. Defaults to 0 if value not passed.
- Returns
Field that was passed in with min attribute added.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|with_min:5 %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="range" name="field" min="5" id="id_field" />
- django_adminlte_2.templatetags.adminlte_filters.with_pattern(field, pattern=None)
Add pattern to a form field and return the form field so filters can be chained. Unfortunately, the Django template engine can’t handle parsing a string regex passed to this filter. Therefore, the regex string needs to be stored in a variable that can be sent to the filter.
NOTE: The default regex in this method is written as a regular string and not a raw string (regex with r prefix) so that the documentation will match. This docstring can not contain a single backslash as python will think it is invalid syntax and raise a warning.
- Parameters
field – Form field to add attributes to.
pattern – The JavaScript regex pattern to use. Defaults to “([0-9]{3}) [0-9]{3}-[0-9]{4}” if value not passed.
- Returns
Field that was passed in with pattern attribute added.
Example:
# Assuming the field has a property called pattern with a string value # that is the needed regex: "\([0-9]{3}\) [0-9]{3}-[0-9]{4}" # We can send that variable to the filter. {% load adminlte_filters %} {% for field in form %} {% field|with_pattern:field.pattern %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="tel" name="field" pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}" id="id_field" />
- django_adminlte_2.templatetags.adminlte_filters.with_placeholder(field, placeholder=None)
Add placeholder to a form field and return the form field so filters can be chained.
- Parameters
field – Form field to add placeholder to.
placeholder – Placeholder text to use. Defaults to fields label if nothing provided.
- Returns
Field that was passed in with placeholder added.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|with_placeholder 'My Placeholder Text' %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="text" name="field" placeholder="My Placeholder Text" id="id_field" />
django_adminlte_2.templatetags.adminlte_helpers module
Django AdminLTE2 Template Tags
Collection of template tags to make rendering things easier.
- django_adminlte_2.templatetags.adminlte_tags.get_avatar_url(context, user=None, email=None, size=None, default='mp')
Get a gravatar image url. If no image is found, gravatar will return an image based on the ‘default’ keyword. See http://en.gravatar.com/site/implement/images/ for more info.
- This function will get the profile email in this order:
The ‘email’ argument, The ‘user’ argument if it has an ‘email’ attribute.
NOTE: Method does not work if context is not taken in despite it not using it.
- Parameters
context – Context that is not used.
user – User that may have an email that can be used for gravatar.
email – Email that can be used for gravatar.
size – Size if it needs to be overridden.
default – The default gravatar that will be used if no email.
- django_adminlte_2.templatetags.adminlte_tags.get_home_url()
Get the home URL from the settings and default to the django_adminlte_2 home.
- django_adminlte_2.templatetags.adminlte_tags.get_logo_text()
Get the logo text from the settings and default to AdminLTE
- django_adminlte_2.templatetags.adminlte_tags.get_logo_text_small()
Get the logo text small from the settings and default to ALTE
- django_adminlte_2.templatetags.adminlte_tags.get_logout_url()
Get the log out URL from the settings.
- django_adminlte_2.templatetags.adminlte_tags.get_skin_class()
Get the skin class to use from the settings and default to skin-blue
- django_adminlte_2.templatetags.adminlte_tags.render_fields(*fields_to_render, labels=True, media=None, **kwargs)
Render given fields with optional labels.
- Parameters
fields_to_render – List or tuple of fields to render out.
labels – Whether to use labels for fields. Defaults to True.
media – Media that needs to be used in the form. Defaults to None.
- Returns
Context to use with template.
- django_adminlte_2.templatetags.adminlte_tags.render_form(form, labels=True, media=None, **kwargs)
Render a vertical form where fields are always below the label.
- Parameters
form – Form to render.
labels – Whether to use labels for fields. Defaults to True.
media – Media that needs to be used in the form. Defaults to None.
- Returns
Fields to render.
- django_adminlte_2.templatetags.adminlte_tags.render_form_error_summary(context)
Determine if the context contains forms or formsets that should be checked for errors, and then add any found errors to the context so they can be rendered out at the top of the page.
- Parameters
context – Context for the template.
- Returns
Context for the template.
- django_adminlte_2.templatetags.adminlte_tags.render_horizontal_fields(*fields_to_render, labels=True, media=None, **kwargs)
Render given fields with optional labels horizontally.
- Parameters
fields_to_render – List or tuple of fields to render.
labels – Whether to use labels for fields. Defaults to True.
media – Media that needs to be used in the form. Defaults to None.
- Returns
Context to use with template.
- django_adminlte_2.templatetags.adminlte_tags.render_horizontal_form(form, labels=True, media=None, **kwargs)
Render a horizontal form.
- Parameters
form – The form to render.
labels – Whether to use labels for fields. Defaults to True.
media – Media that needs to be used in the form. Defaults to None.
- Returns
Context for the template.
- django_adminlte_2.templatetags.adminlte_tags.render_horizontal_formset(formset, section_heading)
Render a horizontal formset.
- Parameters
formset – The formset to render.
section_heading – The section header to render.
- Returns
Context for the template.
- django_adminlte_2.templatetags.adminlte_tags.user_image_initials(context, user=None, email=None, initials=None, first_name='', last_name='', size=None)
Show user gravatar, initials, or gravatar default mystery person as image
Attempt to use/create initials of the user in the style of a profile picture. Overlay with the user’s gravatar image or a blank one if the user does not exist. If initials can not be created, change the gravatar default from blank to the standard mystery person.
If the user is passed in, the user will be used for the base information. Information can be overridden by other key word arguments. If the user is NOT passed in, key word arguments for each piece of information should be used.
- Parameters
context – Context for the template.
user – The user to use for information.
email – The email to use for information.
initials – The initials to use in place of generated ones.
first_name – The first name to use in place of the users.
last_name – The last name to use in place of the users.
size – Size if it needs to be overridden. Default is 25x25.
- Returns
Context for template.
django_adminlte_2.templatetags.sidebar_menu module
Django AdminLTE2 Sidebar Template Tags
Template tags and logic for rendering sidebar menu
- django_adminlte_2.templatetags.sidebar_menu.check_for_all_permissions(user, permissions)
Check to see if the passed user has all of the permissions
that are listed in the passed permissions. If the user does not have all of them, false is returned. If the passed permission list is empty, the method returns false. Even though empty permission lists return false here, they are checked with the whitelist methods in the is_allowed_node method. Unless you know what you are doing, consider using is_allowed_node for true permission checking on a node.
- django_adminlte_2.templatetags.sidebar_menu.check_for_login_whitelisted_node(node)
Check to see if the route property on the node is in the login whitelist
- django_adminlte_2.templatetags.sidebar_menu.check_for_node_that_matches_request_path(request, nodes)
Check for a node that matches the request path
- django_adminlte_2.templatetags.sidebar_menu.check_for_one_permission(user, permissions)
Check to see if the passed user has at least one of the permissions
that are listed in the passed permissions. If the user does not have one of them, false is returned. If the passed permission list is empty, the method returns false. Even though empty permission lists return false here, they are checked with the whitelist methods in the is_allowed_node method. Unless you know what you are doing, consider using is_allowed_node for true permission checking on a node.
- django_adminlte_2.templatetags.sidebar_menu.check_for_one_permission_in_node_list(user, nodes)
Check user has one permission in the entire node list
- django_adminlte_2.templatetags.sidebar_menu.check_for_strict_whitelisted_node(node)
Check to see if the route property on the node is in the whitelist
- django_adminlte_2.templatetags.sidebar_menu.ensure_node_has_url_property(node)
Ensure that a node has a url property
- django_adminlte_2.templatetags.sidebar_menu.get_permissions_from_node(node)
Gets the permissions required from the node
by using either the ‘route’ or ‘url’ key on the node to determine the associated view for the route/url. Then checks the view to see if it contains properties for the required permissions and returns them if found.
- django_adminlte_2.templatetags.sidebar_menu.get_permissions_from_view(view)
Get the permissions and login_required from a view
- django_adminlte_2.templatetags.sidebar_menu.get_view_from_node(node)
Get the view from the node
- django_adminlte_2.templatetags.sidebar_menu.is_allowed_node(user, node)
Checks to ensure a node is valid for rendering.
An all encompassing method that checks all permissions, one of permissions and the whitelist settings to know whether or not a given node is valid for rendering to the user. Any new code that needs to check permissions should use this method.
- django_adminlte_2.templatetags.sidebar_menu.render_link(context, node)
Render out a menu link
- django_adminlte_2.templatetags.sidebar_menu.render_menu(context)
Render out the sidebar menu
- django_adminlte_2.templatetags.sidebar_menu.render_nodes(context, nodes)
Render out a list of nodes
- django_adminlte_2.templatetags.sidebar_menu.render_section(context, section)
Render out an entire sidebar section
- django_adminlte_2.templatetags.sidebar_menu.render_tree(context, node)
Render out a menu tree
- django_adminlte_2.templatetags.sidebar_menu.strip_hash_bookmark_from_url(url)
Strip the hash bookmark from a string url
- django_adminlte_2.templatetags.sidebar_menu.url_starts_with(search_string, sub_string)
Determine if a url starts with a sub string