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
예제 #2
0
    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
예제 #3
0
    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
예제 #4
0
    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
예제 #5
0
    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
예제 #6
0
    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
예제 #7
0
    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
예제 #8
0
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
예제 #9
0
    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
예제 #10
0
    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