Easier tags with parameters as dictionary values

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
@register.tag
def get_popular(parser, token):
    """
    Get highest rated objects

    Syntax::

        {% get_popular for [pkg].[module_name] as [varname] %}

    Usage::

        {% get_popular for blogs.entry as popular %}
    """
    bits = token.contents.split()
    tag = bits.pop(0)

    length = len(bits)
    keys = bits[0:length:2]
    values = bits[1:length:2]
    args = {}
    for k in keys:
        args[k] = values.pop(0)

    return PopularNode(args["for"], args["as"])

More like this

  1. Parse custom template tag's args or kwargs by t_rybik 2 years, 8 months ago
  2. Choices datatype for model by menendez 5 years, 1 month ago
  3. Support for {% macro %} tags in templates, version 2 by mludvig 5 years, 9 months ago
  4. Django Dictionary Model by Morgul 1 year, 11 months ago
  5. keywords arguments parser for custom template tags by bruno 4 years, 4 months ago

Comments

(Forgotten your password?)