0001-fields-convert-empty-date-to-None-40235.patch
tests/test_fields.py | ||
---|---|---|
535 | 535 |
# check total rows |
536 | 536 |
field = fields.TableRowsField(id='1', label='Foobar', columns=['aa', 'ab', 'ac'], total_row=True) |
537 | 537 |
html_table = str(field.get_view_value([['A', 'B', '10'], ['D', 'E', '20']])) |
538 | 538 |
assert html_table.count('<tr>') == 4 |
539 | 539 |
assert html_table.count('<th>') == 3 |
540 | 540 |
assert html_table.count('<td>') == 9 |
541 | 541 |
assert html_table.count('<tfoot>') == 1 |
542 | 542 |
assert '<td>30.00</td>' in html_table |
543 | ||
544 | ||
545 |
def test_date(): |
|
546 |
assert fields.DateField().convert_value_from_str('2015-01-04') is not None |
|
547 |
assert fields.DateField().convert_value_from_str('') is None |
|
548 |
with pytest.raises(ValueError, match="does not match format '%Y-%m-%d'"): |
|
549 |
fields.DateField().convert_value_from_str('not a date') |
wcs/fields.py | ||
---|---|---|
1230 | 1230 |
@classmethod |
1231 | 1231 |
def convert_value_from_anything(cls, value): |
1232 | 1232 |
if value is None or value == '': |
1233 | 1233 |
return None |
1234 | 1234 |
date_value = evalutils.make_date(value).timetuple() # could raise ValueError |
1235 | 1235 |
return date_value |
1236 | 1236 | |
1237 | 1237 |
def convert_value_from_str(self, value): |
1238 |
if not value: |
|
1239 |
return None |
|
1238 | 1240 |
return time.strptime(value, date_format()) |
1239 | 1241 | |
1240 | 1242 |
def convert_value_to_str(self, value): |
1241 | 1243 |
if value is None: |
1242 | 1244 |
return '' |
1243 | 1245 |
try: |
1244 | 1246 |
return strftime(date_format(), value) |
1245 | 1247 |
except TypeError: |
1246 |
- |