Changeset 1715
- Timestamp:
- 12/16/05 21:59:35 (3 years ago)
- Files:
-
- django/branches/magic-removal/django/contrib/admin/templatetags/admin_modify.py (modified) (1 diff)
- django/branches/magic-removal/django/db/models/base.py (modified) (11 diffs)
- django/branches/magic-removal/django/db/models/fields/__init__.py (modified) (3 diffs)
- django/branches/magic-removal/django/db/models/fields/related.py (modified) (3 diffs)
- django/branches/magic-removal/django/db/models/__init__.py (modified) (1 diff)
- django/branches/magic-removal/django/db/models/manipulators.py (modified) (3 diffs)
- django/branches/magic-removal/django/db/models/signals.py (added)
- django/branches/magic-removal/django/dispatch/dispatcher.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/magic-removal/django/contrib/admin/templatetags/admin_modify.py
r1700 r1715 202 202 def filter_interface_script_maybe(bound_field): 203 203 f = bound_field.field 204 if f.rel and isinstance(f.rel, m eta.ManyToMany) and f.rel.filter_interface:204 if f.rel and isinstance(f.rel, models.ManyToMany) and f.rel.filter_interface: 205 205 return '<script type="text/javascript">addEvent(window, "load", function(e) {' \ 206 206 ' SelectFilter.init("id_%s", "%s", %s, "%s"); });</script>\n' % ( django/branches/magic-removal/django/db/models/base.py
r1713 r1715 1 from django.db.models.manipulators import M anipulatorDescriptor, ModelAddManipulator, ModelChangeManipulator2 from django.db.models.fields import Field, DateField, FileField, ImageField,AutoField3 from django.db.models.fields.related import RelatedField, OneToOne, ManyToOne, ManyToMany, RECURSIVE_RELATIONSHIP_CONSTANT1 from django.db.models.manipulators import ModelAddManipulator, ModelChangeManipulator 2 from django.db.models.fields import AutoField 3 from django.db.models.fields.related import OneToOne, ManyToOne 4 4 from django.db.models.related import RelatedObject 5 from django.db.models.manager import Manager , ManagerDescriptor5 from django.db.models.manager import Manager 6 6 from django.db.models.query import orderlist2sql 7 7 from django.db.models.options import Options 8 8 from django.db import connection, backend 9 9 from django.db.models.signals import Signals 10 11 from django.dispatch import dispatcher 10 12 from django.core.exceptions import ObjectDoesNotExist 11 13 from django.utils.functional import curry … … 24 26 # Calculate the verbose_name by converting from InitialCaps to "lowercase with spaces". 25 27 get_verbose_name = lambda class_name: re.sub('([A-Z])', ' \\1', class_name).lower().strip() 28 26 29 27 30 … … 119 122 return 0 120 123 124 125 126 121 127 class Model(object): 122 128 __metaclass__ = ModelBase … … 129 135 add_to_class = classmethod(add_to_class) 130 136 131 AddManipulator = ManipulatorDescriptor('AddManipulator', ModelAddManipulator) 132 ChangeManipulator = ManipulatorDescriptor('ChangeManipulator', ModelChangeManipulator) 133 137 134 138 def __repr__(self): 135 139 return '<%s object>' % self.__class__.__name__ … … 142 146 143 147 def __init__(self, *args, **kwargs): 148 dispatcher.send( signal = Signals.pre_init, sender = self.__class__, args=args, kwargs=kwargs) 144 149 if kwargs: 145 150 for f in self._meta.fields: … … 172 177 for i, arg in enumerate(args): 173 178 setattr(self, self._meta.fields[i].attname, arg) 179 dispatcher.send( signal = Signals.post_init, sender = self.__class__, instance=self) 174 180 175 181 def _prepare(cls): 182 cls.add_to_class( 'AddManipulator', ModelAddManipulator) 183 cls.add_to_class( 'ChangeManipulator', ModelChangeManipulator) 184 176 185 # Creates some methods once self._meta has been populated. 177 186 … … 180 189 cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False) 181 190 182 RelatedField.do_pending_lookups(cls) 191 dispatcher.send( signal = Signals.class_prepared, sender = cls) 192 193 #RelatedField.do_pending_lookups(cls) 183 194 184 195 _prepare = classmethod(_prepare) … … 188 199 if hasattr(self, '_pre_save'): 189 200 self._pre_save() 201 dispatcher.send( signal=Signals.pre_save, sender = self.__class__, instance = self ) 190 202 191 203 non_pks = [f for f in self._meta.fields if not f.primary_key] … … 232 244 233 245 # Run any post-save hooks. 246 dispatcher.send(signal=Signals.pre_save, sender = self.__class__, instance = self ) 247 234 248 if hasattr(self, '_post_save'): 235 249 self._post_save() … … 284 298 if hasattr(instance, '_pre_delete'): 285 299 instance._pre_delete() 300 301 dispatcher.send(signal=Signals.pre_delete, sender = cls, instance = instance ) 286 302 287 303 for related in cls._meta.get_all_related_many_to_many_objects(): … … 312 328 313 329 setattr(self, cls._meta.pk.attname, None) 314 for f in cls._meta.fields: 315 if isinstance(f, FileField) and getattr(self, f.attname): 316 file_name = getattr(instance, 'get_%s_filename' % f.name)() 317 # If the file exists and no other object of this type references it, 318 # delete it from the filesystem. 319 if os.path.exists(file_name) and not cls._default_manager.get_list(**{'%s__exact' % f.name: getattr(self, f.name)}): 320 os.remove(file_name) 321 # Run any post-delete hooks. 330 331 dispatcher.send(signal=Signals.post_delete, sender = cls, instance = instance ) 332 322 333 if hasattr(instance, '_post_delete'): 323 334 instance._post_delete() django/branches/magic-removal/django/db/models/fields/__init__.py
r1713 r1715 1 from django.db.models.signals import Signals 2 from django.dispatch import dispatcher 1 3 from django.conf import settings 2 4 from django.core import formfields, validators … … 6 8 from django.utils.translation import gettext_lazy, ngettext 7 9 import datetime, os 10 8 11 9 12 # Random entropy string used by "default" param. … … 503 506 setattr(cls, 'get_%s_size' % self.name, curry(cls._get_FIELD_size, field=self)) 504 507 setattr(cls, 'save_%s_file' % self.name, curry(cls._save_FIELD_file, field=self)) 508 dispatcher.connect( 509 self.delete_file, 510 signal = Signals.post_delete, 511 sender = cls 512 ) 513 514 def delete_file(self, instance): 515 if getattr(instance, f.attname): 516 file_name = getattr(instance, 'get_%s_filename' % f.name)() 517 # If the file exists and no other object of this type references it, 518 # delete it from the filesystem. 519 if os.path.exists(file_name) and \ 520 not instance.__class__._default_manager.get_list(**{'%s__exact' % self.name: getattr(instance, self.attname)}): 521 os.remove(file_name) 505 522 506 523 def get_manipulator_field_objs(self): django/branches/magic-removal/django/db/models/fields/related.py
r1713 r1715 4 4 from django.utils.functional import curry 5 5 from django.core import formfields 6 6 from django.db.models.signals import Signals 7 8 from django.dispatch import dispatcher 7 9 8 10 # Values for Relation.edit_inline. … … 14 16 class RelatedField(object): 15 17 pending_lookups = {} 18 19 dispatcher.connect( 20 lambda sender: RelatedField.do_pending_lookups(sender) , 21 signal = Signals.class_prepared, 22 weak = False) 23 16 24 17 25 def add_lookup(cls, rel_cls, field): … … 28 36 field.do_related_class(other_cls, rel_cls) 29 37 do_pending_lookups = classmethod(do_pending_lookups) 38 39 30 40 31 41 def contribute_to_class(self, cls, name): django/branches/magic-removal/django/db/models/__init__.py
r1701 r1715 17 17 from django.core.exceptions import ObjectDoesNotExist 18 18 from django.db.models.exceptions import FieldDoesNotExist, BadKeywordArguments 19 from django.db.models.signals import Signals 19 20 20 21 # Admin stages. django/branches/magic-removal/django/db/models/manipulators.py
r1710 r1715 16 16 raise "Manipulator accessed via instance" 17 17 else: 18 class Man(self.get_base_manipulator(type), self.base): 19 pass 20 Man.classinit(type) 21 Man.__name__ = self.name 22 return Man 18 if not self.man: 19 class Man(self.get_base_manipulator(type), self.base): 20 pass 21 22 Man._prepare(type) 23 Man.__name__ = self.name 24 self.man = Man 25 return self.man 23 26 24 27 def get_base_manipulator(self, type): … … 31 34 32 35 class AutomaticManipulator(Manipulator): 33 def classinit(cls, model):36 def _prepare(cls, model): 34 37 cls.model = model 35 38 cls.manager = model._default_manager … … 44 47 if f.unique_for_year: 45 48 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')) 46 classinit = classmethod(classinit) 49 _prepare = classmethod(_prepare) 50 51 def contribute_to_class(cls, other_cls, name ): 52 setattr(other_cls, name, ManipulatorDescriptor(name, cls)) 53 contribute_to_class = classmethod(contribute_to_class) 47 54 48 55 def __init__(self, original_object= None, follow=None): django/branches/magic-removal/django/dispatch/dispatcher.py
r1714 r1715 28 28 from __future__ import generators 29 29 import types, weakref 30 from d ispatch import saferef, robustapply, errors30 from django.dispatch import saferef, robustapply, errors 31 31 32 32 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
