Project

General

Profile

Download (1.05 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / urls_utils.py @ fcfb4f5b

1
from django.core.urlresolvers import RegexURLPattern, RegexURLResolver
2

    
3
class DecoratedURLPattern(RegexURLPattern):
4
    def resolve(self, *args, **kwargs):
5
        result = super(DecoratedURLPattern, self).resolve(*args, **kwargs)
6
        if result:
7
            result.func = self._decorate_with(result.func)
8
        return result
9

    
10
class DecoratedRegexURLResolver(RegexURLResolver):
11
    def resolve(self, *args, **kwargs):
12
        result = super(DecoratedRegexURLResolver, self).resolve(*args, **kwargs)
13
        if result:
14
            result.func = self._decorate_with(result.func)
15
        return result
16

    
17
def decorated_includes(func, includes, *args, **kwargs):
18
    urlconf_module, app_name, namespace = includes
19

    
20
    for item in urlconf_module:
21
        if isinstance(item, RegexURLPattern):
22
            item.__class__ = DecoratedURLPattern
23
            item._decorate_with = func
24

    
25
        elif isinstance(item, RegexURLResolver):
26
            item.__class__ = DecoratedRegexURLResolver
27
            item._decorate_with = func
28

    
29
    return urlconf_module, app_name, namespace
30

    
(9-9/12)