#5925: Unable to use urlresolvers (url,reverse ) feature in redirect argument of
decorator user_passes_test
-------------------------------------+--------------------------------------
Reporter: anonymous | Owner: SmileyChris
Status: assigned | Milestone:
Component: Core framework | Version: SVN
Resolution: | Keywords:
urlresolver,reverse,decorator,url,permalink
Stage: Accepted | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
-------------------------------------+--------------------------------------
Changes (by SmileyChris):
* has_patch: 0 => 1
Comment:
If anyone needs this functionality currently, here's a stand-alone object
I created which works well enough:
{{{
#!python
from django.core.urlresolvers import reverse
from django.utils.functional import LazyObject
class ReverseLazy(LazyObject):
"""
A lazily evaluated URL reversing object.
Takes identical arguments to the ``reverse`` method in
``django.core.urlresolvers``.
"""
def __init__(self, viewname, *args, **kwargs):
self.__dict__['_reverse_args'] = (viewname,) + args
self.__dict__['_reverse_kwargs'] = kwargs
super(ReverseLazy, self).__init__()
def _setup(self):
self._wrapped = reverse(*self._reverse_args,
**self._reverse_kwargs)
def __nonzero__(self):
"""
Always assuming a boolean check passes.
This avoids one test in the ``user_passes_test`` decorator
generator
in ``django.contrib.auth``.
"""
return True
def __str__(self):
self._setup()
return str(self._wrapped)
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/5925#comment:13>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.