annotate taginthemiddle/handlers.py @ 16:5f492a6fbdd1

add note about URL structure
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 24 May 2010 07:28:39 -0700
parents 86118cd8912e
children c85d42296c06
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1 """
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 request handlers:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 these are instantiated for every request, then called
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 """
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 from urlparse import urlparse
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 from webob import Response, exc
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 class HandlerMatchException(Exception):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10 """the handler doesn't match the request"""
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 class Handler(object):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14 methods = set(['GET']) # methods to listen to
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 handler_path = [] # path elements to match
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 @classmethod
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18 def match(cls, app, request):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20 # check the method
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 if request.method not in cls.methods:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 return None
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 # check the path
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 if request.environ['path'][:len(cls.handler_path)] != cls.handler_path:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 return None
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 try:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 return cls(app, request)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 except HandlerMatchException:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 return None
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 def __init__(self, app, request):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 self.app = app
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 self.request = request
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
36 self.application_path = urlparse(request.application_url)[2]
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38 def link(self, path=(), permanant=False):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39 if isinstance(path, basestring):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
40 path = [ path ]
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
41 path = [ i.strip('/') for i in path ]
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
42 if permanant:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
43 application_url = [ self.request.application_url ]
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
44 else:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
45 application_url = [ self.application_path ]
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
46 path = application_url + path
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
47 return '/'.join(path)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
48
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
49 def redirect(self, location):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
50 raise exc.HTTPSeeOther(location=location)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
51
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
52 class GenshiHandler(Handler):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
53
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
54 def __init__(self, app, request):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
55 Handler.__init__(self, app, request)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
56 self.data = { 'request': request,
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
57 'link': self.link }
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
58
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
59 def __call__(self):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
60 return getattr(self, self.request.method.title())()
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
61
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
62 def Get(self):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
63 # needs to have self.template set
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
64 template = self.app.loader.load(self.template)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
65 return Response(content_type='text/html',
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
66 body=template.generate(**self.data).render('html'))
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
67
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
68 class TagCloud(GenshiHandler):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
69 template = 'cloud.html'
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
70 methods = set(['GET'])
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
71
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
72 @classmethod
2
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
73 def match(cls, app, request):
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
74
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
75 # check the method
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
76 if request.method not in cls.methods:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
77 return None
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
78
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
79 # check the path
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
80 if request.path_info.endswith('/%s' % app.tags_url):
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
81 try:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
82 return cls(app, request)
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
83 except HandlerMatchException:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
84 return None
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
85
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
86
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
87 class ViewTags(GenshiHandler):
16
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
88 """
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
89 View for tags on a resource; for app.tags_url == 'tags':
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
90
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
91 /<resource>/tags/mozilla :
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
92 all paths under /<resource> tagged with 'mozilla'
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
93
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
94 /<resource>/tags/mozilla+workflow :
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
95 all paths under /<resource> tagged with 'mozilla' and 'workflow'
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
96 (or should it be /<resource>/tags/mozilla/workflow , which would be
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
97 identical to /<resource>/tags/workflow/mozilla ?)
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
98
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
99 Also handles RSS:
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
100 /<resource>/tags/mozilla?format=rss
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
101 """
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
102
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
103 template = 'tags.html'
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
104 methods = set(['GET'])
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
105
2
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
106 def __init__(self, app, request):
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
107 GenshiHandler.__init__(self, app, request)
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
108 path = request.path_info.split('/')
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
109 try:
11
fc55d95be553 it is list.index, not list.find, silly!
Jeff Hammel <jhammel@mozilla.com>
parents: 2
diff changeset
110 index = path.index(app.tags_url)
2
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
111 except ValueError:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
112 raise HandlerMatchException
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
113 self.tags = path[index+1:]
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
114 if not self.tags:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
115 raise HandlerMatchException
14
86118cd8912e display what tags we are talking about
Jeff Hammel <jhammel@mozilla.com>
parents: 12
diff changeset
116 self.data['tags'] = self.tags
2
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
117
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
118 @classmethod
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
119 def match(cls, app, request):
16
5f492a6fbdd1 add note about URL structure
Jeff Hammel <jhammel@mozilla.com>
parents: 14
diff changeset
120
2
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
121 # check the method
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
122 if request.method not in cls.methods:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
123 return None
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
124
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
125 try:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
126 return cls(app, request)
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
127 except HandlerMatchException:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
128 return None
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
129
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
130 def Get(self):
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
131 if self.request.GET.get('format') == 'rss':
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
132 pass # TODO
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
133 return GenshiHandler.Get(self)
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
134
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
135 class PostTags(Handler):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
136 methods = set(['POST'])
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
137
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
138 @classmethod
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
139 def match(cls, app, request):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
140
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
141 # check the method
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
142 if request.method not in cls.methods:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
143 return None
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
144
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
145 # check auth
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
146 if not request.remote_user:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
147 return None
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
148
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
149 # check the path
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
150 if request.path_info.endswith('/%s' % app.post_url):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
151 try:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
152 return cls(app, request)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
153 except HandlerMatchException:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
154 return None
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
155
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
156 def __call__(self):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
157
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
158 # get the url
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
159 url = self.request.path_info.rsplit('/' + self.app.post_url, 1)[0]
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
160
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
161 # add and remove tags
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
162 # TODO
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
163
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
164 # redirect to original resource
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
165 return exc.HTTPSeeOther(location=url)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
166