##// END OF EJS Templates
Added grouping by days in journal
marcink -
r994:7f9d23f6 beta
parent child Browse files
Show More
@@ -33,6 +33,7 b' from pylons import request, response, se'
33 33 from rhodecode.lib.auth import LoginRequired, NotAnonymous
34 34 from rhodecode.lib.base import BaseController, render
35 35 from rhodecode.lib.helpers import get_token
36 from rhodecode.lib.utils import OrderedDict
36 37 from rhodecode.model.db import UserLog, UserFollowing
37 38 from rhodecode.model.scm import ScmModel
38 39
@@ -59,16 +60,29 b' class JournalController(BaseController):'
59 60 user_ids = [x.follows_user.user_id for x in c.following
60 61 if x.follows_user is not None]
61 62
62 c.journal = self.sa.query(UserLog)\
63 journal = self.sa.query(UserLog)\
63 64 .filter(or_(
64 65 UserLog.repository_id.in_(repo_ids),
65 66 UserLog.user_id.in_(user_ids),
66 67 ))\
67 68 .order_by(UserLog.action_date.desc())\
68 .limit(20)\
69 .limit(30)\
69 70 .all()
71
72 c.journal_day_aggreagate = self._get_daily_aggregate(journal)
73
70 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 86 def toggle_following(self):
73 87 cur_token = request.POST.get('auth_token')
74 88 token = get_token()
@@ -26,6 +26,7 b''
26 26 # MA 02110-1301, USA.
27 27 import logging
28 28 import datetime
29 from datetime import date
29 30
30 31 from sqlalchemy import *
31 32 from sqlalchemy.exc import DatabaseError
@@ -150,6 +151,10 b' class UserLog(Base, BaseModel):'
150 151 action = Column("action", String(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
151 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 158 user = relationship('User')
154 159 repository = relationship('Repository')
155 160
@@ -17,29 +17,32 b''
17 17 <h5>${_('Journal')}</h5>
18 18 </div>
19 19 <div>
20 %if c.journal:
21 %for entry in c.journal:
22 <div style="padding:10px">
23 <div class="gravatar">
24 <img alt="gravatar" src="${h.gravatar_url(entry.user.email)}"/>
25 </div>
26 <div>${entry.user.name} ${entry.user.lastname}</div>
27 <div style="padding-left: 45px;padding-top:5px;min-height:20px">${h.action_parser(entry)}</div>
28 <div style="float: left; padding-top: 8px;padding-left:18px">
29 ${h.action_parser_icon(entry)}
30 </div>
31 <div style="margin-left: 45px;padding-top: 10px">
32 <span style="font-weight: bold;font-size: 1.1em">
33 %if entry.repository:
34 ${h.link_to(entry.repository.repo_name,
35 h.url('summary_home',repo_name=entry.repository.repo_name))}
36 %else:
37 ${entry.repository_name}
38 %endif
39 </span> - <span title="${entry.action_date}">${h.age(entry.action_date)}</span>
40 </div>
41 </div>
42 <div style="clear:both;border-bottom:1px dashed #DDD;padding:3px 3px;margin:0px 10px 0px 10px"></div>
20 %if c.journal_day_aggreagate:
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:
24 <div style="padding:10px">
25 <div class="gravatar">
26 <img alt="gravatar" src="${h.gravatar_url(entry.user.email)}"/>
27 </div>
28 <div>${entry.user.name} ${entry.user.lastname}</div>
29 <div style="padding-left: 45px;padding-top:5px;min-height:20px">${h.action_parser(entry)}</div>
30 <div style="float: left; padding-top: 8px;padding-left:18px">
31 ${h.action_parser_icon(entry)}
32 </div>
33 <div style="margin-left: 45px;padding-top: 10px">
34 <span style="font-weight: bold;font-size: 1.1em">
35 %if entry.repository:
36 ${h.link_to(entry.repository.repo_name,
37 h.url('summary_home',repo_name=entry.repository.repo_name))}
38 %else:
39 ${entry.repository_name}
40 %endif
41 </span> - <span title="${entry.action_date}">${h.age(entry.action_date)}</span>
42 </div>
43 </div>
44 <div style="clear:both;border-bottom:1px dashed #DDD;padding:3px 3px;margin:0px 10px 0px 10px"></div>
45 %endfor
43 46 %endfor
44 47 %else:
45 48 ${_('No entries yet')}
General Comments 0
You need to be logged in to leave comments. Login now