# HG changeset patch # User Marcin Kuzminski # Date 1276466176 -7200 # Node ID 237470e64bb85d1d7b584c31f82300a0eca82997 # Parent cd2ee462fc2c6c880034972e9b3e32dc0f40d19d switched filters into webhelpers for easy of usage. Rewrite of html to use predefined templates from branches shortlog tags, for DRY usage. Added info messages about empty branches/tags etc. diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/controllers/changelog.py --- a/pylons_app/controllers/changelog.py Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/controllers/changelog.py Sun Jun 13 23:56:16 2010 +0200 @@ -49,12 +49,13 @@ session['changelog_size'] = c.size session.save() else: - c.size = session.get('changelog_size', default) + c.size = int(session.get('changelog_size', default)) changesets = HgModel().get_repo(c.repo_name) p = int(request.params.get('page', 1)) - c.pagination = Page(changesets, page=p, item_count=len(changesets), + c.total_cs = len(changesets) + c.pagination = Page(changesets, page=p, item_count=c.total_cs, items_per_page=c.size) #self._graph(c.repo, c.size,p) diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/controllers/graph.py --- a/pylons_app/controllers/graph.py Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/controllers/graph.py Sun Jun 13 23:56:16 2010 +0200 @@ -25,9 +25,9 @@ from mercurial.graphmod import revisions as graph_rev, colored, CHANGESET from mercurial.node import short from pylons import request, tmpl_context as c +import pylons_app.lib.helpers as h from pylons_app.lib.auth import LoginRequired from pylons_app.lib.base import BaseController, render -from pylons_app.lib.filters import age as _age, person from pylons_app.model.hg_model import HgModel from simplejson import dumps from webhelpers.paginate import Page @@ -74,9 +74,9 @@ if type != CHANGESET: continue node = short(ctx.node()) - age = _age(ctx.date()) + age = h.age(ctx.date()) desc = ctx.description() - user = person(ctx.user()) + user = h.person(ctx.user()) branch = ctx.branch() branch = branch, repo.repo.branchtags().get(branch) == ctx.node() data.append((node, vtx, edges, desc, user, age, branch, ctx.tags())) diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/controllers/summary.py --- a/pylons_app/controllers/summary.py Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/controllers/summary.py Sun Jun 13 23:56:16 2010 +0200 @@ -25,7 +25,8 @@ from pylons import tmpl_context as c, request from pylons_app.lib.auth import LoginRequired from pylons_app.lib.base import BaseController, render -from pylons_app.model.hg_model import HgModel, _full_changelog_cached +from pylons_app.model.hg_model import HgModel +from webhelpers.paginate import Page import logging log = logging.getLogger(__name__) @@ -39,7 +40,7 @@ def index(self): hg_model = HgModel() c.repo_info = hg_model.get_repo(c.repo_name) - c.repo_changesets = _full_changelog_cached(c.repo_name)[:10] + c.repo_changesets = Page(list(c.repo_info[:10]), page=1, items_per_page=20) e = request.environ uri = u'%(protocol)s://%(user)s@%(host)s/%(repo_name)s' % { 'protocol': e.get('wsgi.url_scheme'), diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/lib/filters.py --- a/pylons_app/lib/filters.py Sun Jun 13 23:14:04 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -#!/usr/bin/env python -# encoding: utf-8 -# simple filters for hg apps html templates -# Copyright (C) 2009-2010 Marcin Kuzminski - -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; version 2 -# of the License or (at your opinion) any later version of the license. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, -# MA 02110-1301, USA. - -""" -Created on April 12, 2010 -simple filters for hg apps html templates -@author: marcink -""" - -from mercurial import util -from mercurial.templatefilters import age as _age, person as _person - -age = lambda x:_age(x) -capitalize = lambda x: x.capitalize() -date = lambda x: util.datestr(x) -email = util.email -person = lambda x: _person(x) -hgdate = lambda x: "%d %d" % x -isodate = lambda x: util.datestr(x, '%Y-%m-%d %H:%M %1%2') -isodatesec = lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2') -localdate = lambda x: (x[0], util.makedate()[1]) -rfc822date = lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2") -rfc3339date = lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2") -time_ago = lambda x: util.datestr(_age(x), "%a, %d %b %Y %H:%M:%S %1%2") diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/lib/helpers.py --- a/pylons_app/lib/helpers.py Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/lib/helpers.py Sun Jun 13 23:56:16 2010 +0200 @@ -203,3 +203,29 @@ return slug flash = _Flash() + + +#=============================================================================== +# MERCURIAL FILTERS available via h. +#=============================================================================== + + +from mercurial import util +from mercurial.templatefilters import age as _age, person as _person + +age = lambda x:_age(x) +capitalize = lambda x: x.capitalize() +date = lambda x: util.datestr(x) +email = util.email +person = lambda x: _person(x) +hgdate = lambda x: "%d %d" % x +isodate = lambda x: util.datestr(x, '%Y-%m-%d %H:%M %1%2') +isodatesec = lambda x: util.datestr(x, '%Y-%m-%d %H:%M:%S %1%2') +localdate = lambda x: (x[0], util.makedate()[1]) +rfc822date = lambda x: util.datestr(x, "%a, %d %b %Y %H:%M:%S %1%2") +rfc3339date = lambda x: util.datestr(x, "%Y-%m-%dT%H:%M:%S%1:%2") +time_ago = lambda x: util.datestr(_age(x), "%a, %d %b %Y %H:%M:%S %1%2") + + + + diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/branches/branches.html --- a/pylons_app/templates/branches/branches.html Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/templates/branches/branches.html Sun Jun 13 23:56:16 2010 +0200 @@ -1,5 +1,4 @@ <%inherit file="/base/base.html"/> -<%! from pylons_app.lib import filters %> <%def name="title()"> ${_('Branches')} @@ -14,33 +13,6 @@ ${self.menu('branches')} <%def name="main()"> - - - - - - - - - - %for cnt,branch in enumerate(c.repo_branches.items()): - - - - - - - %endfor -
${_('date')}${_('revision')}${_('name')}${_('links')}
${branch[1]._ctx.date()|n,filters.age}r${branch[1].revision}:${branch[1].raw_id} - - ${h.link_to(branch[0], - h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))} - - - ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))} - | - ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=branch[1].raw_id))} -
- + <%include file='branches_data.html'/> \ No newline at end of file diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/branches/branches_data.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/templates/branches/branches_data.html Sun Jun 13 23:56:16 2010 +0200 @@ -0,0 +1,30 @@ +% if c.repo_branches: + + + + + + + + %for cnt,branch in enumerate(c.repo_branches.items()): + + + + + + + %endfor +
${_('date')}${_('revision')}${_('name')}${_('links')}
${h.age(branch[1]._ctx.date())}r${branch[1].revision}:${branch[1].raw_id} + + ${h.link_to(branch[0], + h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))} + + + ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))} + | + ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=branch[1].raw_id))} +
+%else: + ${_('There are no branches yet')} +%endif + diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/changelog/changelog.html --- a/pylons_app/templates/changelog/changelog.html Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/templates/changelog/changelog.html Sun Jun 13 23:56:16 2010 +0200 @@ -1,6 +1,3 @@ -<%! -from pylons_app.lib import filters -%> <%inherit file="/base/base.html"/> <%def name="title()"> @@ -19,8 +16,12 @@ <%def name="main()"> - + +% if c.pagination:
##
@@ -89,4 +90,7 @@

${c.pagination.pager('$link_previous ~2~ $link_next')}

+%else: + ${_('There are no changes yet')} +%endif \ No newline at end of file diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/changeset/changeset.html --- a/pylons_app/templates/changeset/changeset.html Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/templates/changeset/changeset.html Sun Jun 13 23:56:16 2010 +0200 @@ -1,6 +1,3 @@ -<%! -from pylons_app.lib import filters -%> <%inherit file="/base/base.html"/> <%def name="title()"> diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/errors/error_404.html --- a/pylons_app/templates/errors/error_404.html Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/templates/errors/error_404.html Sun Jun 13 23:56:16 2010 +0200 @@ -1,7 +1,4 @@ ## -*- coding: utf-8 -*- -<%! -from pylons_app.lib import filters -%> <%inherit file="./../base/base.html"/> <%def name="title()"> diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/index.html --- a/pylons_app/templates/index.html Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/templates/index.html Sun Jun 13 23:56:16 2010 +0200 @@ -1,7 +1,4 @@ ## -*- coding: utf-8 -*- -<%! -from pylons_app.lib import filters -%> <%inherit file="base/base.html"/> <%def name="title()"> ${c.repos_prefix} Mercurial Repositories @@ -38,12 +35,12 @@ ${h.link_to(repo['name'], h.url('summary_home',repo_name=repo['name']))} ${h.truncate(repo['description'],60)} - ${repo['last_change']|n,filters.age} + ${h.age(repo['last_change'])} ${h.link_to('r%s:%s' % (repo['rev'],repo['tip']), h.url('changeset_home',repo_name=repo['name'],revision=repo['tip']), class_="tooltip", tooltip_title=h.tooltip(repo['last_msg']))} - ${repo['contact']|n,filters.person} + ${h.person(repo['contact'])} diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/login.html --- a/pylons_app/templates/login.html Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/templates/login.html Sun Jun 13 23:56:16 2010 +0200 @@ -1,7 +1,4 @@ ## -*- coding: utf-8 -*- -<%! -from pylons_app.lib import filters -%> <%inherit file="base/base.html"/> <%def name="title()"> ${c.repos_prefix} Mercurial Repositories diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/shortlog/shortlog_data.html --- a/pylons_app/templates/shortlog/shortlog_data.html Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/templates/shortlog/shortlog_data.html Sun Jun 13 23:56:16 2010 +0200 @@ -1,7 +1,6 @@ ## -*- coding: utf-8 -*- -<%! -from pylons_app.lib import filters -%> +% if c.repo_changesets: + @@ -15,8 +14,8 @@ %for cnt,cs in enumerate(c.repo_changesets): - - + +
${_('date')}
${cs._ctx.date()|n,filters.age}${cs.author|n,filters.person}${h.age(cs._ctx.date())}${h.person(cs.author)} r${cs.revision}:${cs.raw_id} ${h.link_to(h.truncate(cs.message,60), @@ -59,4 +58,7 @@ YAHOO.util.Dom.setStyle(data_div,'opacity','0.3');}); YAHOO.util.Dom.setStyle(data_div,'opacity','1');}},null); return false;""")} - \ No newline at end of file + +%else: + ${_('There are no commits yet')} +%endif \ No newline at end of file diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/summary/summary.html --- a/pylons_app/templates/summary/summary.html Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/templates/summary/summary.html Sun Jun 13 23:56:16 2010 +0200 @@ -1,7 +1,4 @@ <%inherit file="/base/base.html"/> -<%! -from pylons_app.lib import filters -%> <%def name="title()"> ${_('Repository managment')} @@ -41,7 +38,7 @@
${_('contact')}
${c.repo_info.contact}
${_('last change')}
-
${c.repo_info.last_change|n,filters.age} - ${c.repo_info.last_change|n,filters.rfc822date}
+
${h.age(c.repo_info.last_change)} - ${h.rfc822date(c.repo_info.last_change)}
${_('clone url')}
${_('download')}
@@ -63,100 +60,12 @@

${h.link_to(_('Last ten changes'),h.url('changelog_home',repo_name=c.repo_name))}

- - - - - - - - - - - - %for cnt,cs in enumerate(c.repo_changesets): - - - - - - - - - - %endfor -
${_('date')}${_('author')}${_('revision')}${_('commit message')}${_('branch')}${_('tags')}${_('links')}
${cs._ctx.date()|n,filters.age}${cs.author|n,filters.person}r${cs.revision}:${cs.raw_id} - ${h.link_to(h.truncate(cs.message,60), - h.url('changeset_home',repo_name=c.repo_name,revision=cs._short), - title=cs.message)} - - - ${cs.branch} - - - - %for tag in cs.tags: - ${tag} - %endfor - - - ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=cs._short))} - | - ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=cs._short))} -
+ <%include file='../shortlog/shortlog_data.html'/>

${h.link_to(_('Last ten tags'),h.url('tags_home',repo_name=c.repo_name))}

- - - - - - - - %for cnt,tag in enumerate(c.repo_tags.items()): - - - - - - - %endfor -
${_('date')}${_('revision')}${_('name')}${_('links')}
${tag[1]._ctx.date()|n,filters.age}r${tag[1].revision}:${tag[1].raw_id} - - ${h.link_to(tag[0], - h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))} - - - ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))} - | - ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=tag[1].raw_id))} -
- + <%include file='../tags/tags_data.html'/> +

${h.link_to(_('Last ten branches'),h.url('branches_home',repo_name=c.repo_name))}

- - - - - - - - %for cnt,branch in enumerate(c.repo_branches.items()): - - - - - - - %endfor -
${_('date')}${_('revision')}${_('name')}${_('links')}
${branch[1]._ctx.date()|n,filters.age}r${branch[1].revision}:${branch[1].raw_id} - - ${h.link_to(branch[0], - h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))} - - - ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=branch[1].raw_id))} - | - ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=branch[1].raw_id))} -
+ <%include file='../branches/branches_data.html'/> \ No newline at end of file diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/tags/tags.html --- a/pylons_app/templates/tags/tags.html Sun Jun 13 23:14:04 2010 +0200 +++ b/pylons_app/templates/tags/tags.html Sun Jun 13 23:56:16 2010 +0200 @@ -1,7 +1,4 @@ <%inherit file="/base/base.html"/> -<%! -from pylons_app.lib import filters -%> <%def name="title()"> ${_('Tags')} @@ -18,30 +15,6 @@ <%def name="main()"> - - - - - - - - %for cnt,tag in enumerate(c.repo_tags.items()): - - - - - - - %endfor -
${_('date')}${_('revision')}${_('name')}${_('links')}
${tag[1]._ctx.date()|n,filters.age}r${tag[1].revision}:${tag[1].raw_id} - - ${h.link_to(tag[0], - h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))} - - - ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))} - | - ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=tag[1].raw_id))} -
+ <%include file='tags_data.html'/> \ No newline at end of file diff -r cd2ee462fc2c -r 237470e64bb8 pylons_app/templates/tags/tags_data.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pylons_app/templates/tags/tags_data.html Sun Jun 13 23:56:16 2010 +0200 @@ -0,0 +1,29 @@ +%if c.repo_tags: + + + + + + + + %for cnt,tag in enumerate(c.repo_tags.items()): + + + + + + + %endfor +
${_('date')}${_('revision')}${_('name')}${_('links')}
${h.age(tag[1]._ctx.date())}r${tag[1].revision}:${tag[1].raw_id} + + ${h.link_to(tag[0], + h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))} + + + ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=tag[1].raw_id))} + | + ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=tag[1].raw_id))} +
+%else: + ${_('There are no tags yet')} +%endif \ No newline at end of file