Changeset - d65843e07d3c
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 15 years ago 2010-12-31 12:12:19
marcin@python-works.com
Added message tooltip into journal revisions in push.
removed link helper as obsolete
2 files changed with 40 insertions and 44 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/files.py
Show inline comments
 
@@ -263,11 +263,6 @@ class FilesController(BaseController):
 
            #chs = chs.split(':')[-1]
 
            tags_group[0].append((chs, name),)
 
        hist_l.append(tags_group)
 

	
 
        return hist_l
 

	
 
#                [
 
#                 ([("u1", "User1"), ("u2", "User2")], "Users"),
 
#                 ([("g1", "Group1"), ("g2", "Group2")], "Groups")
 
#                 ]
 

	
rhodecode/lib/helpers.py
Show inline comments
 
@@ -28,12 +28,14 @@ from webhelpers.text import chop_at, col
 
from webhelpers.date import time_ago_in_words
 

	
 
from webhelpers.html.tags import _set_input_attrs, _set_id_attr, \
 
    convert_boolean_attrs, NotGiven
 

	
 
def _reset(name, value=None, id=NotGiven, type="reset", **attrs):
 
    """Reset button
 
    """
 
    _set_input_attrs(attrs, type, name, value)
 
    _set_id_attr(attrs, id, name)
 
    convert_boolean_attrs(attrs, ["disabled"])
 
    return HTML.input(**attrs)
 

	
 
reset = _reset
 
@@ -52,43 +54,32 @@ def get_token():
 
            token = hashlib.sha1(str(random.randrange(2 ** 128))).hexdigest()
 
        session[token_key] = token
 
        if hasattr(session, 'save'):
 
            session.save()
 
    return session[token_key]
 

	
 

	
 
#Custom helpers 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 '':
 
            label = url
 
        link_fn = link_to(label, url(*url_, **urlargs))
 
        return link_fn
 

	
 
link = _Link()
 

	
 
class _GetError(object):
 
    """Get error from form_errors, and represent it as span wrapped error
 
    message
 
    
 
    :param field_name: field to fetch errors for
 
    :param form_errors: form errors dict
 
    """
 

	
 
    def __call__(self, field_name, form_errors):
 
        tmpl = """<span class="error_msg">%s</span>"""
 
        if form_errors and form_errors.has_key(field_name):
 
            return literal(tmpl % form_errors.get(field_name))
 

	
 
get_error = _GetError()
 

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

	
 
@@ -242,33 +233,35 @@ class _FilesBreadCrumbs(object):
 
                                            revision=rev,
 
                                            f_path='/'.join(paths_l[:cnt + 1]))))
 

	
 
        return literal('/'.join(url_l))
 

	
 
files_breadcrumbs = _FilesBreadCrumbs()
 

	
 
class CodeHtmlFormatter(HtmlFormatter):
 

	
 
    def wrap(self, source, outfile):
 
        return self._wrap_div(self._wrap_pre(self._wrap_code(source)))
 

	
 
    def _wrap_code(self, source):
 
        for cnt, it in enumerate(source):
 
            i, t = it
 
            t = '<div id="#S-%s">%s</div>' % (cnt + 1, t)
 
            yield i, t
 
def pygmentize(filenode, **kwargs):
 
    """
 
    pygmentize function using pygments
 
    """pygmentize function using pygments
 
    
 
    :param filenode:
 
    """
 

	
 
    return literal(code_highlight(filenode.content,
 
                                  filenode.lexer, CodeHtmlFormatter(**kwargs)))
 

	
 
def pygmentize_annotation(filenode, **kwargs):
 
    """
 
    pygmentize function for annotation
 
    """pygmentize function for annotation
 
    
 
    :param filenode:
 
    """
 

	
 
    color_dict = {}
 
    def gen_color():
 
        """generator for getting 10k of evenly distibuted colors using hsv color
 
@@ -319,12 +312,13 @@ def pygmentize_annotation(filenode, **kw
 

	
 
def repo_name_slug(value):
 
    """Return slug of name of repository
 
    This function is called on each creation/modification
 
    of repository to prevent bad names in repo
 
    """
 

	
 
    slug = remove_formatting(value)
 
    slug = strip_tags(slug)
 

	
 
    for c in """=[]\;'"<>,/~!@#$%^&*()+{}|: """:
 
        slug = slug.replace(c, '-')
 
    slug = recursive_replace(slug, '-')
 
@@ -352,14 +346,12 @@ flash = _Flash()
 
#==============================================================================
 
# MERCURIAL FILTERS available via h.
 
#==============================================================================
 
from mercurial import util
 
from mercurial.templatefilters import person as _person
 

	
 

	
 

	
 
def _age(curdate):
 
    """turns a datetime into an age string."""
 

	
 
    if not curdate:
 
        return ''
 

	
 
@@ -389,15 +381,15 @@ email = util.email
 
email_or_none = lambda x: util.email(x) if util.email(x) != x else None
 
person = lambda x: _person(x)
 
short_id = lambda x: x[:12]
 

	
 

	
 
def bool2icon(value):
 
    """
 
    Returns True/False values represented as small html image of true/false
 
    """Returns True/False values represented as small html image of true/false
 
    icons
 
    
 
    :param value: bool value
 
    """
 

	
 
    if value is True:
 
        return HTML.tag('img', src="/images/icons/accept.png", alt=_('True'))
 

	
 
@@ -405,48 +397,57 @@ def bool2icon(value):
 
        return HTML.tag('img', src="/images/icons/cancel.png", alt=_('False'))
 

	
 
    return value
 

	
 

	
 
def action_parser(user_log):
 
    """
 
    This helper will map the specified string action into translated
 
    """This helper will map the specified string action into translated
 
    fancy names with icons and links
 
    
 
    @param action:
 
    :param user_log: user log instance
 
    """
 

	
 
    action = user_log.action
 
    action_params = ' '
 

	
 
    x = action.split(':')
 

	
 
    if len(x) > 1:
 
        action, action_params = x
 

	
 
    def get_cs_links():
 
        if action == 'push':
 
            revs_limit = 5
 
            revs_limit = 5 #display this amount always
 
            revs_top_limit = 50 #show upto this amount of changesets hidden
 
            revs = action_params.split(',')
 
            cs_links = " " + ', '.join ([link(rev,
 
            repo_name = user_log.repository.repo_name
 
            from rhodecode.model.scm import ScmModel
 

	
 
            message = lambda rev: get_changeset_safe(ScmModel().get(repo_name),
 
                                                     rev).message
 

	
 
            cs_links = " " + ', '.join ([link_to(rev,
 
                    url('changeset_home',
 
                    repo_name=user_log.repository.repo_name,
 
                    revision=rev)) for rev in revs[:revs_limit] ])
 
                    repo_name=repo_name,
 
                    revision=rev), tooltip_title=message(rev),
 
                    class_='tooltip') for rev in revs[:revs_limit] ])
 
            if len(revs) > revs_limit:
 
                uniq_id = revs[0]
 
                html_tmpl = ('<span> %s '
 
                '<a class="show_more" id="_%s" href="#">%s</a> '
 
                '%s</span>')
 
                cs_links += html_tmpl % (_('and'), uniq_id, _('%s more') \
 
                                            % (len(revs) - revs_limit),
 
                                            _('revisions'))
 

	
 
                html_tmpl = '<span id="%s" style="display:none"> %s </span>'
 
                cs_links += html_tmpl % (uniq_id, ', '.join([link(rev,
 
                cs_links += html_tmpl % (uniq_id, ', '.join([link_to(rev,
 
                    url('changeset_home',
 
                    repo_name=user_log.repository.repo_name,
 
                    revision=rev)) for rev in revs[revs_limit:] ]))
 
                    repo_name=repo_name, revision=rev),
 
                    tooltip_title=message(rev), class_='tooltip')
 
                    for rev in revs[revs_limit:revs_top_limit]]))
 

	
 
            return cs_links
 
        return ''
 

	
 
    def get_fork_name():
 
        if action == 'user_forked_repo':
 
@@ -488,13 +489,13 @@ def action_parser_icon(user_log):
 
    tmpl = """<img src="/images/icons/%s" alt="%s"/>"""
 
    map = {'user_deleted_repo':'database_delete.png',
 
           'user_created_repo':'database_add.png',
 
           'user_forked_repo':'arrow_divide.png',
 
           'user_updated_repo':'database_edit.png',
 
           'admin_deleted_repo':'database_delete.png',
 
           'admin_created_repo':'database_ddd.png',
 
           'admin_created_repo':'database_add.png',
 
           'admin_forked_repo':'arrow_divide.png',
 
           'admin_updated_repo':'database_edit.png',
 
           'push':'script_add.png',
 
           'pull':'down_16.png',
 
           'started_following_repo':'heart_add.png',
 
           'stopped_following_repo':'heart_delete.png',
0 comments (0 inline, 0 general)