D970: hgweb: extract function for loading style from request context
durin42 (Augie Fackler)
phabricator at mercurial-scm.org
Thu Oct 5 21:32:24 UTC 2017
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
Also make it work on Python 3.
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D970
AFFECTED FILES
mercurial/hgweb/hgweb_mod.py
mercurial/hgweb/hgwebdir_mod.py
CHANGE DETAILS
diff --git a/mercurial/hgweb/hgwebdir_mod.py b/mercurial/hgweb/hgwebdir_mod.py
--- a/mercurial/hgweb/hgwebdir_mod.py
+++ b/mercurial/hgweb/hgwebdir_mod.py
@@ -503,12 +503,8 @@
url += '/'
vars = {}
- styles = (
- req.form.get('style', [None])[0],
- config('web', 'style'),
- 'paper'
- )
- style, mapfile = templater.stylemap(styles, self.templatepath)
+ styles, (style, mapfile) = hgweb_mod.getstyle(req, config,
+ self.templatepath)
if style == styles[0]:
vars['style'] = style
diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -30,6 +30,7 @@
hg,
hook,
profiling,
+ pycompat,
repoview,
templatefilters,
templater,
@@ -60,6 +61,17 @@
('bz2', ('application/x-bzip2', 'tbz2', '.tar.bz2', None)),
))
+def getstyle(req, configfn, templatepath):
+ fromreq = req.form.get('style', [None])[0]
+ if fromreq is not None:
+ fromreq = pycompat.sysbytes(fromreq)
+ styles = (
+ fromreq,
+ configfn('web', 'style'),
+ 'paper',
+ )
+ return styles, templater.stylemap(styles, templatepath)
+
def makebreadcrumb(url, prefix=''):
'''Return a 'URL breadcrumb' list
@@ -170,12 +182,8 @@
# figure out which style to use
vars = {}
- styles = (
- req.form.get('style', [None])[0],
- self.config('web', 'style'),
- 'paper',
- )
- style, mapfile = templater.stylemap(styles, self.templatepath)
+ styles, (style, mapfile) = getstyle(req, self.config,
+ self.templatepath)
if style == styles[0]:
vars['style'] = style
To: durin42, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list