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

render_field_to_table(serializer, field_name, value, row_data)[source]

Renders separate field to table view.

Parameters:
  • serializer – Serializer
  • field_name – Field name
  • value – Field value
  • row_data – data for entire row
Returns:

rendered field for table view

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_field_to_table(serializer, field_name, value, row_data)[source]

Renders separate field to table view.

Parameters:
  • serializer – Serializer
  • field_name – Field name
  • value – Field value
  • row_data – data for entire row
Returns:

rendered field for table view

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

dict_item(d, k)[source]

Returns the given key from a dictionary.

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)[source]

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

Parameters:value – variable to serialise
Returns:JSON serialised string