annotate taginthemiddle/handlers.py @ 4:61dd789330f7

stub out example .ini file for taginthemiddle
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 05 May 2010 22:07:56 -0700
parents 1182315b18ac
children fc55d95be553
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):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
88 # TODO: RSS
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
89 template = 'tags.html'
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
90 methods = set(['GET'])
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
91
2
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
92 def __init__(self, app, request):
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
93 GenshiHandler.__init__(self, app, request)
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
94 path = request.path_info.split('/')
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
95 try:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
96 index = path.find(app.tags_url)
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
97 except ValueError:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
98 raise HandlerMatchException
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
99 self.tags = path[index+1:]
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
100 if not self.tags:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
101 raise HandlerMatchException
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
102
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
103 @classmethod
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
104 def match(cls, app, request):
2
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
105 # check the method
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
106 if request.method not in cls.methods:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
107 return None
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
108
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
109 try:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
110 return cls(app, request)
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
111 except HandlerMatchException:
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
112 return None
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
113
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
114 def Get(self):
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
115 if self.request.GET.get('format') == 'rss':
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
116 pass # TODO
1182315b18ac add rudimentary code for handlers
Jeff Hammel <jhammel@mozilla.com>
parents: 0
diff changeset
117 return GenshiHandler.Get(self)
0
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
118
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
119 class PostTags(Handler):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
120 methods = set(['POST'])
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
121
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
122 @classmethod
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
123 def match(cls, app, request):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
124
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
125 # check the method
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
126 if request.method not in cls.methods:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
127 return None
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
128
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
129 # check auth
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
130 if not request.remote_user:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
131 return None
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
132
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
133 # check the path
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
134 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
135 try:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
136 return cls(app, request)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
137 except HandlerMatchException:
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
138 return None
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
139
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
140 def __call__(self):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
141
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
142 # get the url
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
143 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
144
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
145 # add and remove tags
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
146 # TODO
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
147
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
148 # redirect to original resource
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
149 return exc.HTTPSeeOther(location=url)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
150
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
151 class Index(GenshiHandler):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
152 template = 'index.html'
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
153 methods=set(['GET', 'POST'])
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
154
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
155 def __init__(self, app, request):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
156 GenshiHandler.__init__(self, app, request)
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 def Get(self):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
159 self.data['name'] = self.request.remote_user or self.app.name
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
160 return GenshiHandler.Get(self)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
161
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
162 def Post(self):
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
163 self.app.name = self.request.POST.get('name', self.app.name)
1c5cbbde4299 initial commit of middleware tagging; doesnt yet work
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
164 self.redirect(self.link(self.handler_path))