Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2)

Unified Diff: appengine_django/serializer/python.py

Issue 950: Google App Engine Django - Deserialize db.DateTimeProperty SVN Base: http://google-app-engine-django.googlecode.com/svn/trunk/
Patch Set: Created 3 months, 4 weeks ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side by-side-diff with in-line comments
Download patch
Index: appengine_django/serializer/python.py
===================================================================
--- appengine_django/serializer/python.py (revision 19)
+++ appengine_django/serializer/python.py (working copy)
@@ -22,6 +22,8 @@
entity and also recreate the keys for any references appropriately.
"""
+import datetime
+import time
from django.conf import settings
from django.core.serializers import base
@@ -34,7 +36,6 @@
try:
from django.utils.encoding import smart_unicode
except ImportError:
- import datetime
import types
from django.utils.functional import Promise
@@ -75,7 +76,10 @@
Serializer = python.Serializer
+DATE_FORMAT = "%Y-%m-%d"
+TIME_FORMAT = "%H:%M:%S"
GvR 2008/05/13 16:40:54 I think it makes more sense to define a single con
+
class FakeParent(object):
"""Fake parent 'model' like object.
@@ -121,8 +125,18 @@
if not data[field.name].name():
raise base.DeserializationError(u"Cannot load Reference with "
"unnamed key: '%s'" % field_value)
- else:
- data[field.name] = field.validate(field_value)
+ continue
+
+ if isinstance(field, db.DateTimeProperty):
GvR 2008/05/13 16:40:54 I'm reluctant to see a growing list of if isins
+ try:
+ t = time.strptime(field_value, "%s %s"% (DATE_FORMAT, TIME_FORMAT))
+ d = datetime.datetime(*(t)[0:6])
+ field_value = d
GvR 2008/05/13 16:40:54 Any reason you aren't writing field_value = dat
+ except (ValueError, TypeError), e:
GvR 2008/05/13 16:40:54 I'm uncomfortable casting such a wide net. I'd mu
+ # Pass it on anyway, and hope the model can deal with it.
+ pass
+
+ data[field.name] = field.validate(field_value)
# Create the new model instance with all it's data, but no parent.
object = Model(**data)
# Now add the parent into the hidden attribute, bypassing the type checks
« no previous file | appengine_django/serializer/xml.py » ('j')

Powered by Google App Engine
This is Rietveld r305