lazy url reverse()

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# file lazy.py
from django.core import urlresolvers

class lazy_string(object):
    def __init__(self, function, *args, **kwargs):
        self.function=function
        self.args=args
        self.kwargs=kwargs
        
    def __str__(self):
        if not hasattr(self, 'str'):
            self.str=self.function(*self.args, **self.kwargs)
        return self.str

def reverse(*args, **kwargs):
    return lazy_string(urlresolvers.reverse, *args, **kwargs)

More like this

  1. Lazy context processor. by spookylukey 4 months ago
  2. The chunkmaker by pbx 6 years, 11 months ago
  3. View Redirect Decorators by bryanpieper 3 years, 9 months ago
  4. activation_required by offline 5 years, 9 months ago
  5. Simple Age Verification Middleware by eculver 4 years, 8 months ago

Comments

(Forgotten your password?)