Changeset - df61378032f3
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 15 years ago 2010-11-05 22:36:51
marcin@python-works.com
#48 rewrote action logger, translated action logger messages, added some extra messages. Linked and showed pushed revisions in logs
4 files changed with 53 insertions and 10 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/admin/repos.py
Show inline comments
 
@@ -128,24 +128,27 @@ class ReposController(BaseController):
 
        # url('repo', repo_name=ID)
 
        repo_model = RepoModel()
 
        changed_name = repo_name
 
        _form = RepoForm(edit=True, old_data={'repo_name':repo_name})()
 

	
 
        try:
 
            form_result = _form.to_python(dict(request.POST))
 
            repo_model.update(repo_name, form_result)
 
            invalidate_cache('cached_repo_list')
 
            h.flash(_('Repository %s updated succesfully' % repo_name),
 
                    category='success')
 
            changed_name = form_result['repo_name']
 
            action_logger(self.rhodecode_user, 'admin_updated_repo',
 
                              changed_name, '', self.sa)
 

	
 
        except formencode.Invalid, errors:
 
            c.repo_info = repo_model.get(repo_name)
 
            c.users_array = repo_model.get_users_js()
 
            errors.value.update({'user':c.repo_info.user.username})
 
            return htmlfill.render(
 
                render('admin/repos/repo_edit.html'),
 
                defaults=errors.value,
 
                errors=errors.error_dict or {},
 
                prefix_error=False,
 
                encoding="UTF-8")
 

	
 
        except Exception:
rhodecode/controllers/settings.py
Show inline comments
 
@@ -73,24 +73,26 @@ class SettingsController(BaseController)
 

	
 
    def update(self, repo_name):
 
        repo_model = RepoModel()
 
        changed_name = repo_name
 
        _form = RepoSettingsForm(edit=True, old_data={'repo_name':repo_name})()
 
        try:
 
            form_result = _form.to_python(dict(request.POST))
 
            repo_model.update(repo_name, form_result)
 
            invalidate_cache('cached_repo_list')
 
            h.flash(_('Repository %s updated successfully' % repo_name),
 
                    category='success')
 
            changed_name = form_result['repo_name']
 
            action_logger(self.rhodecode_user, 'user_updated_repo',
 
                              changed_name, '', self.sa)
 
        except formencode.Invalid, errors:
 
            c.repo_info = repo_model.get(repo_name)
 
            c.users_array = repo_model.get_users_js()
 
            errors.value.update({'user':c.repo_info.user.username})
 
            return htmlfill.render(
 
                render('settings/repo_settings.html'),
 
                defaults=errors.value,
 
                errors=errors.error_dict or {},
 
                prefix_error=False,
 
                encoding="UTF-8")
 
        except Exception:
 
            log.error(traceback.format_exc())
rhodecode/lib/helpers.py
Show inline comments
 
@@ -319,25 +319,25 @@ 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 ''
 

	
 
    from datetime import timedelta, datetime
 

	
 
    agescales = [("year", 3600 * 24 * 365),
 
                 ("month", 3600 * 24 * 30),
 
                 ("day", 3600 * 24),
 
                 ("hour", 3600),
 
                 ("minute", 60),
 
                 ("second", 1), ]
 

	
 
@@ -348,24 +348,68 @@ def _age(curdate):
 
        if scale[1] <= age_seconds:
 
            if pos == 6:pos = 5
 
            return time_ago_in_words(curdate, agescales[pos][0])
 
        pos += 1
 

	
 
age = lambda  x:_age(x)
 
capitalize = lambda x: x.capitalize()
 
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 action_parser(user_log):
 
    """
 
    This helper will map the specified string action into translated
 
    fancy names with icons and links
 
    
 
    @param action:
 
    """
 
    action = user_log.action
 
    action_params = None
 
    cs_links = ''
 

	
 
    x = action.split(':')
 

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

	
 
    if action == 'push':
 
        revs_limit = 5
 
        revs = action_params.split(',')
 
        cs_links = " " + ', '.join ([link(rev,
 
                url('changeset_home',
 
                repo_name=user_log.repository.repo_name,
 
                revision=rev)) for rev in revs[:revs_limit] ])
 
        if len(revs) > revs_limit:
 
            html_tmpl = '<span title="%s"> %s </span>'
 
            cs_links += html_tmpl % (', '.join(r for r in revs[revs_limit:]),
 
                                     _('and %s more revisions') % (len(revs) - revs_limit))
 

	
 
    map = {'user_deleted_repo':_('User deleted repository'),
 
           'user_created_repo':_('User created repository'),
 
           'user_forked_repo':_('User forked repository'),
 
           'user_updated_repo':_('User updated repository'),
 
           'admin_deleted_repo':_('Admin delete repository'),
 
           'admin_created_repo':_('Admin created repository'),
 
           'admin_forked_repo':_('Admin forked repository'),
 
           'admin_updated_repo':_('Admin updated repository'),
 
           'push':_('Pushed') + literal(cs_links),
 
           'pull':_('Pulled'), }
 

	
 
    print action, action_params
 
    return map.get(action, action)
 

	
 

	
 
#==============================================================================
 
# PERMS
 
#==============================================================================
 
from rhodecode.lib.auth import HasPermissionAny, HasPermissionAll, \
 
HasRepoPermissionAny, HasRepoPermissionAll
 

	
 
#==============================================================================
 
# GRAVATAR URL
 
#==============================================================================
 
import hashlib
 
import urllib
 
from pylons import request
rhodecode/templates/admin/admin_log.html
Show inline comments
 
## -*- coding: utf-8 -*-
 
%if c.users_log:
 
<table>
 
	<tr>
 
		<th class="left">${_('Username')}</th>
 
		<th class="left">${_('Action')}</th>
 
		<th class="left">${_('Repository')}</th>
 
		<th class="left">${_('Action')}</th>
 
		<th class="left">${_('Date')}</th>
 
		<th class="left">${_('From IP')}</th>
 
	</tr>
 

	
 
	%for cnt,l in enumerate(c.users_log):
 
	<tr class="parity${cnt%2}">
 
		<td>${h.link_to(l.user.username,h.url('edit_user', id=l.user.user_id))}</td>
 
		<td>${h.action_parser(l)}</td>
 
		<td>
 
		%if l.repository:
 
		  ${h.link_to(l.repository.repo_name,h.url('summary_home',repo_name=l.repository.repo_name))}
 
		%else:
 
		  ${l.repository_name}
 
		%endif
 
		</td>
 
		<td>
 
		% if l.action == 'push' and l.revision:
 
		  ${h.link_to('%s - %s' % (l.action,l.revision),
 
		  h.url('changeset_home',repo_name=l.repository.repo_name,revision=l.revision))}
 
		%else:
 
		  ${l.action}
 
		%endif
 
		</td>
 
		
 
		<td>${l.action_date}</td>
 
		<td>${l.user_ip}</td>
 
	</tr>
 
	%endfor
 
</table>
 

	
 
<script type="text/javascript">
 
  var data_div = 'user_log';
 
  YAHOO.util.Event.onDOMReady(function(){
 
	YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('pager_link'),"click",function(){
 
			YAHOO.util.Dom.setStyle('shortlog_data','opacity','0.3');});});
 
</script>
0 comments (0 inline, 0 general)