def templater(self, req): def header(**map): yield tmpl('header', encoding=encoding.encoding, **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): if self.motd is not None: yield self.motd else: yield config('web', 'motd', '') def config(section, name, default=None, untrusted=True): return self.ui.config(section, name, default, untrusted) self.updatereqenv(req.env) url = req.env.get('SCRIPT_NAME', '') if not url.endswith('/'): url += '/' vars = {} styles = ( req.form.get('style', [None])[0], config('web', 'style'), 'paper' ) style, mapfile = templater.stylemap(styles, self.templatepath) if style == styles[0]: vars['style'] = style start = url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) logourl = config('web', 'logourl', 'http://mercurial.selenic.com/') logoimg = config('web', 'logoimg', 'hglogo.png') staticurl = config('web', 'staticurl') or url + 'static/' if not staticurl.endswith('/'): staticurl += '/' tmpl = templater.templater(mapfile, defaults={"header": header, "footer": footer, "motd": motd, "url": url, "logourl": logourl, "logoimg": logoimg, "staticurl": staticurl, "sessionvars": sessionvars}) return tmpl
def templater(self, req): def header(**map): header = tmpl('header', encoding=util._encoding, **map) if 'mimetype' not in tmpl: # old template with inline HTTP headers header_file = cStringIO.StringIO(templater.stringify(header)) msg = mimetools.Message(header_file, 0) header = header_file.read() yield header def footer(**map): yield tmpl("footer", **map) def motd(**map): if self.motd is not None: yield self.motd else: yield config('web', 'motd', '') def config(section, name, default=None, untrusted=True): return self.parentui.config(section, name, default, untrusted) if self._baseurl is not None: req.env['SCRIPT_NAME'] = self._baseurl url = req.env.get('SCRIPT_NAME', '') if not url.endswith('/'): url += '/' staticurl = config('web', 'staticurl') or url + 'static/' if not staticurl.endswith('/'): staticurl += '/' style = self.style if style is None: style = config('web', 'style', '') if 'style' in req.form: style = req.form['style'][0] if self.stripecount is None: self.stripecount = int(config('web', 'stripes', 1)) mapfile = style_map(templater.templatepath(), style) tmpl = templater.templater(mapfile, templatefilters.filters, defaults={ "header": header, "footer": footer, "motd": motd, "url": url, "staticurl": staticurl }) return tmpl
def templater(self, req): def header(**map): header = tmpl('header', encoding=util._encoding, **map) if 'mimetype' not in tmpl: # old template with inline HTTP headers header_file = cStringIO.StringIO(templater.stringify(header)) msg = mimetools.Message(header_file, 0) header = header_file.read() yield header def footer(**map): yield tmpl("footer", **map) def motd(**map): if self.motd is not None: yield self.motd else: yield config('web', 'motd', '') def config(section, name, default=None, untrusted=True): return self.parentui.config(section, name, default, untrusted) if self._baseurl is not None: req.env['SCRIPT_NAME'] = self._baseurl url = req.env.get('SCRIPT_NAME', '') if not url.endswith('/'): url += '/' staticurl = config('web', 'staticurl') or url + 'static/' if not staticurl.endswith('/'): staticurl += '/' style = self.style if style is None: style = config('web', 'style', '') if 'style' in req.form: style = req.form['style'][0] if self.stripecount is None: self.stripecount = int(config('web', 'stripes', 1)) mapfile = style_map(templater.templatepath(), style) tmpl = templater.templater(mapfile, templatefilters.filters, defaults={"header": header, "footer": footer, "motd": motd, "url": url, "staticurl": staticurl}) return tmpl
def templater(self, req): def header(**map): yield tmpl('header', encoding=encoding.encoding, **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): if self.motd is not None: yield self.motd else: yield config('web', 'motd', '') def config(section, name, default=None, untrusted=True): return self.ui.config(section, name, default, untrusted) if self._baseurl is not None: req.env['SCRIPT_NAME'] = self._baseurl url = req.env.get('SCRIPT_NAME', '') if not url.endswith('/'): url += '/' vars = {} style = self.style if 'style' in req.form: vars['style'] = style = req.form['style'][0] start = url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) staticurl = config('web', 'staticurl') or url + 'static/' if not staticurl.endswith('/'): staticurl += '/' style = 'style' in req.form and req.form['style'][0] or self.style mapfile = templater.stylemap(style) tmpl = templater.templater(mapfile, defaults={ "header": header, "footer": footer, "motd": motd, "url": url, "staticurl": staticurl, "sessionvars": sessionvars }) return tmpl
def templater(self, req): def header(**map): yield tmpl('header', encoding=encoding.encoding, **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): if self.motd is not None: yield self.motd else: yield config('web', 'motd', '') def config(section, name, default=None, untrusted=True): return self.ui.config(section, name, default, untrusted) if self._baseurl is not None: req.env['SCRIPT_NAME'] = self._baseurl url = req.env.get('SCRIPT_NAME', '') if not url.endswith('/'): url += '/' vars = {} style = self.style if 'style' in req.form: vars['style'] = style = req.form['style'][0] start = url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) staticurl = config('web', 'staticurl') or url + 'static/' if not staticurl.endswith('/'): staticurl += '/' style = 'style' in req.form and req.form['style'][0] or self.style mapfile = templater.stylemap(style) tmpl = templater.templater(mapfile, defaults={"header": header, "footer": footer, "motd": motd, "url": url, "staticurl": staticurl, "sessionvars": sessionvars}) return tmpl
def templater(self): def header(**map): yield tmpl('header', encoding=util._encoding, **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): if self.motd is not None: yield self.motd else: yield config('web', 'motd', '') def config(section, name, default=None, untrusted=True): return self.parentui.config(section, name, default, untrusted) url = self._baseurl if not url.endswith('/'): url += '/' staticurl = url + 'static/' style = self.style if style is None: style = config('web', 'style', '') style = self.request.get("style", style) if self.stripecount is None: self.stripecount = int(config('web', 'stripes', 1)) mapfile = style_map(templater.templatepath(), style) tmpl = templater.templater(mapfile, templatefilters.filters, defaults={"header": header, "footer": footer, "motd": motd, "url": url, "staticurl": staticurl}) return tmpl
def templater(self, req): # determine scheme, port and server name # this is needed to create absolute urls proto = req.env.get('wsgi.url_scheme') if proto == 'https': proto = 'https' default_port = "443" else: proto = 'http' default_port = "80" port = req.env["SERVER_PORT"] port = port != default_port and (":" + port) or "" urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) logourl = self.config("web", "logourl", "http://mercurial.selenic.com/") logoimg = self.config("web", "logoimg", "hglogo.png") staticurl = self.config("web", "staticurl") or req.url + 'static/' if not staticurl.endswith('/'): staticurl += '/' # some functions for the templater def header(**map): yield tmpl('header', encoding=encoding.encoding, **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): yield self.config("web", "motd", "") # 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) if style == styles[0]: vars['style'] = style start = req.url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) if not self.reponame: self.reponame = (self.config("web", "name") or req.env.get('REPO_NAME') or req.url.strip('/') or self.repo.root) # create the templater tmpl = templater.templater(mapfile, defaults={"url": req.url, "logourl": logourl, "logoimg": logoimg, "staticurl": staticurl, "urlbase": urlbase, "repo": self.reponame, "header": header, "footer": footer, "motd": motd, "sessionvars": sessionvars }) return tmpl
def templater(self, req): # determine scheme, port and server name # this is needed to create absolute urls proto = req.env.get('wsgi.url_scheme') if proto == 'https': proto = 'https' default_port = "443" else: proto = 'http' default_port = "80" port = req.env["SERVER_PORT"] port = port != default_port and (":" + port) or "" urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) staticurl = self.config("web", "staticurl") or req.url + 'static/' if not staticurl.endswith('/'): staticurl += '/' # some functions for the templater def header(**map): header = tmpl('header', encoding=self.encoding, **map) if 'mimetype' not in tmpl: # old template with inline HTTP headers header_file = cStringIO.StringIO(templater.stringify(header)) msg = mimetools.Message(header_file, 0) header = header_file.read() yield header def footer(**map): yield tmpl("footer", **map) def motd(**map): yield self.config("web", "motd", "") def sessionvars(**map): fields = [] if 'style' in req.form: style = req.form['style'][0] if style != self.config('web', 'style', ''): fields.append(('style', style)) separator = req.url[-1] == '?' and ';' or '?' for name, value in fields: yield dict(name=name, value=value, separator=separator) separator = ';' # figure out which style to use style = self.config("web", "style", "") if 'style' in req.form: style = req.form['style'][0] mapfile = style_map(self.templatepath, style) if not self.reponame: self.reponame = (self.config("web", "name") or req.env.get('REPO_NAME') or req.url.strip('/') or self.repo.root) # create the templater tmpl = templater.templater(mapfile, templatefilters.filters, defaults={"url": req.url, "staticurl": staticurl, "urlbase": urlbase, "repo": self.reponame, "header": header, "footer": footer, "motd": motd, "sessionvars": sessionvars }) return tmpl
def templater(self, req): # determine scheme, port and server name # this is needed to create absolute urls proto = req.env.get('wsgi.url_scheme') if proto == 'https': proto = 'https' default_port = '443' else: proto = 'http' default_port = '80' port = req.env['SERVER_PORT'] port = port != default_port and (':' + port) or '' urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) logourl = self.config('web', 'logourl', 'https://mercurial-scm.org/') logoimg = self.config('web', 'logoimg', 'hglogo.png') staticurl = self.config('web', 'staticurl') or req.url + 'static/' if not staticurl.endswith('/'): staticurl += '/' # some functions for the templater def motd(**map): yield self.config('web', 'motd', '') # 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) if style == styles[0]: vars['style'] = style start = req.url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) if not self.reponame: self.reponame = (self.config('web', 'name') or req.env.get('REPO_NAME') or req.url.strip('/') or self.repo.root) def websubfilter(text): return websub(text, self.websubtable) # create the templater tmpl = templater.templater(mapfile, filters={'websub': websubfilter}, defaults={'url': req.url, 'logourl': logourl, 'logoimg': logoimg, 'staticurl': staticurl, 'urlbase': urlbase, 'repo': self.reponame, 'encoding': encoding.encoding, 'motd': motd, 'sessionvars': sessionvars, 'pathdef': makebreadcrumb(req.url), 'style': style, }) return tmpl
else: template.append('{date|lsdate}') align_columns.append('l') if flags: template.append('{name}{kind}') else: template.append('{name}') align_columns.append('l') template = '\0'.join(template) align_columns = ''.join(align_columns) formatter = None if style or template: formatter = templater.templater(mapfile) if template: formatter.cache['file'] = template tmplmodes = [ (True, None), (ui.verbose, 'verbose'), (ui.quiet, 'quiet'), (ui.debugflag, 'debug'), ] for mode, postfix in tmplmodes: cur = postfix and ('file_%s' % postfix) or 'file' if mode and cur in formatter: template_name = cur
def templater(self, req): # determine scheme, port and server name # this is needed to create absolute urls proto = req.env.get('wsgi.url_scheme') if proto == 'https': proto = 'https' default_port = "443" else: proto = 'http' default_port = "80" port = req.env["SERVER_PORT"] port = port != default_port and (":" + port) or "" urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) logourl = self.config("web", "logourl", "http://mercurial.selenic.com/") logoimg = self.config("web", "logoimg", "hglogo.png") staticurl = self.config("web", "staticurl") or req.url + 'static/' if not staticurl.endswith('/'): staticurl += '/' # some functions for the templater def motd(**map): yield self.config("web", "motd", "") # 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) if style == styles[0]: vars['style'] = style start = req.url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) if not self.reponame: self.reponame = (self.config("web", "name") or req.env.get('REPO_NAME') or req.url.strip('/') or self.repo.root) def websubfilter(text): return websub(text, self.websubtable) # create the templater tmpl = templater.templater(mapfile, filters={"websub": websubfilter}, defaults={"url": req.url, "logourl": logourl, "logoimg": logoimg, "staticurl": staticurl, "urlbase": urlbase, "repo": self.reponame, "encoding": encoding.encoding, "motd": motd, "sessionvars": sessionvars, "pathdef": makebreadcrumb(req.url), "style": style, }) return tmpl
def templater(self, form): # determine scheme, port and server name # this is needed to create absolute urls req = self.request url = urlparse(req.url) urlbase = "http://www.example.com/" if len(url) > 1: urlbase = "%s://%s/" % (url[0], url[1]) staticurl = self.config("web", "staticurl") or urlbase + "static/" if not staticurl.endswith("/"): staticurl += "/" urlbase += req.repo_name + "/" # some functions for the templater def header(**map): yield tmpl("header", encoding="utf-8", **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): yield self.config("web", "motd", "") def sessionvars(**map): fields = [] if "style" in form: style = form.get("style", [""])[0] if style != self.config("web", "style", ""): fields.append(("style", style)) separator = req.url[-1] == "?" and ";" or "?" for name, value in fields: yield dict(name=name, value=value, separator=separator) separator = ";" # figure out which style to use style = self.style if "style" in form: style = form.get("style", [""])[0] mapfile = style_map(self.templatepath, style) if not self.reponame: self.reponame = ( self.config("web", "name") or os.environ.get("REPO_NAME") or req.url.strip("/") or self.repo.root ) # create the templater tmpl = templater.templater( mapfile, templatefilters.filters, defaults={ "url": urlbase, "staticurl": staticurl, "urlbase": urlbase, "repo": self.reponame, "header": header, "footer": footer, "motd": motd, "sessionvars": sessionvars, }, ) return tmpl
def templater(self, req): # determine scheme, port and server name # this is needed to create absolute urls proto = req.env.get('wsgi.url_scheme') if proto == 'https': proto = 'https' default_port = "443" else: proto = 'http' default_port = "80" port = req.env["SERVER_PORT"] port = port != default_port and (":" + port) or "" urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) staticurl = self.config("web", "staticurl") or req.url + 'static/' if not staticurl.endswith('/'): staticurl += '/' # some functions for the templater def header(**map): yield tmpl('header', encoding=self.encoding, **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): yield self.config("web", "motd", "") # figure out which style to use vars = {} style = self.config("web", "style", "paper") if 'style' in req.form: style = req.form['style'][0] vars['style'] = style start = req.url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) mapfile = style_map(self.templatepath, style) if not self.reponame: self.reponame = (self.config("web", "name") or req.env.get('REPO_NAME') or req.url.strip('/') or self.repo.root) # create the templater tmpl = templater.templater(mapfile, templatefilters.filters, defaults={"url": req.url, "staticurl": staticurl, "urlbase": urlbase, "repo": self.reponame, "header": header, "footer": footer, "motd": motd, "sessionvars": sessionvars }) return tmpl
def templater(self, req): # determine scheme, port and server name # this is needed to create absolute urls proto = req.env.get('wsgi.url_scheme') if proto == 'https': proto = 'https' default_port = '443' else: proto = 'http' default_port = '80' port = req.env['SERVER_PORT'] port = port != default_port and (':' + port) or '' urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) logourl = self.config('web', 'logourl', 'https://mercurial-scm.org/') logoimg = self.config('web', 'logoimg', 'hglogo.png') staticurl = self.config('web', 'staticurl') or req.url + 'static/' if not staticurl.endswith('/'): staticurl += '/' # some functions for the templater def motd(**map): yield self.config('web', 'motd', '') # 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) if style == styles[0]: vars['style'] = style start = req.url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) if not self.reponame: self.reponame = (self.config('web', 'name') or req.env.get('REPO_NAME') or req.url.strip('/') or self.repo.root) def websubfilter(text): return websub(text, self.websubtable) # create the templater tmpl = templater.templater(mapfile, filters={'websub': websubfilter}, defaults={ 'url': req.url, 'logourl': logourl, 'logoimg': logoimg, 'staticurl': staticurl, 'urlbase': urlbase, 'repo': self.reponame, 'encoding': encoding.encoding, 'motd': motd, 'sessionvars': sessionvars, 'pathdef': makebreadcrumb(req.url), 'style': style, }) return tmpl
def templater(self, req): # determine scheme, port and server name # this is needed to create absolute urls proto = req.env.get("wsgi.url_scheme") if proto == "https": proto = "https" default_port = "443" else: proto = "http" default_port = "80" port = req.env["SERVER_PORT"] port = port != default_port and (":" + port) or "" urlbase = "%s://%s%s" % (proto, req.env["SERVER_NAME"], port) logourl = self.config("web", "logourl", "http://mercurial.selenic.com/") logoimg = self.config("web", "logoimg", "hglogo.png") staticurl = self.config("web", "staticurl") or req.url + "static/" if not staticurl.endswith("/"): staticurl += "/" # some functions for the templater def motd(**map): yield self.config("web", "motd", "") # 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) if style == styles[0]: vars["style"] = style start = req.url[-1] == "?" and "&" or "?" sessionvars = webutil.sessionvars(vars, start) if not self.reponame: self.reponame = ( self.config("web", "name") or req.env.get("REPO_NAME") or req.url.strip("/") or self.repo.root ) def websubfilter(text): return websub(text, self.websubtable) # create the templater tmpl = templater.templater( mapfile, filters={"websub": websubfilter}, defaults={ "url": req.url, "logourl": logourl, "logoimg": logoimg, "staticurl": staticurl, "urlbase": urlbase, "repo": self.reponame, "encoding": encoding.encoding, "motd": motd, "sessionvars": sessionvars, "pathdef": makebreadcrumb(req.url), }, ) return tmpl
def templater(self, req): # determine scheme, port and server name # this is needed to create absolute urls proto = req.env.get('wsgi.url_scheme') if proto == 'https': proto = 'https' default_port = "443" else: proto = 'http' default_port = "80" port = req.env["SERVER_PORT"] port = port != default_port and (":" + port) or "" urlbase = '%s://%s%s' % (proto, req.env['SERVER_NAME'], port) staticurl = self.config("web", "staticurl") or req.url + 'static/' if not staticurl.endswith('/'): staticurl += '/' # some functions for the templater def header(**map): yield tmpl('header', encoding=encoding.encoding, **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): yield self.config("web", "motd", "") # 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) if style == styles[0]: vars['style'] = style start = req.url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) if not self.reponame: self.reponame = (self.config("web", "name") or req.env.get('REPO_NAME') or req.url.strip('/') or self.repo.root) # create the templater tmpl = templater.templater(mapfile, defaults={ "url": req.url, "staticurl": staticurl, "urlbase": urlbase, "repo": self.reponame, "header": header, "footer": footer, "motd": motd, "sessionvars": sessionvars }) return tmpl
def repo_list(request): # Handle repo_detail u = ui.ui() u.setconfig('ui', 'report_untrusted', 'off') u.setconfig('ui', 'interactive', 'off') #stripecount = u.config('web', 'stripes', 1) stripecount = 1 response = HttpResponse() #TODO: Is this right? url = request.path if not url.endswith('/'): url += '/' def header(**map): yield tmpl('header', encoding=encoding.encoding, **map) def footer(**map): yield tmpl("footer", **map) def motd(**map): yield "" def archivelist(ui, nodeid, url): # TODO: support archivelist if 1 == 2: yield "" sortdefault = 'name', False def entries(sortcolumn="", descending=False, subdir="", **map): rows = [] parity = common.paritygen(stripecount) for repo in Repository.objects.has_view_permission(request.user): contact = smart_str(repo.owner.get_full_name()) lastchange = (common.get_mtime(repo.location), util.makedate()[1]) row = dict(contact=contact or "unknown", contact_sort=contact.upper() or "unknown", name=smart_str(repo.name), name_sort=smart_str(repo.name), url=repo.get_absolute_url(), description=smart_str(repo.description) or "unknown", description_sort=smart_str(repo.description.upper()) or "unknown", lastchange=lastchange, lastchange_sort=lastchange[1]-lastchange[0], archives=archivelist(u, "tip", url)) if (not sortcolumn or (sortcolumn, descending) == sortdefault): # fast path for unsorted output row['parity'] = parity.next() yield row else: rows.append((row["%s_sort" % sortcolumn], row)) if rows: rows.sort() if descending: rows.reverse() for key, row in rows: row['parity'] = parity.next() yield row defaultstaticurl = request.path + 'static/' staticurl = hgwebproxy_settings.STATIC_URL or defaultstaticurl if not settings.DEBUG else defaultstaticurl if hgwebproxy_settings.TEMPLATE_PATHS is not None: hgserve.templatepath = hgwebproxy_settings.TEMPLATE_PATHS vars = {} start = url[-1] == '?' and '&' or '?' sessionvars = webutil.sessionvars(vars, start) if not templater.templatepath(hgwebproxy_settings.STYLE): raise ImproperlyConfigured(_("'%s' is not an available style. Please check the HGPROXY_STYLE property in your settings.py" % hgwebproxy_settings.STYLE)) mapfile = templater.stylemap(hgwebproxy_settings.STYLE) if isinstance(mapfile, tuple): mapfile = mapfile[1] tmpl = templater.templater(mapfile, defaults={"header": header, "footer": footer, "motd": motd, "url": url, "staticurl": staticurl, "sessionvars": sessionvars}) #Support for descending, sortcolumn etc. sortable = ["name", "description", "contact", "lastchange"] sortcolumn, descending = sortdefault if 'sort' in request.GET: sortcolumn = request.GET['sort'] descending = sortcolumn.startswith('-') if descending: sortcolumn = sortcolumn[1:] if sortcolumn not in sortable: sortcolumn = "" sort = [("sort_%s" % column, "%s%s" % ((not descending and column == sortcolumn) and "-" or "", column)) for column in sortable] chunks = tmpl("index", entries=entries, subdir="", sortcolumn=sortcolumn, descending=descending, **dict(sort)) for chunk in chunks: response.write(chunk) return response