hg.py
47 lines
| 1.6 KiB
| text/x-python
|
PythonLexer
Marcin Kuzminski
|
r0 | #!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||||
r93 | from mako.template import Template | |||
from mercurial.hg import repository | ||||
from mercurial.hgweb import hgweb | ||||
from mercurial.hgweb.request import wsgiapplication | ||||
from mercurial.localrepo import localrepository | ||||
from operator import itemgetter | ||||
Marcin Kuzminski
|
r41 | from pylons import tmpl_context as c, app_globals as g, session, request, config | ||
r93 | from pylons.controllers.util import abort | |||
Marcin Kuzminski
|
r22 | from pylons_app.lib import helpers as h | ||
Marcin Kuzminski
|
r76 | from pylons_app.lib.base import BaseController, render | ||
Marcin Kuzminski
|
r82 | from pylons_app.lib.utils import get_repo_slug | ||
Marcin Kuzminski
|
r58 | from pylons_app.model.hg_model import HgModel | ||
r93 | import logging | |||
import os | ||||
from beaker.cache import cache_region | ||||
Marcin Kuzminski
|
r10 | log = logging.getLogger(__name__) | ||
Marcin Kuzminski
|
r0 | |||
class HgController(BaseController): | ||||
Marcin Kuzminski
|
r21 | |||
def __before__(self): | ||||
Marcin Kuzminski
|
r41 | c.repos_prefix = config['repos_name'] | ||
Marcin Kuzminski
|
r82 | c.repo_name = get_repo_slug(request) | ||
Marcin Kuzminski
|
r55 | def index(self): | ||
r93 | ||||
Marcin Kuzminski
|
r58 | hg_model = HgModel() | ||
r93 | @cache_region('short_term', 'repo_list') | |||
def _list(): | ||||
return list(hg_model.get_repos()) | ||||
c.repos_list = _list() | ||||
Marcin Kuzminski
|
r57 | c.current_sort = request.GET.get('sort', 'name') | ||
Marcin Kuzminski
|
r55 | |||
Marcin Kuzminski
|
r57 | cs = c.current_sort | ||
c.cs_slug = cs.replace('-', '') | ||||
sortables = ['name', 'description', 'last_change', 'tip', 'contact'] | ||||
if cs and c.cs_slug in sortables: | ||||
sort_key = c.cs_slug + '_sort' | ||||
if cs.startswith('-'): | ||||
c.repos_list.sort(key=itemgetter(sort_key), reverse=True) | ||||
else: | ||||
c.repos_list.sort(key=itemgetter(sort_key), reverse=False) | ||||
Marcin Kuzminski
|
r55 | return render('/index.html') | ||