| | 82 | def add_to_class(cls, name, value): |
| | 83 | if name == 'Admin': |
| | 84 | assert type(value) == types.ClassType, "%r attribute of %s model must be a class, not a %s object" % (name, cls.__name__, type(value)) |
| | 85 | value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_')])) |
| | 86 | if hasattr(value, 'contribute_to_class'): |
| | 87 | value.contribute_to_class(cls, name) |
| | 88 | else: |
| | 89 | setattr(cls, name, value) |
| | 90 | |
| | 91 | def _prepare(cls): |
| | 92 | # Creates some methods once self._meta has been populated. |
| | 93 | opts = cls._meta |
| | 94 | opts._prepare(cls) |
| | 95 | |
| | 96 | if opts.order_with_respect_to: |
| | 97 | cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True) |
| | 98 | cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False) |
| | 99 | setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls)) |
| | 100 | setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls)) |
| | 101 | |
| | 102 | # Give the class a docstring -- its definition. |
| | 103 | if cls.__doc__ is None: |
| | 104 | cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields])) |
| | 105 | |
| | 106 | if hasattr(cls, 'get_absolute_url'): |
| | 107 | cls.get_absolute_url = curry(get_absolute_url, opts, cls.get_absolute_url) |
| | 108 | |
| | 109 | dispatcher.send(signal=signals.class_prepared, sender=cls) |
| | 110 | |
| 179 | | def add_to_class(cls, name, value): |
| 180 | | if name == 'Admin': |
| 181 | | assert type(value) == types.ClassType, "%r attribute of %s model must be a class, not a %s object" % (name, cls.__name__, type(value)) |
| 182 | | value = AdminOptions(**dict([(k, v) for k, v in value.__dict__.items() if not k.startswith('_')])) |
| 183 | | if hasattr(value, 'contribute_to_class'): |
| 184 | | value.contribute_to_class(cls, name) |
| 185 | | else: |
| 186 | | setattr(cls, name, value) |
| 187 | | add_to_class = classmethod(add_to_class) |
| 188 | | |
| 189 | | def _prepare(cls): |
| 190 | | # Creates some methods once self._meta has been populated. |
| 191 | | opts = cls._meta |
| 192 | | opts._prepare(cls) |
| 193 | | |
| 194 | | if opts.order_with_respect_to: |
| 195 | | cls.get_next_in_order = curry(cls._get_next_or_previous_in_order, is_next=True) |
| 196 | | cls.get_previous_in_order = curry(cls._get_next_or_previous_in_order, is_next=False) |
| 197 | | setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' % cls.__name__.lower(), curry(method_get_order, cls)) |
| 198 | | setattr(opts.order_with_respect_to.rel.to, 'set_%s_order' % cls.__name__.lower(), curry(method_set_order, cls)) |
| 199 | | |
| 200 | | # Give the class a docstring -- its definition. |
| 201 | | if cls.__doc__ is None: |
| 202 | | cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields])) |
| 203 | | |
| 204 | | if hasattr(cls, 'get_absolute_url'): |
| 205 | | cls.get_absolute_url = curry(get_absolute_url, opts, cls.get_absolute_url) |
| 206 | | |
| 207 | | dispatcher.send(signal=signals.class_prepared, sender=cls) |
| 208 | | |
| 209 | | _prepare = classmethod(_prepare) |
| 210 | | |