Template tags

Tag reference

get_data_template(context, context_data=None)[source]

Returns template that should be used for rendering current serializer data

Parameters:context – template context (automatically provided by django)
Returns:template file name
render_field(field, style)[source]

Renders separate field. Style is a dict, that contains template_pack or form_template and rendered. It is defined when rendering form, so it is best to use that one. To do that dynamicforms should be loaded first.

See example below.

{% load dynamicforms %}
{% for field in form %}
  {% if not field.read_only %}
    {% render_field field style=style %}
  {% endif %}
{% endfor %}
Parameters:
  • field – Serializer Field instance
  • style – render parameters
Returns:

rendered field template

render_form(serializer, form_template=None)[source]

Renders form from serializer. If form_template is given, then renderer will use that one, otherwise it will use what is defined in self.base_template (e.g.: »form.html«) from template_pack (e.g.: »dynamicforms/bootstrap/field/«)

{% set_var template_pack=DYNAMICFORMS.template|add:'field' %}
{% render_form serializer template_pack=template_pack %}
Parameters:
  • serializer – Serializer object
  • form_template – form template file name to use. overrides all other template name declarations
Returns:

rendered template

set_var(context, **kwds)[source]

Sets the given variables to provided values. Kind of like the ‘with’ block, only it isn’t a block tag

Parameters:
  • context – template context (automatically provided by django)
  • kwds – named parameters with their respective values
Returns:

this tag doesn’t render

set_var_conditional(context, condition=None, condition_var=None, compare=None, else_value=None, **kwds)[source]

Sets the given variables to provided values. Kind of like the ‘with’ block, only it isn’t a block tag

Parameters:
  • context – template context (automatically provided by django)
  • kwds – named parameters with their respective values
  • condition_var – pair with compare to obtain True or False whether to use original assignment or else_value
  • compare – pair with condition_var to obtain True or False whether to use original assignment or else_value
  • condition – alternative to condition_var & compare: original assignment if truthy or else_value if falsy
  • else_value – value to be assigned to the variable(s) when condition is falsy
Returns:

this tag doesn’t render

render_table_commands(context, serializer, position, field_name=None, button_position=None)[source]

Renders commands that are defined in serializers controls attribute.

Parameters:
  • context – Context
  • serializer – Serializer
  • position – Position of command (See action.py->Action for more details)
  • field_name – If position is left or right to the field, then this parameter must contain field name
  • button_position – form button position one of (form, dialog, user-provided)
Returns:

rendered command buttons. If table_header parameter is given and commands for position are defined, returns only rendered table header

table_columns_count(serializer)[source]

Returns number of columns including control columns

Parameters:serializer – Serializer
Returns:Number of all columns

Filter reference

class ExtendTemplateNode(nodelist, template_name, kwargs, only, multiline)[source]

Node for rendering extended template

render(context)[source]

Return the node rendered as a string.

dict_item(d, k)[source]

Returns the given key from a dictionary.

do_extendtemplate(parser, token)[source]

Similar to base tag include, but with possibility to use blocks This tag is used as single line (without closing tag) For multiline use extendtemplateblock

Template name can be provided in two ways:
  • If template name is static than declare it in first arg
  • If template name is in variable than declare variable name in ‘template_name_var’ kwarg

Keyword parameters will be used as context when rendering template If there is “only” in parameters only keyword parameters will be used as context for rendering. Otherwise keywords will be added to existing context

do_extendtemplateblock(parser, token)[source]

Same do_extendtemplate, only multiline… with posibillity to use blocks

field_to_serializer_and_data(context, serializer)[source]

Adjusts context such that the nested serializer field becomes THE serializer

Parameters:serializer – field to be converted into context
Returns:nothing
items(value)[source]

Simple filter to return the items of the dict. Useful when the dict may have a key ‘items’ which is resolved first in Django template dot-notation lookup. See DRF issue #4931 Also see: https://stackoverflow.com/questions/15416662/django-template-loop-over-dictionary-items-with-items-as-key

json(value, field_list: str = None)[source]

JSON serialises given variable. Use when you want to insert a variable directly into JavaScript

Parameters:
  • value – variable to serialise
  • field_list – if supplied, the “value” is assumed to be iterable of dict or object. only field_list members will be serialized
Returns:

JSON serialised string

template_from_string(template_string, using=None)[source]

Convert a string into a template object, using a given template engine or using the default backends from settings.TEMPLATES if no engine was specified.