oioioi.base.templatetags.simple_filters

Module Contents

Functions

is_checkbox(field)

is_checkbox_select_multiple(field)

is_radioselect(field)

lookup(d, key)

Lookup value from dictionary

safe_lookup(d, key)

Lookup value from dictionary. Returns None if key key

multival_lookup(d, key)

Returns a value list corresponding to a key from Django's MultiValueDict

indent_string(value[, num_spaces])

Adds num_spaces spaces at the

_append_attr(field, attribute, value)

add_class(field, css_class)

Adds css class to a django form field

add_form(field, form_id)

partition(thelist, n)

From: http://djangosnippets.org/snippets/6/

cyclic_lookup(thelist, index)

zip_lists(a, b)

jsonify(value)

Be careful when using it directly in js! Code like that:

json_parse(value)

This is a correct way of embedding json inside js in an HTML template.

latex_escape(x)

Escape string for generating LaTeX report.

result_color_class(raw_score)

Attributes

oioioi.base.templatetags.simple_filters.register[source]
oioioi.base.templatetags.simple_filters.is_checkbox(field)[source]
oioioi.base.templatetags.simple_filters.is_checkbox_select_multiple(field)[source]
oioioi.base.templatetags.simple_filters.is_radioselect(field)[source]
oioioi.base.templatetags.simple_filters.lookup(d, key)[source]

Lookup value from dictionary

Example:

{% load simple_filters %} {{ dict|lookup:key }}

oioioi.base.templatetags.simple_filters.safe_lookup(d, key)[source]

Lookup value from dictionary. Returns None if key key is not present in d.

Example:

{% load simple_filters %} {{ dict|safe_lookup:key }}

oioioi.base.templatetags.simple_filters.multival_lookup(d, key)[source]

Returns a value list corresponding to a key from Django’s MultiValueDict

oioioi.base.templatetags.simple_filters.indent_string(value, num_spaces=4)[source]

Adds num_spaces spaces at the beginning of every line in value.

oioioi.base.templatetags.simple_filters._append_attr(field, attribute, value)[source]
oioioi.base.templatetags.simple_filters.add_class(field, css_class)[source]

Adds css class to a django form field :param field: form field :param css_class: css class :return: field with added class

Example usage

# my_app/forms.py ```python class MyForm(Form):

my_field = forms.CharField(max_length=100)

# my_app/views.py ```python def get_form(request):

my_form = MyForm() return render(request, ‘my_form.html’, { form: my_form })

```

# my_app/templates/my_form.html `html {{ form.field|add_class:"my-class" }} `

would generate

`html <input class="my-class" id="my_field" name="my_field" /> `

oioioi.base.templatetags.simple_filters.add_form(field, form_id)[source]
oioioi.base.templatetags.simple_filters.partition(thelist, n)[source]

From: http://djangosnippets.org/snippets/6/

Break a list into n pieces. If n is not a divisor of the length of the list, then first pieces are one element longer then the last ones. That is:

>>> l = range(10)
>>> partition(l, 2)
[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9]]
>>> partition(l, 3)
[[0, 1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> partition(l, 4)
[[0, 1, 2], [3, 4, 5], [6, 7], [8, 9]]
>>> partition(l, 5)
[[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]]

You can use the filter in the following way:

{% load simple_filters %} {% for sublist in mylist|parition:”3” %}

{% for item in sublist %}

do something with {{ item }}

{% endfor %}

{% endfor %}

oioioi.base.templatetags.simple_filters.cyclic_lookup(thelist, index)[source]
oioioi.base.templatetags.simple_filters.zip_lists(a, b)[source]
oioioi.base.templatetags.simple_filters.jsonify(value)[source]

Be careful when using it directly in js! Code like that:

<script>

var x = {{ some_user_data|jsonify }};

</script>

contains an XSS vulnerability. That’s because browsers will interpret </script> tag inside js string.

oioioi.base.templatetags.simple_filters.json_parse(value)[source]

This is a correct way of embedding json inside js in an HTML template.

oioioi.base.templatetags.simple_filters.latex_escape(x)[source]

Escape string for generating LaTeX report.

Usage: {{ malicious|latex_escape }}

Remember: when generating LaTeX report, you should always check whether write18 is disabled! http://www.texdev.net/2009/10/06/what-does-write18-mean/

oioioi.base.templatetags.simple_filters.result_color_class(raw_score)[source]