Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Adrian Holovaty authored December 19, 2005
17  django/db/models/base.py
@@ -10,6 +10,7 @@
10 10
 from django.dispatch import dispatcher
11 11
 from django.core.exceptions import ObjectDoesNotExist
12 12
 from django.utils.functional import curry
  13
+from django.conf import settings
13 14
 import re
14 15
 import types
15 16
 import sys
@@ -28,20 +29,18 @@ def __new__(cls, name, bases, attrs):
28 29
 
29 30
         # Create the class.
30 31
         new_class = type.__new__(cls, name, bases, {'__module__': attrs.pop('__module__')})
31  
-        new_class.add_to_class('_meta', 
32  
-                                Options(attrs.pop('META', None)))
33  
-        new_class.add_to_class('DoesNotExist', 
34  
-                                types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}) )
35  
-        
  32
+        new_class.add_to_class('_meta', Options(attrs.pop('META', None)))
  33
+        new_class.add_to_class('DoesNotExist', types.ClassType('DoesNotExist', (ObjectDoesNotExist,), {}))
  34
+
36 35
         #Figure out the app_label by looking one level up.
37 36
         #FIXME: wrong for nested model modules
38 37
         app_package = sys.modules.get(new_class.__module__)
39 38
         app_label = app_package.__name__.replace('.models', '')
40 39
         app_label = app_label[app_label.rfind('.')+1:]
41  
-        
  40
+
42 41
         # Cache the app label.
43 42
         new_class._meta.app_label = app_label
44  
-        
  43
+
45 44
         # Add all attributes to the class.
46 45
         for obj_name, obj in attrs.items():
47 46
             new_class.add_to_class(obj_name, obj)
@@ -110,7 +109,7 @@ def __init__(self, *args, **kwargs):
110 109
     def add_to_class(cls, name, attribute):
111 110
         transform = attribute_transforms.get(name, None)
112 111
         if transform:
113  
-            attribute = transform(attribute) 
  112
+            attribute = transform(attribute)
114 113
         if hasattr(attribute, 'contribute_to_class'):
115 114
             attribute.contribute_to_class(cls, name)
116 115
         else:
@@ -121,7 +120,7 @@ def _prepare(cls):
121 120
         # Creates some methods once self._meta has been populated.
122 121
         opts =  cls._meta
123 122
         opts._prepare()
124  
-        
  123
+
125 124
         if opts.order_with_respect_to:
126 125
             cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True)
127 126
             cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False)
14  django/db/models/manipulators.py
... ...
@@ -1,8 +1,11 @@
1 1
 from django.core.exceptions import ObjectDoesNotExist
  2
+from django.core import formfields
2 3
 from django.core.formfields import Manipulator
3 4
 from django.db.models.fields import FileField, AutoField
  5
+from django.db.models.fields.related import ManyToOne
4 6
 from django.dispatch import dispatcher
5 7
 from django.db.models import signals
  8
+from django.utils.functional import curry
6 9
 
7 10
 def add_manipulators(sender):
8 11
     cls = sender
@@ -51,14 +54,14 @@ def _prepare(cls, model):
51 54
         cls.manager = model._default_manager
52 55
         cls.opts = model._meta
53 56
         for field_name_list in cls.opts.unique_together:
54  
-            setattr(cls, 'isUnique%s' % '_'.join(field_name_list), curry(manipulator_validator_unique_together, field_name_list, opts))
  57
+            setattr(cls, 'isUnique%s' % '_'.join(field_name_list), curry(manipulator_validator_unique_together, field_name_list, cls.opts))
55 58
         for f in cls.opts.fields:
56 59
             if f.unique_for_date:
57  
-                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'))
  60
+                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'))
58 61
             if f.unique_for_month:
59  
-                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'))
  62
+                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'))
60 63
             if f.unique_for_year:
61  
-                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'))
  64
+                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'))
62 65
     _prepare = classmethod(_prepare)
63 66
 
64 67
     def contribute_to_class(cls, other_cls, name ):
@@ -310,7 +313,6 @@ def manipulator_validator_unique_together(field_name_list, opts, self, field_dat
310 313
 
311 314
 def manipulator_validator_unique_for_date(from_field, date_field, opts, lookup_type, self, field_data, all_data):
312 315
     date_str = all_data.get(date_field.get_manipulator_field_names('')[0], None)
313  
-    mod = opts.get_model_module()
314 316
     date_val = formfields.DateField.html2python(date_str)
315 317
     if date_val is None:
316 318
         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
324 326
     if lookup_type == 'date':
325 327
         lookup_kwargs['%s__day' % date_field.name] = date_val.day
326 328
     try:
327  
-        old_obj = mod.get_object(**lookup_kwargs)
  329
+        old_obj = opts.model._default_manager.get_object(**lookup_kwargs)
328 330
     except ObjectDoesNotExist:
329 331
         return
330 332
     else:

0 notes on commit d828a40

Please sign in to comment.
Something went wrong with that request. Please try again.