mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	magic-removal: ManipulatorDescriptor simplification.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1753 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -7,6 +7,8 @@ from django.dispatch import dispatcher | |||||||
| from django.db.models import signals | from django.db.models import signals | ||||||
| from django.utils.functional import curry | from django.utils.functional import curry | ||||||
|  |  | ||||||
|  | import types | ||||||
|  |  | ||||||
| def add_manipulators(sender): | def add_manipulators(sender): | ||||||
|     cls = sender |     cls = sender | ||||||
|     cls.add_to_class('AddManipulator', ModelAddManipulator) |     cls.add_to_class('AddManipulator', ModelAddManipulator) | ||||||
| @@ -33,21 +35,13 @@ class ManipulatorDescriptor(object): | |||||||
|             if not self.man: |             if not self.man: | ||||||
|                 # Create a class which inherits from the MANIPULATOR class given in the class, |                 # Create a class which inherits from the MANIPULATOR class given in the class, | ||||||
|                 # and the appropriate automatic manipulator, |                 # and the appropriate automatic manipulator, | ||||||
|                 class Man(self.get_base_manipulator(type), self.base): |                 bases = [ self.base ] | ||||||
|                     pass |                 if hasattr(type, 'MANIPULATOR'): | ||||||
|  |                     bases = [type.MANIPULATOR] + bases | ||||||
|                 Man._prepare(type) |                 self.man = types.ClassType(self.name, tuple(bases), {}) | ||||||
|                 Man.__name__ = self.name |                 self.man._prepare(type) | ||||||
|                 self.man = Man |  | ||||||
|             return self.man |             return self.man | ||||||
|  |  | ||||||
|     def get_base_manipulator(self, type): |  | ||||||
|         if hasattr(type, 'MANIPULATOR'): |  | ||||||
|             man = type.MANIPULATOR |  | ||||||
|         else: |  | ||||||
|             man = self.empty |  | ||||||
|         return man |  | ||||||
|  |  | ||||||
| class AutomaticManipulator(Manipulator): | class AutomaticManipulator(Manipulator): | ||||||
|     def _prepare(cls, model): |     def _prepare(cls, model): | ||||||
|         cls.model = model |         cls.model = model | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user