Mercurial > kallithea
changeset 994:7f9d23f6a526 beta
Added grouping by days in journal
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 04 Feb 2011 13:40:38 +0100 |
parents | e80b2cbbd4ba |
children | d14723711d17 |
files | rhodecode/controllers/journal.py rhodecode/model/db.py rhodecode/templates/journal.html |
diffstat | 3 files changed, 47 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/controllers/journal.py Fri Feb 04 12:29:45 2011 +0100 +++ b/rhodecode/controllers/journal.py Fri Feb 04 13:40:38 2011 +0100 @@ -33,6 +33,7 @@ from rhodecode.lib.auth import LoginRequired, NotAnonymous from rhodecode.lib.base import BaseController, render from rhodecode.lib.helpers import get_token +from rhodecode.lib.utils import OrderedDict from rhodecode.model.db import UserLog, UserFollowing from rhodecode.model.scm import ScmModel @@ -59,16 +60,29 @@ user_ids = [x.follows_user.user_id for x in c.following if x.follows_user is not None] - c.journal = self.sa.query(UserLog)\ + journal = self.sa.query(UserLog)\ .filter(or_( UserLog.repository_id.in_(repo_ids), UserLog.user_id.in_(user_ids), ))\ .order_by(UserLog.action_date.desc())\ - .limit(20)\ + .limit(30)\ .all() + + c.journal_day_aggreagate = self._get_daily_aggregate(journal) + return render('/journal.html') + + def _get_daily_aggregate(self, journal): + from itertools import groupby + groups = [] + for k, g in groupby(journal, lambda x:x.action_as_day): + groups.append((k, list(g),)) # Store group iterator as a list + + return groups + + def toggle_following(self): cur_token = request.POST.get('auth_token') token = get_token()
--- a/rhodecode/model/db.py Fri Feb 04 12:29:45 2011 +0100 +++ b/rhodecode/model/db.py Fri Feb 04 13:40:38 2011 +0100 @@ -26,6 +26,7 @@ # MA 02110-1301, USA. import logging import datetime +from datetime import date from sqlalchemy import * from sqlalchemy.exc import DatabaseError @@ -150,6 +151,10 @@ action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None) + @property + def action_as_day(self): + return date(*self.action_date.timetuple()[:3]) + user = relationship('User') repository = relationship('Repository')
--- a/rhodecode/templates/journal.html Fri Feb 04 12:29:45 2011 +0100 +++ b/rhodecode/templates/journal.html Fri Feb 04 13:40:38 2011 +0100 @@ -17,29 +17,32 @@ <h5>${_('Journal')}</h5> </div> <div> - %if c.journal: - %for entry in c.journal: - <div style="padding:10px"> - <div class="gravatar"> - <img alt="gravatar" src="${h.gravatar_url(entry.user.email)}"/> - </div> - <div>${entry.user.name} ${entry.user.lastname}</div> - <div style="padding-left: 45px;padding-top:5px;min-height:20px">${h.action_parser(entry)}</div> - <div style="float: left; padding-top: 8px;padding-left:18px"> - ${h.action_parser_icon(entry)} - </div> - <div style="margin-left: 45px;padding-top: 10px"> - <span style="font-weight: bold;font-size: 1.1em"> - %if entry.repository: - ${h.link_to(entry.repository.repo_name, - h.url('summary_home',repo_name=entry.repository.repo_name))} - %else: - ${entry.repository_name} - %endif - </span> - <span title="${entry.action_date}">${h.age(entry.action_date)}</span> - </div> - </div> - <div style="clear:both;border-bottom:1px dashed #DDD;padding:3px 3px;margin:0px 10px 0px 10px"></div> + %if c.journal_day_aggreagate: + %for day,items in c.journal_day_aggreagate: + <div style="font-size:20px;padding:10px 5px">${day}</div> + % for entry in items: + <div style="padding:10px"> + <div class="gravatar"> + <img alt="gravatar" src="${h.gravatar_url(entry.user.email)}"/> + </div> + <div>${entry.user.name} ${entry.user.lastname}</div> + <div style="padding-left: 45px;padding-top:5px;min-height:20px">${h.action_parser(entry)}</div> + <div style="float: left; padding-top: 8px;padding-left:18px"> + ${h.action_parser_icon(entry)} + </div> + <div style="margin-left: 45px;padding-top: 10px"> + <span style="font-weight: bold;font-size: 1.1em"> + %if entry.repository: + ${h.link_to(entry.repository.repo_name, + h.url('summary_home',repo_name=entry.repository.repo_name))} + %else: + ${entry.repository_name} + %endif + </span> - <span title="${entry.action_date}">${h.age(entry.action_date)}</span> + </div> + </div> + <div style="clear:both;border-bottom:1px dashed #DDD;padding:3px 3px;margin:0px 10px 0px 10px"></div> + %endfor %endfor %else: ${_('No entries yet')}