Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #15604 -- Changed django.db.models.permalink to use wraps() so …

…that it doesn't eat the docstring. Thanks for the report, sfllaw. Also added tests.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15798 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 72c5733869c38897f31e82cbae3c6a24f7292d11 1 parent 3a5b87c
@adrianholovaty adrianholovaty authored
View
2  django/db/models/__init__.py
@@ -13,6 +13,7 @@
from django.db.models.fields.related import ForeignKey, OneToOneField, ManyToManyField, ManyToOneRel, ManyToManyRel, OneToOneRel
from django.db.models.deletion import CASCADE, PROTECT, SET, SET_NULL, SET_DEFAULT, DO_NOTHING, ProtectedError
from django.db.models import signals
+from django.utils.decorators import wraps
# Admin stages.
ADD, CHANGE, BOTH = 1, 2, 3
@@ -28,6 +29,7 @@ def permalink(func):
(viewname, viewargs, viewkwargs)
"""
from django.core.urlresolvers import reverse
+ @wraps(func)
def inner(*args, **kwargs):
bits = func(*args, **kwargs)
return reverse(bits[0], None, *bits[1:3])
View
0  tests/regressiontests/model_permalink/__init__.py
No changes.
View
10 tests/regressiontests/model_permalink/models.py
@@ -0,0 +1,10 @@
+from django.db import models
+
+class Guitarist(models.Model):
+ name = models.CharField(max_length=50)
+ slug = models.CharField(max_length=50)
+
+ @models.permalink
+ def url(self):
+ "Returns the URL for this guitarist."
+ return ('guitarist_detail', [self.slug])
View
14 tests/regressiontests/model_permalink/tests.py
@@ -0,0 +1,14 @@
+from django.test import TestCase
+from regressiontests.model_permalink.models import Guitarist
+
+class PermalinkTests(TestCase):
+ urls = 'regressiontests.model_permalink.urls'
+
+ def test_permalink(self):
+ g = Guitarist(name='Adrien Moignard', slug='adrienmoignard')
+ self.assertEqual(g.url(), '/guitarists/adrienmoignard/')
+
+ def test_wrapped_docstring(self):
+ "Methods using the @permalink decorator retain their docstring."
+ g = Guitarist(name='Adrien Moignard', slug='adrienmoignard')
+ self.assertEqual(g.url.__doc__, "Returns the URL for this guitarist.")
View
5 tests/regressiontests/model_permalink/urls.py
@@ -0,0 +1,5 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',
+ url(r'^guitarists/(\w{1,50})/$', 'unimplemented_view_placeholder', name='guitarist_detail'),
+)
Please sign in to comment.
Something went wrong with that request. Please try again.