adminlte2_pdq.templatetags package
Subpackages
Submodules
adminlte2_pdq.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.
- adminlte2_pdq.templatetags.adminlte_filters.dict_get(dict_instance, key)
Return value for a dict key or None if key does not exist.
- Parameters:
dict_instance – Dictionary to retrieve the value from with get.
key – Key to use when attempting to get the value.
- Returns:
Value for the dict key or None if key does not exist.
- adminlte2_pdq.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.
- adminlte2_pdq.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.
- adminlte2_pdq.templatetags.adminlte_filters.divide(a, b)
Return result of dividing the first value by the second. Same as python’s / operator.
- Parameters:
a – Dividend in the division operation.
b – Divisor in the division operation.
- Returns:
Result of the division operation.
- adminlte2_pdq.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.
- adminlte2_pdq.templatetags.adminlte_filters.modulo(a, b)
Return remainder after dividing the first value by the second. Same as python’s % operator.
- Parameters:
a – Dividend in the modulo operation.
b – Division in the modulo operation.
- Returns:
Result of the modulo operation.
- adminlte2_pdq.templatetags.adminlte_filters.multiply(a, b)
Return result of multiplying two values. Same as python’s * operator.
- Parameters:
a – First value in multiplication operation.
b – Second value in multiplication operation.
- Returns:
Result of the multiplication operation.
- adminlte2_pdq.templatetags.adminlte_filters.unslugify(field)
Return a string that converts dash to spaces and capitalizes first letter.
- Parameters:
field – Form field to unslugify.
- Returns:
unslugified string of the field passed in.
- adminlte2_pdq.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.
- adminlte2_pdq.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" />
- adminlte2_pdq.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" />
- adminlte2_pdq.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" />
- adminlte2_pdq.templatetags.adminlte_filters.with_input_type(field, new_type)
Change widget input_type to passed value.
- Parameters:
field – Form field to change type on.
new_type – New HTML type that the field should have.
- Returns:
Field that was passed in with input_type changed to passed value.
Example:
{% load adminlte_filters %} {% for field in form %} {% field|with_input_type:'date' %} {% field %} {% endfor %} Which will update the form field to look like the following: <input type="date" name="field" id="id_field" />
- adminlte2_pdq.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" />
- adminlte2_pdq.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" />
- adminlte2_pdq.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" />
- adminlte2_pdq.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" />
- adminlte2_pdq.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" />
- adminlte2_pdq.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" />
adminlte2_pdq.templatetags.adminlte_tags module
Django AdminLTE2 Template Tags
Collection of template tags to make rendering things easier.
- adminlte2_pdq.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.
- adminlte2_pdq.templatetags.adminlte_tags.get_date_widget()
Get a generic setting from the settings file
- adminlte2_pdq.templatetags.adminlte_tags.get_datetime_widget()
Get a generic setting from the settings file
- adminlte2_pdq.templatetags.adminlte_tags.get_home_url()
Get the home URL from the settings and default to the adminlte2_pdq home.
- adminlte2_pdq.templatetags.adminlte_tags.get_login_url()
Get the log in URL from the constants.
- adminlte2_pdq.templatetags.adminlte_tags.get_logo_text()
Get the logo text from the settings and default to AdminLTE
- adminlte2_pdq.templatetags.adminlte_tags.get_logo_text_small()
Get the logo text small from the settings and default to ALTE
- adminlte2_pdq.templatetags.adminlte_tags.get_logout_url()
Get the log out URL from the constants.
- adminlte2_pdq.templatetags.adminlte_tags.get_skin_class()
Get the skin class to use from the settings and default to skin-blue
- adminlte2_pdq.templatetags.adminlte_tags.get_time_widget()
Get a generic setting from the settings file
- adminlte2_pdq.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.
- adminlte2_pdq.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.
- adminlte2_pdq.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.
- adminlte2_pdq.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.
- adminlte2_pdq.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.
- adminlte2_pdq.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.
- adminlte2_pdq.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.
adminlte2_pdq.templatetags.sidebar_menu module
Django AdminLTE2 Sidebar Template Tags
Template tags and logic for rendering sidebar menu
- adminlte2_pdq.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.
- adminlte2_pdq.templatetags.sidebar_menu.check_for_login_whitelisted_node(node)
Check to see if the route property on the node is in the login whitelist
- adminlte2_pdq.templatetags.sidebar_menu.check_for_node_that_matches_request_path(request, nodes)
Check for a node that matches the request path
- adminlte2_pdq.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.
- adminlte2_pdq.templatetags.sidebar_menu.check_for_one_permission_in_node_list(user, nodes)
Check user has one permission in the entire node list
- adminlte2_pdq.templatetags.sidebar_menu.check_for_strict_whitelisted_node(node)
Check to see if the route property on the node is in the whitelist
- adminlte2_pdq.templatetags.sidebar_menu.ensure_node_has_url_property(node, required=True)
Ensure that a node has a url property
- adminlte2_pdq.templatetags.sidebar_menu.get_permissions_from_node(node)
Gets the permission/access data for provided node.
If values are defined on the node itself, then those values take priority over all else.
If node is missing one or more values, then logic falls back to the view, if the values are defined there as per the associated decorators/mixins.
If the view also is missing one or more values, then logic falls back to expected default behavior as per project settings. Mostly those defined by STRICT mode and LOGIN_REQUIRED mode.
- adminlte2_pdq.templatetags.sidebar_menu.get_permissions_from_view(view)
Get the permission/access data from a view.
- adminlte2_pdq.templatetags.sidebar_menu.get_view_from_node(node)
Get the view from the node
- adminlte2_pdq.templatetags.sidebar_menu.is_allowed_node(user, node)
Checks if a node is valid for rendering to current user.
A node is valid for rendering if the user has permissions needed as specified by the node, view, or general project settings.
Values to check against are generally determined by the get_permissions_from_node function. If conflicting values are provided, the most strict interpretation is used.
- adminlte2_pdq.templatetags.sidebar_menu.render_link(context, node)
Render out a menu link.
A menu link is the clickable link within a given node.
- adminlte2_pdq.templatetags.sidebar_menu.render_menu(context)
Render out the sidebar menu.
A menu is the entire menu on the sidebar.
- adminlte2_pdq.templatetags.sidebar_menu.render_nodes(context, nodes)
Render out a list of nodes.
A node is an individual clickable item within the menu.
- adminlte2_pdq.templatetags.sidebar_menu.render_section(context, section)
Render out an entire sidebar section.
A section is a grouping of items within the menu.
- adminlte2_pdq.templatetags.sidebar_menu.render_tree(context, node)
Render out a menu tree.
A tree is an optional, expandable item with nodes within it.
- adminlte2_pdq.templatetags.sidebar_menu.strip_hash_bookmark_from_url(url)
Strip the hash bookmark from a string url