Changeset - 6ada8c223374
[Not reviewed]
default
0 7 0
Marcin Kuzminski - 15 years ago 2010-06-06 21:54:54
marcin@python-works.com
made global funcion to clean repo names, and remove all special chars from the name.
Switched message slug into webhelpers function
7 files changed with 35 insertions and 34 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/error.py
Show inline comments
 
import logging
 
import cgi
 
import os
 
import paste.fileapp
 
from pylons import tmpl_context as c, app_globals as g, request, config
 
from pylons.controllers.util import forward
 
from pylons.i18n.translation import _
 
from pylons_app.lib.base import BaseController, render
 
from pylons.middleware import  media_path
 
from pylons_app.lib.utils import check_repo
 
from pylons_app.lib.filters import clean_repo
 
import pylons_app.lib.helpers as h
 
log = logging.getLogger(__name__)
 

	
 
class ErrorController(BaseController):
 
    """
 
    Generates error documents as and when they are required.
 

	
 
    The ErrorDocuments middleware forwards to ErrorController when error
 
    related status codes are returned from the application.
 

	
 
    This behaviour can be altered by changing the parameters to the
 
    ErrorDocuments middleware in your config/middleware.py file.
 
    """
 
@@ -30,25 +30,25 @@ class ErrorController(BaseController):
 
        log.debug(resp.status)
 

	
 
        e = request.environ
 
        c.serv_p = r'%(protocol)s://%(host)s/' % {
 
                                                'protocol': e.get('wsgi.url_scheme'),
 
                                                'host':e.get('HTTP_HOST'),
 
                                                }
 

	
 
                        
 
        if resp.status_int == 404:
 
            org_e = request.environ.get('pylons.original_request').environ
 
            c.repo_name = repo_name = org_e['PATH_INFO'].split('/')[1]
 
            c.repo_name_cleaned = clean_repo(c.repo_name)
 
            c.repo_name_cleaned = h.repo_name_slug(c.repo_name)
 
            if check_repo(repo_name, g.base_path):
 
                return render('/errors/error_404.html')
 
                
 
        c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
 
        c.error_explanation = self.get_error_explanation(resp.status_int)
 

	
 
        #redirect to when error with given seconds
 
        c.redirect_time = 0
 
        c.redirect_module = _('Home page')# name to what your going to be redirected
 
        c.url_redirect = "/"
 

	
 
        return render('/errors/error_document.html')
pylons_app/lib/filters.py
Show inline comments
 
@@ -17,32 +17,24 @@
 
# 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
 
from string import punctuation
 

	
 
def clean_repo(repo_name):
 
    for x in punctuation:
 
        if x != '_':
 
            repo_name = repo_name.replace(x, '')
 
    repo_name = repo_name.lower().strip()
 
    return repo_name.replace(' ', '_')
 

	
 
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")
pylons_app/lib/helpers.py
Show inline comments
 
@@ -12,25 +12,25 @@ from webhelpers.html import literal, HTM
 
from webhelpers.html.builder import make_tag
 
from webhelpers.html.tags import auto_discovery_link, checkbox, css_classes, \
 
    end_form, file, form, hidden, image, javascript_link, link_to, link_to_if, \
 
    link_to_unless, ol, required_legend, select, stylesheet_link, submit, text, \
 
    password, textarea, title, ul, xml_declaration
 
from webhelpers.html.tools import auto_link, button_to, highlight, js_obfuscate, \
 
    mail_to, strip_links, strip_tags, tag_re
 
from webhelpers.number import format_byte_size, format_bit_size
 
from webhelpers.pylonslib import Flash as _Flash
 
from webhelpers.pylonslib.secure_form import secure_form
 
from webhelpers.text import chop_at, collapse, convert_accented_entities, \
 
    convert_misc_entities, lchop, plural, rchop, remove_formatting, \
 
    replace_whitespace, urlify
 
    replace_whitespace, urlify, truncate
 

	
 

	
 
#Custom helper here :)
 
class _Link(object):
 
    '''
 
    Make a url based on label and url with help of url_for
 
    @param label:name of link    if not defined url is used
 
    @param url: the url for link
 
    '''
 

	
 
    def __call__(self, label='', *url_, **urlargs):
 
        if label is None or '':
 
@@ -83,16 +83,45 @@ def pygmentize_annotation(filenode, **kw
 
            col = color_dict[cs]
 
        return "color: rgb(%s) ! important;" % (','.join(col))
 
        
 
    def url_func(changeset):
 
        return '%s\n' % (link_to(changeset.raw_id,
 
        url('changeset_home', repo_name='test', revision=changeset.raw_id),
 
        title=_('author') + ':%s rev:%s %s' % (changeset.author, changeset.revision,
 
                                                changeset.message,),
 
        style=get_color_string(changeset.raw_id)))
 
           
 
    return literal(annotate_highlight(filenode, url_func, **kwargs))
 

	
 
def recursive_replace(str, replace=' '):
 
    """
 
    Recursive replace of given sign to just one instance
 
    @param str: given string
 
    @param replace:char to find and replace multiple instances
 
        
 
    Examples::
 
    >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-')
 
    'Mighty-Mighty-Bo-sstones'
 
    """
 

	
 
    if str.find(replace * 2) == -1:
 
        return str
 
    else:
 
        str = str.replace(replace * 2, replace)
 
        return recursive_replace(str, replace)  
 
      
 
def repo_name_slug(value):
 
    """
 
    Return slug of name of repository
 
    """
 
    slug = urlify(value)
 
    for c in """=[]\;',/~!@#$%^&*()+{}|:""":
 
        slug = slug.replace(c, '-')
 
    print slug
 
    slug = recursive_replace(slug, '-')
 
    print slug    
 
    return slug
 
    
 
files_breadcrumbs = _FilesBreadCrumbs()
 
link = _Link()
 
flash = _Flash()
 
get_error = _GetError()
pylons_app/templates/base/base.html
Show inline comments
 
@@ -142,24 +142,13 @@ def is_current(selected):
 
<script type="text/javascript" src="/js/yui/utilities/utilities.js"></script>
 
</%def>
 

	
 
<!-- DEFINITION OF FORM ERROR FETCHER -->
 
<%def name="get_form_error(element)">
 
	%if hasattr(c,'form_errors') and type(c.form_errors) == dict:
 
        %if c.form_errors.get(element,False):
 
            <span class="error-message">
 
                ${c.form_errors.get(element,'')}
 
            </span>
 
        %endif
 
	%endif           
 
</%def>
 

	
 
<!-- SHORTER LONGER STRINGS -->
 
<%def name="message_slug(msg)">
 
	<%
 
	limit = 60
 
	if len(msg) > limit:
 
		return msg[:limit]+'...'
 
	else:
 
		return msg
 
	%>
 
</%def>
 
\ No newline at end of file
pylons_app/templates/index.html
Show inline comments
 
@@ -28,25 +28,25 @@ from pylons_app.lib import filters
 
	    <td>${get_sort(_('Name'))}</td>
 
	    <td>${get_sort(_('Description'))}</td>
 
	    <td>${get_sort(_('Last change'))}</td>
 
	    <td>${get_sort(_('Tip'))}</td>
 
	    <td>${get_sort(_('Contact'))}</td>
 
	    <td></td>
 
	    <td></td>
 
	    <td></td>
 
	  </tr>	
 
	%for cnt,repo in enumerate(c.repos_list):
 
 		<tr class="parity${cnt%2}">
 
		    <td>${h.link(repo['name'],h.url('summary_home',repo_name=repo['name']))}</td>
 
		    <td title="${repo['description']}">${self.message_slug(repo['description'])}</td>
 
		    <td title="${repo['description']}">${h.truncate(repo['description'],60)}</td>
 
	        <td>${repo['last_change']|n,filters.age}</td>
 
	        <td>${h.link_to('r%s:%s' % (repo['rev'],repo['tip']),h.url('changeset_home',repo_name=repo['name'],revision=repo['tip']))}</td>
 
	        <td title="${repo['contact']}">${repo['contact']|n,filters.person}</td>
 
	        
 
	        	##%for archive in repo['repo_archives']:
 
	        	##<td class="indexlinks">
 
	        	##	${h.link_to(archive['type'],
 
       			##	h.url('files_archive_home',repo_name=repo['name'],
 
       			##	revision='tip',fileformat=archive['extension']),class_="archive_logo" )}
 
				##</td>
 
				##%endfor
 
	        
pylons_app/templates/shortlog/shortlog_data.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
<%!
 
from pylons_app.lib import filters
 
%>
 
<table>
 
%for cnt,cs in enumerate(c.repo_changesets):
 
	<tr class="parity${cnt%2}">
 
		<td>${cs._ctx.date()|n,filters.age}</td>
 
		<td title="${cs.author}">${cs.author|n,filters.person}</td>
 
		<td>r${cs.revision}</td>
 
		<td>
 
			${h.link_to(self.message_slug(cs.message),
 
			${h.link_to(h.truncate(cs.message,60),
 
			h.url('changeset_home',repo_name=c.repo_name,revision=cs._short),
 
			title=cs.message)}
 
		</td>
 
		<td>
 
				<span class="logtags">
 
					<span class="branchtag">${cs.branch}</span>
 
					%for tag in cs.tags:
 
						<span class="tagtag">${tag}</span>
 
					%endfor
 
				</span>
 
		</td>
 
		<td class="nowrap">
pylons_app/templates/summary/summary.html
Show inline comments
 
@@ -55,40 +55,31 @@ E.onDOMReady(function(e){
 
       			revision='tip',fileformat=archive['extension']),class_="archive_logo")}
 
		%endfor
 
        </dd>
 
        <dt>${_('feeds')}</dt>
 
        <dd>
 
        	${h.link_to(_('RSS'),h.url('rss_feed_home',repo_name=c.repo_info.name),class_='rss_logo')}
 
			${h.link_to(_('Atom'),h.url('atom_feed_home',repo_name=c.repo_info.name),class_='atom_logo')}
 
        </dd>
 
    </dl>
 

	
 
    <h2>${h.link_to(_('Changes'),h.url('changelog_home',repo_name=c.repo_name))}</h2>
 
    <table>
 
	<%def name="message_slug(msg)">
 
		<%
 
		limit = 60
 
		if len(msg) > limit:
 
			return msg[:limit]+'...'
 
		else:
 
			return msg
 
		%>
 
	</%def>    
 
	%for cnt,cs in enumerate(c.repo_changesets):
 
		<tr class="parity${cnt%2}">
 
			<td>${cs._ctx.date()|n,filters.age}</td>
 
			<td>${cs.author|n,filters.person}</td>
 
			<td>r${cs.revision}</td>
 
			<td>
 
				${h.link_to(message_slug(cs.message),
 
				${h.link_to(truncate(cs.message,60),
 
				h.url('changeset_home',repo_name=c.repo_name,revision=cs._short),
 
				title=cs.message)}
 
			</td>
 
			<td>
 
				<span class="logtags">
 
					<span class="branchtag">${cs.branch}</span>
 
					%for tag in cs.tags:
 
						<span class="tagtag">${tag}</span>
 
					%endfor
 
				</span>
 
			</td>
 
			<td class="nowrap">
0 comments (0 inline, 0 general)