misc: add year/month/day variables to lazy date fields (#37433)
This commit is contained in:
parent
8bc1466003
commit
071d35e768
|
@ -1,3 +1,5 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import collections
|
||||
import datetime
|
||||
import pytest
|
||||
|
@ -5,8 +7,10 @@ import sys
|
|||
import shutil
|
||||
import time
|
||||
|
||||
from django.utils import six
|
||||
from quixote import cleanup
|
||||
from quixote.http_request import Upload
|
||||
from wcs.qommon import force_str
|
||||
from wcs.qommon.template import Template
|
||||
from wcs.qommon.form import PicklableUpload
|
||||
from wcs.qommon.http_request import HTTPRequest
|
||||
|
@ -1510,6 +1514,32 @@ def test_lazy_formdata_decimal_filter(pub):
|
|||
assert tmpl.render(context) == '4.120'
|
||||
|
||||
|
||||
def test_lazy_formdata_timesince_filter(pub):
|
||||
formdef = FormDef()
|
||||
formdef.name = 'foobar'
|
||||
formdef.url_name = 'foobar'
|
||||
formdef.fields = [
|
||||
fields.DateField(id='0', label='value', varname='value'),
|
||||
]
|
||||
formdef.store()
|
||||
formdata = formdef.data_class()()
|
||||
formdata.data = {'0': time.strptime('2015-05-12', '%Y-%m-%d')}
|
||||
formdata.store()
|
||||
pub.substitutions.feed(formdata)
|
||||
for mode in (None, 'lazy'):
|
||||
context = pub.substitutions.get_context_variables(mode=mode)
|
||||
context['refdate'] = datetime.date(2015, 5, 22)
|
||||
|
||||
tmpl = Template('{{ form_var_value|date|timesince:refdate }}')
|
||||
assert force_str(tmpl.render(context)) == '1 week, 3 days'
|
||||
|
||||
# in lazy mode it's not even necessary to add the |date filter.
|
||||
context = pub.substitutions.get_context_variables(mode='lazy')
|
||||
context['refdate'] = datetime.date(2015, 5, 22)
|
||||
tmpl = Template('{{ form_var_value|timesince:refdate }}')
|
||||
assert force_str(tmpl.render(context)) == '1 week, 3 days'
|
||||
|
||||
|
||||
def test_decimal_conditions_django(pub, variable_test_data):
|
||||
for condition_value in (
|
||||
'form_var_foo_foo|decimal == 0',
|
||||
|
|
|
@ -677,6 +677,10 @@ class LazyFieldVarDate(DateOperatorsMixin, LazyFieldVar):
|
|||
def tm_yday(self):
|
||||
return self.get_raw().tm_yday
|
||||
|
||||
year = tm_year
|
||||
month = tm_mon
|
||||
day = tm_mday
|
||||
|
||||
|
||||
class LazyFieldVarMap(LazyFieldVar):
|
||||
def split(self, *args, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue