# HG changeset patch # User Marcin Kuzminski # Date 2011-02-04 12:40:38 # Node ID 7f9d23f6a526b2ab104da40549c1d70b5c4fd21d # Parent e80b2cbbd4babac42097ada9b00a87c101ea70d1 Added grouping by days in journal diff --git a/rhodecode/controllers/journal.py b/rhodecode/controllers/journal.py --- a/rhodecode/controllers/journal.py +++ b/rhodecode/controllers/journal.py @@ -33,6 +33,7 @@ from pylons import request, response, se 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 @@ class JournalController(BaseController): 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() diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -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 @@ class UserLog(Base, BaseModel): 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') diff --git a/rhodecode/templates/journal.html b/rhodecode/templates/journal.html --- a/rhodecode/templates/journal.html +++ b/rhodecode/templates/journal.html @@ -17,29 +17,32 @@
${_('Journal')}
- %if c.journal: - %for entry in c.journal: -
-
- gravatar -
-
${entry.user.name} ${entry.user.lastname}
-
${h.action_parser(entry)}
-
- ${h.action_parser_icon(entry)} -
-
- - %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 - - ${h.age(entry.action_date)} -
-
-
+ %if c.journal_day_aggreagate: + %for day,items in c.journal_day_aggreagate: +
${day}
+ % for entry in items: +
+
+ gravatar +
+
${entry.user.name} ${entry.user.lastname}
+
${h.action_parser(entry)}
+
+ ${h.action_parser_icon(entry)} +
+
+ + %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 + - ${h.age(entry.action_date)} +
+
+
+ %endfor %endfor %else: ${_('No entries yet')}