0001-fields-make-it-possible-to-prefill-with-a-date-objec.patch
tests/test_prefill.py | ||
---|---|---|
1 |
import datetime |
|
1 | 2 |
import sys |
2 | 3 |
import shutil |
3 | 4 | |
... | ... | |
86 | 87 |
field = fields.Field() |
87 | 88 |
field.prefill = {'type': 'formula', 'value': 'test'} |
88 | 89 |
assert field.get_prefill_value() == ('value', False) |
90 | ||
91 |
def test_prefill_formula_date_value(): |
|
92 |
pub.substitutions.get_context_variables = lambda: {} |
|
93 |
field = fields.Field() |
|
94 |
field.prefill = {'type': 'formula', 'value': 'utils.add_days(utils.today(), 10)'} |
|
95 |
in_ten_days = (datetime.date.today() + datetime.timedelta(days=10)).strftime('%Y-%m-%d') |
|
96 |
assert field.get_prefill_value() == (in_ten_days, False) |
|
97 | ||
98 |
field.prefill = {'type': 'formula', 'value': 'utils.add_days("2016-01-01", 10)'} |
|
99 |
assert field.get_prefill_value() == ('2016-01-11', False) |
wcs/fields.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU General Public License |
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import datetime |
|
17 | 18 |
import json |
18 | 19 |
import time |
19 | 20 |
import random |
... | ... | |
302 | 303 |
ret = eval(formula, |
303 | 304 |
get_publisher().get_global_eval_dict(), |
304 | 305 |
get_publisher().substitutions.get_context_variables()) |
306 |
if isinstance(ret, datetime.date): |
|
307 |
ret = ret.strftime(date_format()) |
|
305 | 308 |
if ret: |
306 | 309 |
return (str(ret), False) |
307 | 310 |
except: |
308 |
- |