current
Last change
on this file since 035792a was
5ec3a0b,
checked in by borja <borja@…>, 5 years ago
|
Imported sources from the old python2-only repository:
- Modified the code so it is python 3.6 compatible
- Fixed deprecation warnings, pyramid 1.10.x supported now
- Fixed deprecation warnings about some libraries, like pyramid-simpleform
- Added pytest-pycodestyle and pytest-flakes for automatic checks on the
source code files when running tests.
- Added default pytest.ini setup to enforce some default parameters when
running tests.
- Cleaned up the code a bit, catched up with tests coverage.
|
-
Property mode set to
100644
|
File size:
842 bytes
|
Line | |
---|
1 | from datetime import datetime, date |
---|
2 | from webhelpers2.html import tags |
---|
3 | from pyramid_simpleform.renderers import FormRenderer |
---|
4 | |
---|
5 | |
---|
6 | class OWFormRenderer(FormRenderer): |
---|
7 | """ |
---|
8 | Subclass FormRenderer to add a custom renderer for date fields. |
---|
9 | |
---|
10 | Such renderer already exist in newer (devel) versions of pyramid_simpleform |
---|
11 | but they had not been released yet. |
---|
12 | """ |
---|
13 | |
---|
14 | def date(self, name, value=None, id=None, date_format=None, **attrs): |
---|
15 | """ |
---|
16 | Outputs text input with an optionally formatted datetime. |
---|
17 | """ |
---|
18 | value = self.value(name, value) |
---|
19 | id = id or name |
---|
20 | is_date = isinstance(value, date) |
---|
21 | is_datetime = isinstance(value, datetime) |
---|
22 | |
---|
23 | if (is_date or is_datetime) and date_format: |
---|
24 | value = value.strftime(date_format) |
---|
25 | |
---|
26 | return tags.text(name, value, id, **attrs) |
---|
Note: See
TracBrowser
for help on using the repository browser.