Template tags¶
cradmin_tags¶
Template tag implementation of
django_cradmin.crinstance.BaseCrAdminInstance.get_titletext_for_role().
Template tag implementation of
django_cradmin.crinstance.BaseCrAdminInstance.get_titletext_for_role().
Template tag implementation of
django_cradmin.crinstance.BaseCrAdminInstance.rolefrontpage_url().
Template tag implementation of
django_cradmin.crapp.App.reverse_appurl().Examples
Reverse the view named
"edit"within the current app:{% load cradmin_tags %} <a href='{% cradmin_appurl "edit" %}'>Edit</a>
Reverse a view with keyword arguments:
{% load cradmin_tags %} <a href='{% cradmin_appurl "list" mode="advanced" orderby="name" %}'> Show advanced listing ordered by name </a>
Template tag implementation of
django_cradmin.crinstance.BaseCrAdminInstance.appindex_url().Examples
Reverse index (frontpage) of current app:
{% load cradmin_tags %} <a href='{% cradmin_appindex_url %}'> Go to pages-app </a>
Reverse a view with keyword arguments:
{% load cradmin_tags %} <a href='{% cradmin_appindex_url mode="advanced" orderby="name" %}'> Show advanced listing ordered by name </a>
Template tag implementation of
django_cradmin.crinstance.BaseCrAdminInstance.appindex_url().Examples
Reverse index (frontpage) of the
"pages"app:{% load cradmin_tags %} <a href='{% cradmin_instance_appindex_url appname="pages" %}'> Go to pages-app </a>
Reverse a view with keyword arguments:
{% load cradmin_tags %} <a href='{% cradmin_instance_appindex_url appname="pages" mode="advanced" orderby="name" %}'> Show advanced listing ordered by name </a>
Template tag implementation of
django_cradmin.crinstance.BaseCrAdminInstance.reverse_url().Examples
Reverse the view named
"edit"within the app named"pages":{% load cradmin_tags %} <a href='{% cradmin_instance_url appname="pages" viewname="edit" %}'> Edit </a>
Reverse a view with keyword arguments:
{% load cradmin_tags %} <a href='{% cradmin_instance_url appname="pages" viewname="list" mode="advanced" orderby="name" %}'> Show advanced pages listing ordered by name </a>
Get the URL of the cradmin instance with the provided
instanceid.Parameters: instanceid – The idif adjango_cradmin.crinstance.BaseCrAdminInstance.
Template tag implementation of
django_cradmin.crinstance.reverse_cradmin_url().Examples
Reverse the view named
"edit"within the app named"pages"in the cradmin-instance with id"my_cradmin_instance"using roleid10:{% load cradmin_tags %} <a href='{% cradmin_url instanceid="my_cradmin_instance" appname="pages" roleid=10 viewname="edit" %}'> Edit </a>
Reverse a view with keyword arguments:
{% load cradmin_tags %} <a href='{% cradmin_url instanceid="my_cradmin_instance" appname="pages" roleid=10 viewname="list" mode="advanced" orderby="name" %}'> Show advanced pages listing ordered by name </a>
Template filter that converts a json serializable object to a json encoded string.
Template tag that converts a json serializable object to a json encoded string and quotes it for use as an attribute value.
Examples
Typical usage:
{% load cradmin_tags %} <div data-something={% cradmin_jsonencode_html_attribute_value serializableobject %}></div>
Notice that we do not add
"around the value - that is done automatically.
Render a
django_cradmin.renderable.AbstractRenderable.Unlike just using
{{ renderable.render }}, this sends therequestinto render (so this is the same as callingrenderable.render(request=context['request']).Examples
Render a renderable named
renderablein the current template context:{% load cradmin_tags %} {% cradmin_render_renderable renderable %}
Adds a CSS class for automatic tests. CSS classes added using this template tag is only included when the the
DJANGO_CRADMIN_INCLUDE_TEST_CSS_CLASSESsetting is set toTrue.To use this template tag, you provide a
suffixas input, and the output will be `` test-<suffix> ``. Notice that we include space before and after the css class - this means that you do not need to add any extra spaces within your class-attribute to make room for the automatic test only css class.Examples
Use the template tag to add test only css classes:
{% load cradmin_tags %} <p class="paragraph paragraph--large{% cradmin_test_css_class 'introduction' %}"> The introduction </p>
Ensure that your test settings have
DJANGO_CRADMIN_INCLUDE_TEST_CSS_CLASSES = True.Write tests based on the test css class:
from django import test import htmls class TestCase(test.TestCase): def test_introduction(self): response = some_code_to_get_response() selector = htmls.S(response.content) with self.assertEqual( 'The introduction', selector.one('test-introduction')
Parameters: suffix – The suffix for your css class. The actual css class will be `` test-<suffix> ``.
Joins a list of css classes.
Parameters: css_classes_list (list) – List or other iterable of css class strings. Examples
Simple example:
{% cradmin_join_css_classes_list my_list_of_css_classes %}
Render a header.
Parameters: - context – template context.
- headername (list) – List or other iterable of css class strings.
Sent to
django_cradmin.crinstance.BaseCrAdminInstance.get_header_renderable()to get the header. - include_context – Forwarded to
cradmin_render_renderable(). - **kwargs – Forwarded to
cradmin_render_renderable().
Examples
Render the default header:
{% cradmin_render_header %} ... or ... {% cradmin_render_header headername='default' %}
Render a custom header:
{% cradmin_render_header headername='myheader' %}
The last example assumes that you have overridden
django_cradmin.crinstance.BaseCrAdminInstance.get_header_renderable()to handle this headername as an argument.
Render breadcrumbs from the
cradmin_breadcrumb_item_listtemplate context variable.If
cradmin_breadcrumb_item_listis not in the template context, or if the cradmin_breadcrumb_item_list is empty (has no breadcrumb items), nothing is rendered.Parameters: - context – template context.
- include_context – Forwarded to
cradmin_render_renderable(). - location (str) – The location to render the breadcrumb item list.
If this is
None(the default), we render the list no matter what. If it has a value, the value must match theget_location()of thecradmin_breadcrumb_item_listitem list. - **kwargs – Forwarded to
cradmin_render_renderable().
Examples
Render the breadcrumbs:
{% cradmin_render_breadcrumb_item_list %}
Render the default header specified via the :setting:DJANGO_CRADMIN_DEFAULT_HEADER_CLASS` setting.
Uses
django_cradmin.crheader.get_default_header_renderable()to get the header renderable.
Render the default footer specified via the :setting:DJANGO_CRADMIN_DEFAULT_FOOTER_CLASS` setting.
Uses
django_cradmin.crfooter.get_default_footer_renderable()to get the footer renderable.
Render the default header specified via the :setting:DJANGO_CRADMIN_DEFAULT_EXPANDABLE_MENU_CLASS` setting.
Uses
django_cradmin.crmenu.get_default_expandable_menu_renderable()to get the expandable menu renderable.
cradmin_icon_tags¶
The cradmin_icon_tags Django template tag library defines tags that makes
it easy to swap out the icons used by the provided Django cradmin components.
It is used like this:
{% load cradmin_icon_tags %}
<span class="{% cradmin_icon 'search' %}"></span>
where {% cradmin_icon 'search' %} will look up css classes for the
icon in the DJANGO_CRADMIN_CSS_ICON_MAP Django setting.
If DJANGO_CRADMIN_CSS_ICON_MAP is not set, we default to
django_cradmin.css_icon_map.FONT_AWESOME, but you can
easily provide your own with something like this in your settings.py:
from django_cradmin import css_icon_map
DJANGO_CRADMIN_CSS_ICON_MAP = css_icon_map.FONT_AWESOME.copy()
DJANGO_CRADMIN_CSS_ICON_MAP.update({
'search': 'my my-search-icon'
})
You can even add your own icons and use cradmin_icon for your own
views/components.
-
FONT_AWESOME= {'bold': 'fa fa-bold', 'caret-down': 'fa fa-caret-down', 'caret-up': 'fa fa-caret-up', 'close-overlay-right-to-left': 'fa fa-chevron-left', 'codeblock': 'fa fa-code', 'h1': 'fa fa-header django-cradmin-icon-font-lg', 'h2': 'fa fa-header', 'h3': 'fa fa-header django-cradmin-icon-font-sm', 'italic': 'fa fa-italic', 'link': 'fa fa-link', 'list-ol': 'fa fa-list-ol', 'list-ul': 'fa fa-list-ul', 'loadspinner': 'fa fa-spin fa-spinner', 'pager-next-page': 'fa fa-chevron-right', 'pager-previus-page': 'fa fa-chevron-left', 'search': 'fa fa-search', 'select-left': 'fa fa-angle-right', 'select-right': 'fa fa-angle-left', 'x': 'fa fa-times'}¶ Font-awesome icon map for the
cradmin_icontemplate tag.