summaryrefslogtreecommitdiff
path: root/django/core
diff options
context:
space:
mode:
authorChristopher Long <indirecthit@gmail.com>2006-09-07 01:36:27 +0000
committerChristopher Long <indirecthit@gmail.com>2006-09-07 01:36:27 +0000
commite12c2f83e0109a8e78954c8a176aa42b28ea96dc (patch)
treee50a312784e3251ba7950fe99f400421ac141992 /django/core
parent5c13ad5ea2d65cd705c6362ef4194b45725177f8 (diff)
[per-object-permissions] Merged to trunk [3731]
git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@3732 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/core')
-rw-r--r--django/core/management.py3
-rw-r--r--django/core/serializers/base.py54
-rw-r--r--django/core/serializers/json.py2
3 files changed, 32 insertions, 27 deletions
diff --git a/django/core/management.py b/django/core/management.py
index 51c8c760d5..799ec30d2c 100644
--- a/django/core/management.py
+++ b/django/core/management.py
@@ -501,7 +501,8 @@ def syncdb(verbosity=2, interactive=True):
if model in created_models:
initial_sql = get_sql_initial_data_for_model(model)
if initial_sql:
- print "Installing initial data for %s model" % model._meta.object_name
+ if verbosity >= 2:
+ print "Installing initial data for %s model" % model._meta.object_name
try:
for sql in initial_sql:
cursor.execute(sql)
diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py
index e939c0c6e7..fb293c7c13 100644
--- a/django/core/serializers/base.py
+++ b/django/core/serializers/base.py
@@ -11,7 +11,7 @@ from django.db import models
class SerializationError(Exception):
"""Something bad happened during serialization."""
pass
-
+
class DeserializationError(Exception):
"""Something bad happened during deserialization."""
pass
@@ -20,15 +20,15 @@ class Serializer(object):
"""
Abstract serializer base class.
"""
-
+
def serialize(self, queryset, **options):
"""
Serialize a queryset.
"""
self.options = options
-
+
self.stream = options.get("stream", StringIO())
-
+
self.start_serialization()
for obj in queryset:
self.start_object(obj)
@@ -44,61 +44,65 @@ class Serializer(object):
self.end_object(obj)
self.end_serialization()
return self.getvalue()
-
+
def get_string_value(self, obj, field):
"""
Convert a field's value to a string.
"""
if isinstance(field, models.DateTimeField):
- value = getattr(obj, field.name).strftime("%Y-%m-%d %H:%M:%S")
+ value = getattr(obj, field.name)
+ if value is None:
+ value = ''
+ else:
+ value = value.strftime("%Y-%m-%d %H:%M:%S")
elif isinstance(field, models.FileField):
value = getattr(obj, "get_%s_url" % field.name, lambda: None)()
else:
value = field.flatten_data(follow=None, obj=obj).get(field.name, "")
return str(value)
-
+
def start_serialization(self):
"""
Called when serializing of the queryset starts.
"""
raise NotImplementedError
-
+
def end_serialization(self):
"""
Called when serializing of the queryset ends.
"""
pass
-
+
def start_object(self, obj):
"""
Called when serializing of an object starts.
"""
raise NotImplementedError
-
+
def end_object(self, obj):
"""
Called when serializing of an object ends.
"""
pass
-
+
def handle_field(self, obj, field):
"""
Called to handle each individual (non-relational) field on an object.
"""
raise NotImplementedError
-
+
def handle_fk_field(self, obj, field):
"""
Called to handle a ForeignKey field.
"""
raise NotImplementedError
-
+
def handle_m2m_field(self, obj, field):
"""
Called to handle a ManyToManyField.
"""
raise NotImplementedError
-
+
def getvalue(self):
"""
Return the fully serialized queryset.
@@ -109,7 +113,7 @@ class Deserializer(object):
"""
Abstract base deserializer class.
"""
-
+
def __init__(self, stream_or_string, **options):
"""
Init this serializer given a stream or a string
@@ -123,39 +127,39 @@ class Deserializer(object):
# deserialization starts (otherwise subclass calls to get_model()
# and friends might fail...)
models.get_apps()
-
+
def __iter__(self):
return self
-
+
def next(self):
"""Iteration iterface -- return the next item in the stream"""
raise NotImplementedError
-
+
class DeserializedObject(object):
"""
A deserialzed model.
-
+
Basically a container for holding the pre-saved deserialized data along
with the many-to-many data saved with the object.
-
+
Call ``save()`` to save the object (with the many-to-many data) to the
database; call ``save(save_m2m=False)`` to save just the object fields
(and not touch the many-to-many stuff.)
"""
-
+
def __init__(self, obj, m2m_data=None):
self.object = obj
self.m2m_data = m2m_data
-
+
def __repr__(self):
return "<DeserializedObject: %s>" % str(self.object)
-
+
def save(self, save_m2m=True):
self.object.save()
if self.m2m_data and save_m2m:
for accessor_name, object_list in self.m2m_data.items():
setattr(self.object, accessor_name, object_list)
-
- # prevent a second (possibly accidental) call to save() from saving
+
+ # prevent a second (possibly accidental) call to save() from saving
# the m2m data twice.
self.m2m_data = None
diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index a8b4259099..72234a624b 100644
--- a/django/core/serializers/json.py
+++ b/django/core/serializers/json.py
@@ -48,4 +48,4 @@ class DateTimeAwareJSONEncoder(simplejson.JSONEncoder):
elif isinstance(o, datetime.time):
return o.strftime(self.TIME_FORMAT)
else:
- return super(self, DateTimeAwareJSONEncoder).default(o) \ No newline at end of file
+ return super(DateTimeAwareJSONEncoder, self).default(o)