Ticket #11891: get_absolute_url_attributes.diff
File get_absolute_url_attributes.diff, 2.7 KB (added by , 15 years ago) |
---|
-
django/db/models/base.py
18 18 from django.db import connection, transaction, DatabaseError 19 19 from django.db.models import signals 20 20 from django.db.models.loading import register_models, get_model 21 from django.utils.functional import curry 21 from django.utils.functional import curry, update_wrapper 22 22 from django.utils.encoding import smart_str, force_unicode, smart_unicode 23 23 from django.conf import settings 24 24 … … 232 232 cls.__doc__ = "%s(%s)" % (cls.__name__, ", ".join([f.attname for f in opts.fields])) 233 233 234 234 if hasattr(cls, 'get_absolute_url'): 235 cls.get_absolute_url = curry(get_absolute_url, opts, cls.get_absolute_url) 235 cls.get_absolute_url = update_wrapper(curry(get_absolute_url, opts, cls.get_absolute_url), 236 cls.get_absolute_url) 236 237 237 238 signals.class_prepared.send(sender=cls) 238 239 -
tests/regressiontests/views/models.py
39 39 40 40 def get_absolute_url(self): 41 41 return '/urlarticles/%s/' % self.slug 42 get_absolute_url.purge = True 42 43 43 44 class DateArticle(BaseArticle): 44 45 """ -
tests/regressiontests/views/tests/defaults.py
4 4 from django.test import TestCase 5 5 from django.contrib.contenttypes.models import ContentType 6 6 7 from regressiontests.views.models import Author, Article 7 from regressiontests.views.models import Author, Article, UrlArticle 8 8 9 9 class DefaultsTests(TestCase): 10 10 """Test django views in django/views/defaults.py""" … … 37 37 "The server_error view raises a 500 status" 38 38 response = self.client.get('/views/server_error/') 39 39 self.assertEquals(response.status_code, 500) 40 41 def test_get_absolute_url_attributes(self): 42 "A model can set attributes on the get_absolute_url method" 43 self.assertTrue(getattr(UrlArticle.get_absolute_url, 'purge', False), 44 'The attributes of the original get_absolute_url must be added.') 45 article = UrlArticle.objects.get(pk=1) 46 self.assertTrue(getattr(article.get_absolute_url, 'purge', False), 47 'The attributes of the original get_absolute_url must be added.')