|
1 |
# -*- coding: utf-8 -*-
|
|
2 |
|
1 |
3 |
import collections
|
2 |
4 |
import datetime
|
3 |
5 |
import pytest
|
... | ... | |
5 |
7 |
import shutil
|
6 |
8 |
import time
|
7 |
9 |
|
|
10 |
from django.utils import six
|
8 |
11 |
from quixote import cleanup
|
9 |
12 |
from quixote.http_request import Upload
|
|
13 |
from wcs.qommon import force_str
|
10 |
14 |
from wcs.qommon.template import Template
|
11 |
15 |
from wcs.qommon.form import PicklableUpload
|
12 |
16 |
from wcs.qommon.http_request import HTTPRequest
|
... | ... | |
1490 |
1494 |
tmpl = Template('{{ 4.12|decimal:form_var_arg }}')
|
1491 |
1495 |
assert tmpl.render(context) == '4.120'
|
1492 |
1496 |
|
|
1497 |
def test_lazy_formdata_timesince_filter(pub):
|
|
1498 |
formdef = FormDef()
|
|
1499 |
formdef.name = 'foobar'
|
|
1500 |
formdef.url_name = 'foobar'
|
|
1501 |
formdef.fields = [
|
|
1502 |
fields.DateField(id='0', label='value', varname='value'),
|
|
1503 |
]
|
|
1504 |
formdef.store()
|
|
1505 |
formdata = formdef.data_class()()
|
|
1506 |
formdata.data = {'0': time.strptime('2015-05-12', '%Y-%m-%d')}
|
|
1507 |
formdata.store()
|
|
1508 |
pub.substitutions.feed(formdata)
|
|
1509 |
for mode in (None, 'lazy'):
|
|
1510 |
context = pub.substitutions.get_context_variables(mode=mode)
|
|
1511 |
context['refdate'] = datetime.date(2015, 5, 22)
|
|
1512 |
|
|
1513 |
tmpl = Template('{{ form_var_value|date|timesince:refdate }}')
|
|
1514 |
assert force_str(tmpl.render(context)) == '1 week, 3 days'
|
|
1515 |
|
|
1516 |
# in lazy mode it's not even necessary to add the |date filter.
|
|
1517 |
context = pub.substitutions.get_context_variables(mode='lazy')
|
|
1518 |
context['refdate'] = datetime.date(2015, 5, 22)
|
|
1519 |
tmpl = Template('{{ form_var_value|timesince:refdate }}')
|
|
1520 |
assert force_str(tmpl.render(context)) == '1 week, 3 days'
|
|
1521 |
|
|
1522 |
|
1493 |
1523 |
def test_decimal_conditions_django(pub, variable_test_data):
|
1494 |
1524 |
for condition_value in (
|
1495 |
1525 |
'form_var_foo_foo|decimal == 0',
|