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 @@