Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

magic-removal: Fixed #1084 -- Added some missing imports. Thanks, nesh

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1738 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit d828a40cb8a30819f56b0797d51aebdc4f27c53c 1 parent 79b57ab
@adrianholovaty adrianholovaty authored
Showing with 16 additions and 15 deletions.
  1. +8 −9 django/db/models/base.py
  2. +8 −6 django/db/models/manipulators.py
View
17 django/db/models/base.py
@@ -10,6 +10,7 @@
from django.dispatch import dispatcher
from django.core.exceptions import ObjectDoesNotExist
from django.utils.functional import curry
+from django.conf import settings
import re
import types
import sys
@@ -28,20 +29,18 @@ def __new__(cls, name, bases, attrs):
# Create the class.
new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')})
- new_class.add_to_class('_meta',
- Options(attrs.pop('META', None)))
- new_class.add_to_class('DoesNotExist',
- types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}) )
-
+ new_class.add_to_class('_meta', Options(attrs.pop('META', None)))
+ new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
+
#Figure out the app_label by looking one level up.
#FIXME: wrong for nested model modules
app_package = sys.modules.get(new_class.__module__)
app_label = app_package.__name__.replace('.models', '')
app_label = app_label[app_label.rfind('.')+1:]
-
+
# Cache the app label.
new_class._meta.app_label = app_label
-
+
# Add all attributes to the class.
for obj_name, obj in attrs.items():
new_class.add_to_class(obj_name, obj)
@@ -110,7 +109,7 @@ def __init__(self, *args, **kwargs):
def add_to_class(cls, name, attribute):
transform = attribute_transforms.get(name, None)
if transform:
- attribute = transform(attribute)
+ attribute = transform(attribute)
if hasattr(attribute, 'contribute_to_class'):
attribute.contribute_to_class(cls, name)
else:
@@ -121,7 +120,7 @@ def _prepare(cls):
# Creates some methods once self._meta has been populated.
opts = cls._meta
opts._prepare()
-
+
if opts.order_with_respect_to:
cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
View
14 django/db/models/manipulators.py
@@ -1,8 +1,11 @@
from django.core.exceptions import ObjectDoesNotExist
+from django.core import formfields
from django.core.formfields import Manipulator
from django.db.models.fields import FileField, AutoField
+from django.db.models.fields.related import ManyToOne
from django.dispatch import dispatcher
from django.db.models import signals
+from django.utils.functional import curry
def add_manipulators(sender):
cls = sender
@@ -51,14 +54,14 @@ def _prepare(cls, model):
cls.manager = model._default_manager
cls.opts = model._meta
for field_name_list in cls.opts.unique_together:
- setattr(cls, 'isUnique%s' % '_'.join(field_name_list), curry(manipulator_validator_unique_together, field_name_list, opts))
+ setattr(cls, 'isUnique%s' % '_'.join(field_name_list), curry(manipulator_validator_unique_together, field_name_list, cls.opts))
for f in cls.opts.fields:
if f.unique_for_date:
- setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_date), curry(manipulator_validator_unique_for_date, f, opts.get_field(f.unique_for_date), opts, 'date'))
+ setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_date), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_date), cls.opts, 'date'))
if f.unique_for_month:
- setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_month), curry(manipulator_validator_unique_for_date, f, opts.get_field(f.unique_for_month), opts, 'month'))
+ setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_month), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_month), cls.opts, 'month'))
if f.unique_for_year:
- setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_year), curry(manipulator_validator_unique_for_date, f, opts.get_field(f.unique_for_year), opts, 'year'))
+ setattr(cls, 'isUnique%sFor%s' % (f.name, f.unique_for_year), curry(manipulator_validator_unique_for_date, f, cls.opts.get_field(f.unique_for_year), cls.opts, 'year'))
_prepare = classmethod(_prepare)
def contribute_to_class(cls, other_cls, name ):
@@ -310,7 +313,6 @@ def manipulator_validator_unique_together(field_name_list, opts, self, field_dat
def manipulator_validator_unique_for_date(from_field, date_field, opts, lookup_type, self, field_data, all_data):
date_str = all_data.get(date_field.get_manipulator_field_names('')[0], None)
- mod = opts.get_model_module()
date_val = formfields.DateField.html2python(date_str)
if date_val is None:
return # Date was invalid. This will be caught by another validator.
@@ -324,7 +326,7 @@ def manipulator_validator_unique_for_date(from_field, date_field, opts, lookup_t
if lookup_type == 'date':
lookup_kwargs['%s__day' % date_field.name] = date_val.day
try:
- old_obj = mod.get_object(**lookup_kwargs)
+ old_obj = opts.model._default_manager.get_object(**lookup_kwargs)
except ObjectDoesNotExist:
return
else:
Please sign in to comment.
Something went wrong with that request. Please try again.