Skip to content

Commit

Permalink
Overridable serialization for date proxy, don't crash on crud save er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
brendonh committed Mar 16, 2012
1 parent 443115e commit 9904460
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions warp/crud/colproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,23 @@ class DateProxy(BaseProxy):
dateFormat = "%m/%d/%Y"
timezone = pytz.UTC

def to_db(self, val):
return val

def from_db(self, val):
return val

def render_view(self, request):
val = getattr(self.obj, self.col)
if val is None: return u"[None]"
return val.strftime(self.dateFormat)
return self.from_db(val).strftime(self.dateFormat)

def render_edit(self, request):
fieldName = self.fieldName()
val = getattr(self.obj, self.col)

dateField = u'<input type="text" name="warpform-%s" id="date-field-%s" class="warpform-date" value="%s" size="10" />' % (
fieldName, fieldName, val.strftime("%m/%d/%Y") if val else "")
fieldName, fieldName, self.from_db(val).strftime("%m/%d/%Y") if val else "")

return u"%s %s" % (dateField, self.jsTemplate % fieldName)

Expand All @@ -260,9 +266,9 @@ def save(self, val, request):
# .astimezone(pytz.UTC)
.date())
except ValueError:
return u"Value '%s' didn't match format '%m/%d/%Y'" % (val, self.dateFormat)
return u"Value '%s' didn't match format '%s'" % (val, self.dateFormat)

setattr(self.obj, self.col, date)
setattr(self.obj, self.col, self.to_db(date))


class DateTimeProxy(DateProxy):
Expand Down

0 comments on commit 9904460

Please sign in to comment.