~julian-edwards/maas/mipf-celery-job

« back to all changes in this revision

Viewing changes to src/maasserver/middleware.py

  • Committer: Tarmac
  • Author(s): Raphael Badin
  • Date: 2012-03-02 11:00:48 UTC
  • mfrom: (197.2.8 settings-cleanup)
  • Revision ID: ed@carob-20120302110048-nz71y6zr371bd3be
[r=jtv][bug=][author=rvb] Add packaging templates.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from maasserver.exceptions import MaaSAPIException
35
35
 
36
36
 
 
37
def get_relative_path(path):
 
38
    """If the url prefix settings.FORCE_SCRIPT_NAME is not None: strip the
 
39
    prefix from the given path.
 
40
    """
 
41
    prefix = settings.FORCE_SCRIPT_NAME
 
42
    if prefix is None:
 
43
        return path
 
44
    elif path.startswith(prefix):
 
45
        return path[len(prefix):]
 
46
    else:
 
47
        assert False, "Prefix '%s' not in path '%s'" % (prefix, path)
 
48
 
 
49
 
37
50
class AccessMiddleware:
38
51
    """Protect access to views.
39
52
 
64
77
 
65
78
    def process_request(self, request):
66
79
        # Public urls.
67
 
        if self.public_urls.match(request.path):
 
80
        if self.public_urls.match(get_relative_path(request.path)):
68
81
            return None
69
82
        else:
70
83
            if request.user.is_anonymous():
71
84
                return HttpResponseRedirect("%s?next=%s" % (
72
 
                    self.login_url, urlquote_plus(request.path)))
 
85
                    settings.LOGIN_URL, urlquote_plus(request.path)))
73
86
            else:
74
87
                return None
75
88
 
101
114
 
102
115
    def process_exception(self, request, exception):
103
116
        """Django middleware callback."""
104
 
        if not self.path_matcher.match(request.path):
 
117
        if not self.path_matcher.match(get_relative_path(request.path)):
105
118
            # Not a path we're handling exceptions for.
106
119
            return None
107
120