comparison mercurial/hgweb/hgweb_mod.py @ 34515:8afc25e7effc

hgweb: extract function for loading style from request context Also make it work on Python 3. Differential Revision: https://phab.mercurial-scm.org/D970
author Augie Fackler <augie@google.com>
date Thu, 05 Oct 2017 14:29:13 -0400
parents 945c9816ec1d
children bf2389b1f15e
comparison
equal deleted inserted replaced
34514:528b21b853aa 34515:8afc25e7effc
28 encoding, 28 encoding,
29 error, 29 error,
30 hg, 30 hg,
31 hook, 31 hook,
32 profiling, 32 profiling,
33 pycompat,
33 repoview, 34 repoview,
34 templatefilters, 35 templatefilters,
35 templater, 36 templater,
36 ui as uimod, 37 ui as uimod,
37 util, 38 util,
57 archivespecs = util.sortdict(( 58 archivespecs = util.sortdict((
58 ('zip', ('application/zip', 'zip', '.zip', None)), 59 ('zip', ('application/zip', 'zip', '.zip', None)),
59 ('gz', ('application/x-gzip', 'tgz', '.tar.gz', None)), 60 ('gz', ('application/x-gzip', 'tgz', '.tar.gz', None)),
60 ('bz2', ('application/x-bzip2', 'tbz2', '.tar.bz2', None)), 61 ('bz2', ('application/x-bzip2', 'tbz2', '.tar.bz2', None)),
61 )) 62 ))
63
64 def getstyle(req, configfn, templatepath):
65 fromreq = req.form.get('style', [None])[0]
66 if fromreq is not None:
67 fromreq = pycompat.sysbytes(fromreq)
68 styles = (
69 fromreq,
70 configfn('web', 'style'),
71 'paper',
72 )
73 return styles, templater.stylemap(styles, templatepath)
62 74
63 def makebreadcrumb(url, prefix=''): 75 def makebreadcrumb(url, prefix=''):
64 '''Return a 'URL breadcrumb' list 76 '''Return a 'URL breadcrumb' list
65 77
66 A 'URL breadcrumb' is a list of URL-name pairs, 78 A 'URL breadcrumb' is a list of URL-name pairs,
168 yield self.config('web', 'motd', '') 180 yield self.config('web', 'motd', '')
169 181
170 # figure out which style to use 182 # figure out which style to use
171 183
172 vars = {} 184 vars = {}
173 styles = ( 185 styles, (style, mapfile) = getstyle(req, self.config,
174 req.form.get('style', [None])[0], 186 self.templatepath)
175 self.config('web', 'style'),
176 'paper',
177 )
178 style, mapfile = templater.stylemap(styles, self.templatepath)
179 if style == styles[0]: 187 if style == styles[0]:
180 vars['style'] = style 188 vars['style'] = style
181 189
182 start = req.url[-1] == '?' and '&' or '?' 190 start = req.url[-1] == '?' and '&' or '?'
183 sessionvars = webutil.sessionvars(vars, start) 191 sessionvars = webutil.sessionvars(vars, start)