Merge lp:~replaceafill/schooltool/flourish_960367 into lp:schooltool/flourish

Proposed by Douglas Cerna
Status: Merged
Merged at revision: 3373
Proposed branch: lp:~replaceafill/schooltool/flourish_960367
Merge into: lp:schooltool/flourish
Diff against target: 37 lines (+15/-3)
1 file modified
src/schooltool/skin/widgets.py (+15/-3)
To merge this branch: bzr merge lp:~replaceafill/schooltool/flourish_960367
Reviewer Review Type Date Requested Status
Justas Sadzevičius (community) Approve
Review via email: mp+98684@code.launchpad.net

Description of the change

Sorry, to bother you, but could you check this change? I'm not sure if the str(value) part in the toWidgetValue can bite us later. Is there a better way to let the user to fix the wrong date he already has in the system?

Thanks!

To post a comment you must log in.
Revision history for this message
Justas Sadzevičius (justas.sadzevicius) wrote :

Looks OK from the first glance.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/schooltool/skin/widgets.py'
2--- src/schooltool/skin/widgets.py 2011-12-19 17:46:21 +0000
3+++ src/schooltool/skin/widgets.py 2012-03-21 17:05:29 +0000
4@@ -79,18 +79,30 @@
5 """See interfaces.IDataConverter"""
6 if value is self.field.missing_value:
7 return u''
8- return value.strftime("%Y-%m-%d")
9+ try:
10+ return value.strftime("%Y-%m-%d")
11+ except (ValueError,):
12+ # XXX: may be evil, but this allows users to fix incorrect
13+ # dates entered before we added the >= 1900 check
14+ return str(value)
15
16 def toFieldValue(self, value):
17 """See interfaces.IDataConverter"""
18 if value == u'':
19 return self.field.missing_value
20 try:
21- return parse_date(value)
22- except ValueError, err:
23+ value = parse_date(value)
24+ except (ValueError,):
25 raise FormatterValidationError(
26 _("The datetime string did not match the pattern yyyy-mm-dd"),
27 value)
28+ try:
29+ value.strftime("%Y-%m-%d")
30+ except (ValueError,):
31+ raise FormatterValidationError(
32+ _('Year has to be equal or greater than 1900'),
33+ value)
34+ return value
35
36
37 class IFCKConfig(Interface):

Subscribers

People subscribed via source and target branches