##// END OF EJS Templates
Added grouping by days in journal
marcink -
r994:7f9d23f6 beta
parent child Browse files
Show More
@@ -33,6 +33,7 from pylons import request, response, se
33 from rhodecode.lib.auth import LoginRequired, NotAnonymous
33 from rhodecode.lib.auth import LoginRequired, NotAnonymous
34 from rhodecode.lib.base import BaseController, render
34 from rhodecode.lib.base import BaseController, render
35 from rhodecode.lib.helpers import get_token
35 from rhodecode.lib.helpers import get_token
36 from rhodecode.lib.utils import OrderedDict
36 from rhodecode.model.db import UserLog, UserFollowing
37 from rhodecode.model.db import UserLog, UserFollowing
37 from rhodecode.model.scm import ScmModel
38 from rhodecode.model.scm import ScmModel
38
39
@@ -59,16 +60,29 class JournalController(BaseController):
59 user_ids = [x.follows_user.user_id for x in c.following
60 user_ids = [x.follows_user.user_id for x in c.following
60 if x.follows_user is not None]
61 if x.follows_user is not None]
61
62
62 c.journal = self.sa.query(UserLog)\
63 journal = self.sa.query(UserLog)\
63 .filter(or_(
64 .filter(or_(
64 UserLog.repository_id.in_(repo_ids),
65 UserLog.repository_id.in_(repo_ids),
65 UserLog.user_id.in_(user_ids),
66 UserLog.user_id.in_(user_ids),
66 ))\
67 ))\
67 .order_by(UserLog.action_date.desc())\
68 .order_by(UserLog.action_date.desc())\
68 .limit(20)\
69 .limit(30)\
69 .all()
70 .all()
71
72 c.journal_day_aggreagate = self._get_daily_aggregate(journal)
73
70 return render('/journal.html')
74 return render('/journal.html')
71
75
76
77 def _get_daily_aggregate(self, journal):
78 from itertools import groupby
79 groups = []
80 for k, g in groupby(journal, lambda x:x.action_as_day):
81 groups.append((k, list(g),)) # Store group iterator as a list
82
83 return groups
84
85
72 def toggle_following(self):
86 def toggle_following(self):
73 cur_token = request.POST.get('auth_token')
87 cur_token = request.POST.get('auth_token')
74 token = get_token()
88 token = get_token()
@@ -26,6 +26,7
26 # MA 02110-1301, USA.
26 # MA 02110-1301, USA.
27 import logging
27 import logging
28 import datetime
28 import datetime
29 from datetime import date
29
30
30 from sqlalchemy import *
31 from sqlalchemy import *
31 from sqlalchemy.exc import DatabaseError
32 from sqlalchemy.exc import DatabaseError
@@ -150,6 +151,10 class UserLog(Base, BaseModel):
150 action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
151 action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
151 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
152 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
152
153
154 @property
155 def action_as_day(self):
156 return date(*self.action_date.timetuple()[:3])
157
153 user = relationship('User')
158 user = relationship('User')
154 repository = relationship('Repository')
159 repository = relationship('Repository')
155
160
@@ -17,8 +17,10
17 <h5>${_('Journal')}</h5>
17 <h5>${_('Journal')}</h5>
18 </div>
18 </div>
19 <div>
19 <div>
20 %if c.journal:
20 %if c.journal_day_aggreagate:
21 %for entry in c.journal:
21 %for day,items in c.journal_day_aggreagate:
22 <div style="font-size:20px;padding:10px 5px">${day}</div>
23 % for entry in items:
22 <div style="padding:10px">
24 <div style="padding:10px">
23 <div class="gravatar">
25 <div class="gravatar">
24 <img alt="gravatar" src="${h.gravatar_url(entry.user.email)}"/>
26 <img alt="gravatar" src="${h.gravatar_url(entry.user.email)}"/>
@@ -41,6 +43,7
41 </div>
43 </div>
42 <div style="clear:both;border-bottom:1px dashed #DDD;padding:3px 3px;margin:0px 10px 0px 10px"></div>
44 <div style="clear:both;border-bottom:1px dashed #DDD;padding:3px 3px;margin:0px 10px 0px 10px"></div>
43 %endfor
45 %endfor
46 %endfor
44 %else:
47 %else:
45 ${_('No entries yet')}
48 ${_('No entries yet')}
46 %endif
49 %endif
General Comments 0
You need to be logged in to leave comments. Login now