comparison mercurial/hgweb/hgwebdir_mod.py @ 8216:25266fe996b0

hgweb: use new sessionvars code in hgwebdir, too
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Mon, 27 Apr 2009 11:37:30 +0200
parents 227707c90548
children 46293a0c7e9f
comparison
equal deleted inserted replaced
8215:227707c90548 8216:25266fe996b0
12 from mercurial import config, error, encoding 12 from mercurial import config, error, encoding
13 from common import ErrorResponse, get_mtime, staticfile, paritygen,\ 13 from common import ErrorResponse, get_mtime, staticfile, paritygen,\
14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR 14 get_contact, HTTP_OK, HTTP_NOT_FOUND, HTTP_SERVER_ERROR
15 from hgweb_mod import hgweb 15 from hgweb_mod import hgweb
16 from request import wsgirequest 16 from request import wsgirequest
17 import webutil
17 18
18 def cleannames(items): 19 def cleannames(items):
19 return [(util.pconvert(name).strip('/'), path) for name, path in items] 20 return [(util.pconvert(name).strip('/'), path) for name, path in items]
20 21
21 class hgwebdir(object): 22 class hgwebdir(object):
183 untrusted=True): 184 untrusted=True):
184 yield {"type" : i[0], "extension": i[1], 185 yield {"type" : i[0], "extension": i[1],
185 "node": nodeid, "url": url} 186 "node": nodeid, "url": url}
186 187
187 def entries(sortcolumn="", descending=False, subdir="", **map): 188 def entries(sortcolumn="", descending=False, subdir="", **map):
188 def sessionvars(**map):
189 fields = []
190 if 'style' in req.form:
191 style = req.form['style'][0]
192 if style != get('web', 'style', ''):
193 fields.append(('style', style))
194
195 separator = url[-1] == '?' and ';' or '?'
196 for name, value in fields:
197 yield dict(name=name, value=value, separator=separator)
198 separator = ';'
199
200 rows = [] 189 rows = []
201 parity = paritygen(self.stripecount) 190 parity = paritygen(self.stripecount)
202 for name, path in self.repos: 191 for name, path in self.repos:
203 if not name.startswith(subdir): 192 if not name.startswith(subdir):
204 continue 193 continue
242 url=url, 231 url=url,
243 description=description or "unknown", 232 description=description or "unknown",
244 description_sort=description.upper() or "unknown", 233 description_sort=description.upper() or "unknown",
245 lastchange=d, 234 lastchange=d,
246 lastchange_sort=d[1]-d[0], 235 lastchange_sort=d[1]-d[0],
247 sessionvars=sessionvars,
248 archives=archivelist(u, "tip", url)) 236 archives=archivelist(u, "tip", url))
249 if (not sortcolumn 237 if (not sortcolumn
250 or (sortcolumn, descending) == self.repos_sorted): 238 or (sortcolumn, descending) == self.repos_sorted):
251 # fast path for unsorted output 239 # fast path for unsorted output
252 row['parity'] = parity.next() 240 row['parity'] = parity.next()
305 293
306 url = req.env.get('SCRIPT_NAME', '') 294 url = req.env.get('SCRIPT_NAME', '')
307 if not url.endswith('/'): 295 if not url.endswith('/'):
308 url += '/' 296 url += '/'
309 297
298 vars = {}
299 style = self.style
300 if 'style' in req.form:
301 vars['style'] = style = req.form['style'][0]
302 start = url[-1] == '?' and '&' or '?'
303 sessionvars = webutil.sessionvars(vars, start)
304
310 staticurl = config('web', 'staticurl') or url + 'static/' 305 staticurl = config('web', 'staticurl') or url + 'static/'
311 if not staticurl.endswith('/'): 306 if not staticurl.endswith('/'):
312 staticurl += '/' 307 staticurl += '/'
313 308
314 style = 'style' in req.form and req.form['style'][0] or self.style 309 style = 'style' in req.form and req.form['style'][0] or self.style
316 tmpl = templater.templater(mapfile, templatefilters.filters, 311 tmpl = templater.templater(mapfile, templatefilters.filters,
317 defaults={"header": header, 312 defaults={"header": header,
318 "footer": footer, 313 "footer": footer,
319 "motd": motd, 314 "motd": motd,
320 "url": url, 315 "url": url,
321 "staticurl": staticurl}) 316 "staticurl": staticurl,
317 "sessionvars": sessionvars})
322 return tmpl 318 return tmpl