askbot.templatetags.smart_if

A smarter {% if %} tag for django templates.

While retaining current Django functionality, it also handles equality, greater than and less than operators. Some common case examples:

{% if articles|length >= 5 %}...{% endif %}
{% if "ifnotequal tag" != "beautiful" %}...{% endif %}
class askbot.templatetags.smart_if.And(var1, var2=None, negate=False)

Bases: askbot.templatetags.smart_if.BaseCalc

calculate(var1, var2)
class askbot.templatetags.smart_if.BaseCalc(var1, var2=None, negate=False)

Bases: object

calculate(var1, var2)
resolve(context)
resolve_vars(context)
class askbot.templatetags.smart_if.Equals(var1, var2=None, negate=False)

Bases: askbot.templatetags.smart_if.BaseCalc

calculate(var1, var2)
class askbot.templatetags.smart_if.Greater(var1, var2=None, negate=False)

Bases: askbot.templatetags.smart_if.BaseCalc

calculate(var1, var2)
class askbot.templatetags.smart_if.GreaterOrEqual(var1, var2=None, negate=False)

Bases: askbot.templatetags.smart_if.BaseCalc

calculate(var1, var2)
class askbot.templatetags.smart_if.IfParser(tokens)

Bases: object

at_end()
create_var(value)
error_class

alias of ValueError

get_bool_var()

Returns either a variable by itself or a non-boolean operation (such as x == 0 or x < 0).

This is needed to keep correct precedence for boolean operations (i.e. x or x == 0 should be x or (x == 0), not (x or x) == 0).

get_operator()
get_token(eof_message=None, lookahead=False)
get_var()
parse()
tokens
class askbot.templatetags.smart_if.In(var1, var2=None, negate=False)

Bases: askbot.templatetags.smart_if.BaseCalc

calculate(var1, var2)
class askbot.templatetags.smart_if.Or(var1, var2=None, negate=False)

Bases: askbot.templatetags.smart_if.BaseCalc

calculate(var1, var2)
class askbot.templatetags.smart_if.SmartIfNode(var, nodelist_true, nodelist_false=None)

Bases: django.template.Node

get_nodes_by_type(nodetype)
render(context)
class askbot.templatetags.smart_if.SmartIfTests(methodName='runTest')

Bases: unittest.TestCase

assertCalc(calc, context=None)

Test a calculation is True, also checking the inverse “negate” case.

assertCalcFalse(calc, context=None)

Test a calculation is False, also checking the inverse “negate” case.

setUp()
test_and()
test_boolean()
test_equals()
test_greater()
test_greater_or_equal()
test_in()
test_invalid()
test_or()
test_parse_bits()
class askbot.templatetags.smart_if.TemplateIfParser(parser, *args, **kwargs)

Bases: askbot.templatetags.smart_if.IfParser

create_var(value)
error_class

alias of TemplateSyntaxError

class askbot.templatetags.smart_if.TestVar(value)

Bases: object

A basic self-resolvable object similar to a Django template variable. Used to assist with tests.

resolve(context)
askbot.templatetags.smart_if.smart_if(parser, token)

A smarter {% if %} tag for django templates.

While retaining current Django functionality, it also handles equality, greater than and less than operators. Some common case examples:

{% if articles|length >= 5 %}...{% endif %}
{% if "ifnotequal tag" != "beautiful" %}...{% endif %}

Arguments and operators _must_ have a space between them, so {% if 1>2 %} is not a valid smart if tag.

All supported operators are: or, and, in, = (or ==), !=, >, >=, < and <=.

This Page