Template tags

cradmin_tags

cradmin_titletext_for_role(context, role)

Template tag implementation of django_cradmin.crinstance.BaseCrAdminInstance.get_titletext_for_role().

cradmin_descriptionhtml_for_role(context, role)

Template tag implementation of django_cradmin.crinstance.BaseCrAdminInstance.get_titletext_for_role().

cradmin_rolefrontpage_url(context, role)

Template tag implementation of django_cradmin.crinstance.BaseCrAdminInstance.rolefrontpage_url().

cradmin_appurl(context, viewname, *args, **kwargs)

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>
cradmin_appindex_url(context, *args, **kwargs)

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>
cradmin_instance_appindex_url(context, appname, *args, **kwargs)

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>
cradmin_instance_url(context, appname, viewname, *args, **kwargs)

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>
cradmin_instanceroot_url(instanceid)

Get the URL of the cradmin instance with the provided instanceid.

Parameters:instanceid – The id if a django_cradmin.crinstance.BaseCrAdminInstance.
cradmin_url(context, instanceid=None, appname=None, roleid=None, viewname='INDEX', *args, **kwargs)

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 roleid 10:

{% 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>
cradmin_jsonencode(json_serializable_pythonobject)

Template filter that converts a json serializable object to a json encoded string.

cradmin_jsonencode_html_attribute_value(json_serializable_pythonobject)

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.

cradmin_theme_staticpath(context)
cradmin_render_renderable(context, renderable, include_context=False, **kwargs)

Render a django_cradmin.renderable.AbstractRenderable.

Unlike just using {{ renderable.render }}, this sends the request into render (so this is the same as calling renderable.render(request=context['request']).

Examples

Render a renderable named renderable in the current template context:

{% load cradmin_tags %}

{% cradmin_render_renderable renderable %}
cradmin_test_css_class(suffix)

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_CLASSES setting is set to True.

To use this template tag, you provide a suffix as 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> ``.
cradmin_join_css_classes_list(css_classes_list)

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 %}
cradmin_render_header(context, headername='default', include_context=True, **kwargs)

Render a header.

Parameters:

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.

cradmin_render_default_header(context)

Render the default header specified via the :setting:DJANGO_CRADMIN_DEFAULT_HEADER_CLASS` setting.

cradmin_render_default_expandable_menu(context)

Render the default header specified via the :setting:DJANGO_CRADMIN_DEFAULT_EXPANDABLE_CLASS` setting.

cradmin_theme_static(context, path, absolute=False)

Works just like the {% static %} template tag, except that it expects path to be relative to the path specified in the DJANGO_CRADMIN_THEME_PREFIX setting.

Parameters:
  • path (str) – The path to lookup.
  • absolute (bool) – Should we create an absolute url including the domain? Defaults to False.

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', 'list-ul': 'fa fa-list-ul', 'h1': 'fa fa-header django-cradmin-icon-font-lg', 'select-left': 'fa fa-angle-right', 'caret-down': 'fa fa-caret-down', 'codeblock': 'fa fa-code', 'pager-next-page': 'fa fa-chevron-right', 'x': 'fa fa-times', 'search': 'fa fa-search', 'caret-up': 'fa fa-caret-up', 'link': 'fa fa-link', 'close-overlay-right-to-left': 'fa fa-chevron-left', 'italic': 'fa fa-italic', 'list-ol': 'fa fa-list-ol', 'h2': 'fa fa-header', 'h3': 'fa fa-header django-cradmin-icon-font-sm', 'loadspinner': 'fa fa-spin fa-spinner', 'select-right': 'fa fa-angle-left', 'pager-previus-page': 'fa fa-chevron-left'}

Font-awesome icon map for the cradmin_icon template tag.