0001-misc-expose-date-and-days-as-global-functions-17658.patch
tests/test_workflows.py | ||
---|---|---|
149 | 149 |
assert item.compute('[form_var_foo] [bar]', context={'bar': 'world'}) == 'hello world' |
150 | 150 |
assert item.compute('=form_var_foo + " " + bar', context={'bar': 'world'}) == 'hello world' |
151 | 151 | |
152 |
def test_variable_compute_dates(pub): |
|
153 |
FormDef.wipe() |
|
154 |
formdef = FormDef() |
|
155 |
formdef.name = 'foobar' |
|
156 |
formdef.fields = [StringField(id='1', label='Test', type='string', varname='foo'),] |
|
157 |
formdef.store() |
|
158 | ||
159 |
formdata = formdef.data_class()() |
|
160 |
formdata.data = {'1': '2017-07-17'} |
|
161 |
formdata.store() |
|
162 |
pub.substitutions.feed(formdata) |
|
163 | ||
164 |
item = JumpWorkflowStatusItem() |
|
165 | ||
166 |
assert item.compute('=date(form_var_foo)') == datetime.date(2017, 7, 17) |
|
167 |
assert item.compute('=date(form_var_foo) + days(1)') == datetime.date(2017, 7, 18) |
|
168 |
assert item.compute('=date(2017, 7, 18)') == datetime.date(2017, 7, 18) |
|
169 | ||
152 | 170 |
def test_jump_nothing(pub): |
153 | 171 |
FormDef.wipe() |
154 | 172 |
formdef = FormDef() |
wcs/qommon/evalutils.py | ||
---|---|---|
55 | 55 |
return get_as_datetime(datetime_var) |
56 | 56 |
raise ValueError('invalid datetime value: %s' % datetime_var) |
57 | 57 | |
58 |
def date(var, month=None, day=None): |
|
59 |
if var and month and day: |
|
60 |
return datetime.date(int(var), int(month), int(day)) |
|
61 |
return make_date(var) |
|
62 | ||
63 |
def days(count): |
|
64 |
return datetime.timedelta(days=int(count)) |
|
65 | ||
58 | 66 |
def time_delta(t1, t2): |
59 | 67 |
return make_date(t1) - make_date(t2) |
60 | 68 |
wcs/qommon/publisher.py | ||
---|---|---|
146 | 146 |
'Decimal': Decimal, |
147 | 147 |
'random': random.SystemRandom(), |
148 | 148 |
're': re, |
149 |
'date': utils.date, |
|
150 |
'days': utils.days, |
|
149 | 151 |
'utils': utils,} |
150 | 152 | |
151 | 153 |
def format_publish_error(self, exc): |
152 |
- |