Switch to unified view

a/Allura/allura/lib/patches.py b/Allura/allura/lib/patches.py
1
import webob
1
import webob
2
import tg.decorators
2
import tg.decorators
3
from decorator import decorator
3
from pylons import request
4
from pylons import request
4
5
5
from allura.lib import helpers as h
6
from allura.lib import helpers as h
6
7
7
def apply():
8
def apply():
...
...
36
            try:
37
            try:
37
                override_mapping = request._override_mapping
38
                override_mapping = request._override_mapping
38
            except AttributeError:
39
            except AttributeError:
39
                override_mapping = request._override_mapping = {}
40
                override_mapping = request._override_mapping = {}
40
            override_mapping[controller.im_func] = {content_type: template}
41
            override_mapping[controller.im_func] = {content_type: template}
42
43
    @h.monkeypatch(tg, tg.decorators)
44
    @decorator
45
    def without_trailing_slash(func, *args, **kwargs):
46
        '''Monkey-patched to use 301 redirects for SEO'''
47
        if request.method == 'GET' and request.path.endswith('/') and not(request.response_type) and len(request.params)==0:
48
            raise webob.exc.HTTPMovedPermanently(location=request.url[:-1])
49
        return func(*args, **kwargs)
50
51
    @h.monkeypatch(tg, tg.decorators)
52
    @decorator
53
    def with_trailing_slash(func, *args, **kwargs):
54
        '''Monkey-patched to use 301 redirects for SEO'''
55
        if request.method == 'GET' and not(request.path.endswith('/')) and not(request.response_type) and len(request.params)==0:
56
            raise webob.exc.HTTPMovedPermanently(location=request.url+'/')
57
        return func(*args, **kwargs)