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

Unified Diff: appengine_django/serializer/xml.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/xml.py
===================================================================
--- appengine_django/serializer/xml.py (revision 19)
+++ appengine_django/serializer/xml.py (working copy)
@@ -20,6 +20,8 @@
ToXml method for each entity.
"""
+import datetime
+import time
import re
from django.conf import settings
@@ -30,7 +32,9 @@
from google.appengine.api import datastore_types
from google.appengine.ext import db
-from python import FakeParent
+from appengine_django.serializer.python import FakeParent
+from appengine_django.serializer.python import DATE_FORMAT
+from appengine_django.serializer.python import TIME_FORMAT
getInnerText = xml_serializer.getInnerText
@@ -133,9 +137,20 @@
raise base.DeserializationError(u"Cannot load Reference with "
"unnamed key: '%s'" % field_value)
data[field.name] = key_obj
- else:
- data[field.name] = field.validate(field_value)
+ continue
+ if isinstance(field, db.DateTimeProperty):
GvR 2008/05/13 16:40:54 Why the duplicated code? I guess this is another
+ try:
+ t = time.strptime(field_value.split(".")[0],
+ "%s %s"% (DATE_FORMAT, TIME_FORMAT))
+ d = datetime.datetime(*(t)[0:6])
+ field_value = d
+ except (ValueError, TypeError), e:
+ # 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

Powered by Google App Engine
This is Rietveld r305