This tag can be used to calculate a python expression, and save it into a template variable which you can reuse later or directly output to template. So if the default django tag can not be suit for your need, you can use it.
How to use it
{% expr "1" as var1 %}
{% expr [0, 1, 2] as var2 %}
{% expr _('Menu') as var3 %}
{% expr var1 + "abc" as var4 %}
...
{{ var1 }}
for 0.2 version
{% expr 3 %}
{% expr "".join(["a", "b", "c"]) %}
Will directly output the result to template
Syntax
{% expr python_expression as variable_name %}
python_expression can be valid python expression, and you can even use _() to translate a string. Expr tag also can used context variables.
Can be used for create a json format response data. Just like:
{response:'ok', next:'nexturl', message:'response message', data:'returned data'}
for success.
{response:'fail', next:'nexturl', message:'response message', error:'error messages'}
for failure.
And there are some dump function:
json - dump a python variable into json format string
json_response - dump a python variable into json format string, and then use it create a HttpResponse object.
This module is not aimed to replace the newforms, but I would like manually write html code,
and just need a pure validate module, so I write this, and many things may be similar with
newforms. So if you like me would only need a pure validator module, you can use it.
And it has some different features from newforms:
1. Support validator_list parameter, so you could use it just like the old manipuator class
2. Supply easy method, such as `validate_and_save()`, so you can pass a request object, and
get a tuple result `(flag, obj_or_error)`, if the `flag` is `True`, then the next value
is an object; and if the `flag` is `False`, then the next value is error message.
3. Each field has a `validate_and_get` method, and it'll validate first and then return the
result, maybe an object or error message. Just like above.
4. SplitDateTimeField is somewhat different from the newforms. For example::
c = SplitDateTimeField('date', 'time')
print c.validate_and_get({'date':'2006/11/30', 'time':'12:13'})
So the first parameter is DateField's field_name, and the second parameter is TimeField's
field_name.
5. Add yyyy/mm/dd date format support
6. Support default value of a field. You can add a default value for a field, if this field
is not required, and the value is *empty*, Validator will return the default value.
This module is new, so many things could be changed.