Changeset - 98be43b888c4
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 15 years ago 2011-02-13 03:39:28
marcin@python-works.com
Updated new Journal with users and dates aggregates
4 files changed with 54 insertions and 38 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/journal.py
Show inline comments
 
@@ -15,96 +15,101 @@
 
# as published by the Free Software Foundation; version 2
 
# of the License or (at your opinion) any later version of the license.
 
# 
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# GNU General Public License for more details.
 
# 
 
# You should have received a copy of the GNU General Public License
 
# along with this program; if not, write to the Free Software
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
# MA  02110-1301, USA.
 

	
 
import logging
 
from sqlalchemy import or_
 

	
 
from pylons import request, response, session, tmpl_context as c, url
 
from sqlalchemy import or_
 
from sqlalchemy.orm import joinedload, make_transient
 
from webhelpers.paginate import Page
 

	
 
from webhelpers.paginate import Page
 
from paste.httpexceptions import HTTPInternalServerError
 
from pylons import request, response, session, tmpl_context as c, url
 

	
 
from rhodecode.lib.auth import LoginRequired, NotAnonymous
 
from rhodecode.lib.base import BaseController, render
 
from rhodecode.lib.helpers import get_token
 
from rhodecode.model.db import UserLog, UserFollowing
 
from rhodecode.model.scm import ScmModel
 

	
 
from paste.httpexceptions import HTTPInternalServerError
 
from sqlalchemy.orm import joinedload
 

	
 
log = logging.getLogger(__name__)
 

	
 
class JournalController(BaseController):
 

	
 

	
 
    @LoginRequired()
 
    @NotAnonymous()
 
    def __before__(self):
 
        super(JournalController, self).__before__()
 

	
 
    def index(self):
 
        # Return a rendered template
 

	
 
        c.following = self.sa.query(UserFollowing)\
 
            .filter(UserFollowing.user_id == c.rhodecode_user.user_id)\
 
            .options(joinedload(UserFollowing.follows_repository))\
 
            .all()
 

	
 

	
 
        repo_ids = [x.follows_repository.repo_id for x in c.following
 
                    if x.follows_repository is not None]
 
        user_ids = [x.follows_user.user_id for x in c.following
 
                    if x.follows_user is not None]
 

	
 
        filtering_criterion = None
 

	
 
        if repo_ids and user_ids:
 
            filtering_criterion = or_(UserLog.repository_id.in_(repo_ids),
 
                        UserLog.user_id.in_(user_ids))
 
        if repo_ids and not user_ids:
 
            filtering_criterion = UserLog.repository_id.in_(repo_ids)
 
        if not repo_ids and user_ids:
 
            filtering_criterion = UserLog.user_id.in_(user_ids)
 

	
 
        if filtering_criterion is not None:
 
            journal = self.sa.query(UserLog)\
 
                .options(joinedload(UserLog.user))\
 
                .options(joinedload(UserLog.repository))\
 
                .filter(filtering_criterion)\
 
                .order_by(UserLog.action_date.desc())
 
        else:
 
            journal = []
 

	
 
        p = int(request.params.get('page', 1))
 
        c.journal_pager = Page(journal, page=p, items_per_page=10)
 
        c.journal_day_aggreagate = self._get_daily_aggregate(c.journal_pager)
 
        c.journal_data = render('journal/journal_data.html')
 
        if request.params.get('partial'):
 
            return c.journal_data
 

	
 
        return render('journal/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
 
            user_group = []
 
            for k2, g2 in groupby(list(g), lambda x:x.user.email):
 
                l = list(g2)
 
                user_group.append((l[0].user, l))
 

	
 
            groups.append((k, user_group,))
 

	
 
        return groups
 

	
 

	
 
    def toggle_following(self):
 
        cur_token = request.POST.get('auth_token')
 
        token = get_token()
 
        if cur_token == token:
 
            scm_model = ScmModel()
 

	
 
            user_id = request.POST.get('follows_user_id')
 
            if user_id:
rhodecode/lib/helpers.py
Show inline comments
 
@@ -466,50 +466,51 @@ def action_parser(user_log):
 
            '<a class="show_more" id="_%s" href="#more">%s</a> '
 
            '%s</span>')
 
            cs_links += html_tmpl % (_('and'), uniq_id, _('%s more') \
 
                                        % (len(revs) - revs_limit),
 
                                        _('revisions'))
 

	
 
            html_tmpl = '<span id="%s" style="display:none"> %s </span>'
 
            cs_links += html_tmpl % (uniq_id, ', '.join([link_to(rev,
 
                url('changeset_home',
 
                repo_name=repo_name, revision=rev),
 
                title=message(rev), class_='tooltip')
 
                for rev in revs[revs_limit:revs_top_limit]]))
 
        cs_links += _(' into')
 
        if len(revs) > 1:
 
            cs_links += compare_view
 
        return cs_links
 

	
 
    def get_fork_name():
 
        from rhodecode.model.scm import ScmModel
 
        repo_name = action_params
 
        repo, dbrepo = ScmModel().get(repo_name)
 
        if repo is None:
 
            return repo_name
 
        return link_to(action_params, url('summary_home',
 
                                          repo_name=repo.name,),
 
                                          title=dbrepo.description)
 

	
 
    map = {'user_deleted_repo':(_('User [deleted] repository'), None),
 
           'user_created_repo':(_('User [created] repository'), None),
 
           'user_forked_repo':(_('User [forked] repository as:'), get_fork_name),
 
           'user_updated_repo':(_('User [updated] repository'), None),
 
           'admin_deleted_repo':(_('Admin [delete] repository'), None),
 
           'admin_created_repo':(_('Admin [created] repository'), None),
 
           'admin_forked_repo':(_('Admin [forked] repository'), None),
 
           'admin_updated_repo':(_('Admin [updated] repository'), None),
 
           'push':(_('[Pushed]'), get_cs_links),
 
           'pull':(_('[Pulled]'), None),
 
           'started_following_repo':(_('User [started following] repository'), None),
 
           'stopped_following_repo':(_('User [stopped following] repository'), None),
 
    map = {'user_deleted_repo':(_('[deleted] repository'), None),
 
           'user_created_repo':(_('[created] repository'), None),
 
           'user_forked_repo':(_('[forked] repository as:'), get_fork_name),
 
           'user_updated_repo':(_('[updated] repository'), None),
 
           'admin_deleted_repo':(_('[delete] repository'), None),
 
           'admin_created_repo':(_('[created] repository'), None),
 
           'admin_forked_repo':(_('[forked] repository'), None),
 
           'admin_updated_repo':(_('[updated] repository'), None),
 
           'push':(_('[pushed]'), get_cs_links),
 
           'pull':(_('[pulled]'), None),
 
           'started_following_repo':(_('[started following] repository'), None),
 
           'stopped_following_repo':(_('[stopped following] repository'), None),
 
            }
 

	
 
    action_str = map.get(action, action)
 
    action = action_str[0].replace('[', '<span class="journal_highlight">')\
 
                   .replace(']', '</span>')
 
    if action_str[1] is not None:
 
        action = action + " " + action_str[1]()
 

	
 
    return literal(action)
 

	
 
def action_parser_icon(user_log):
 
    action = user_log.action
rhodecode/public/css/style.css
Show inline comments
 
@@ -1404,48 +1404,61 @@ border-width:1px;
 
padding-top:4px;
 
padding-bottom:4px;
 
}
 
 
#journal .journal_day{
 
font-size:20px;
 
padding:10px 0px;
 
border-bottom:2px solid #DDD;
 
margin-left:10px;
 
margin-right:10px;
 
}
 
 
#journal .journal_action{
 
padding-top:4px;
 
min-height:15px;
 
#journal .journal_user{
 
color: #747474;
 
font-size: 14px;
 
font-weight: bold;
 
height: 30px;
 
}
 
 
#journal .journal_icon{
 
float: left;
 
padding-top: 4px;
 
padding-left:12px;
 
padding-right: 4px;
 
clear: both;
 
}
 
 
#journal .journal_action{
 
padding-top:4px;
 
min-height:2px;
 
float:left
 
}
 
#journal .journal_repo{
 
margin-left: 38px;
 
padding-top: 5px;
 
float: left;
 
margin-left: 6px;
 
padding-top: 3px;
 
}
 
 
#journal .journal_repo .journal_repo_name{
 
font-weight: bold;
 
font-size: 1.1em;
 
}
 
#journal .compare_view{
 
padding: 5px 0px 5px 38px;
 
padding: 5px 0px 5px 3px;
 
width: 95px;
 
}
 
.journal_highlight{
 
font-weight: bold;
 
padding: 0 2px;
 
vertical-align: bottom;
 
}
 
.trending_language_tbl,.trending_language_tbl td {
 
border:0 !important;
 
margin:0 !important;
 
padding:0 !important;
 
}
 
 
.trending_language {
 
background-color:#003367;
 
color:#FFF;
 
display:block;
 
min-width:20px;
 
text-decoration:none;
 
@@ -1892,29 +1905,24 @@ height: 16px;
 
width: 20px;
 
cursor: pointer;
 
display: block;
 
float: right;
 
margin-top: 2px;
 
}
 
 
.currently_following{
 
padding-left: 10px;
 
padding-bottom:5px;
 
}
 
 
.journal_highlight{
 
font-weight: bold;
 
text-decoration: underline;
 
}
 
 
.add_icon {
 
background:url("../images/icons/add.png") no-repeat scroll 3px;
 
height:16px;
 
padding-left:20px;
 
padding-top:1px;
 
text-align:left;
 
}
 
 
.edit_icon {
 
background:url("../images/icons/folder_edit.png") no-repeat scroll 3px;
 
height:16px;
 
padding-left:20px;
rhodecode/templates/journal/journal_data.html
Show inline comments
 
## -*- coding: utf-8 -*-
 

	
 
%if c.journal_day_aggreagate:
 
    %for day,items in c.journal_day_aggreagate:
 
    <div class="journal_day">${day}</div>
 
        % for entry in items:
 
        % for user,entries in items:
 
        <div style="padding:10px">
 
            <div class="gravatar">
 
                <img alt="gravatar" src="${h.gravatar_url(entry.user.email,24)}"/>
 
                <img alt="gravatar" src="${h.gravatar_url(user.email,24)}"/>
 
            </div>
 
            <div>${entry.user.name} ${entry.user.lastname}</div>
 
            <div class="journal_user">${user.name} ${user.lastname}</div>
 
            % for entry in entries:
 
            <div class="journal_icon"> ${h.action_parser_icon(entry)}</div>
 
            <div class="journal_action">${h.action_parser(entry)}</div>
 
            <div class="journal_icon">${h.action_parser_icon(entry)}</div>
 
            <div class="journal_repo">
 
                <span class="journal_repo_name">
 
                %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>
 
            %endfor
 
        </div>
 
        <div style="clear:both;border-bottom:1px dashed #DDD;padding:3px 3px;margin:0px 10px 0px 10px"></div>
 
        %endfor
 
    %endfor
 
    
 
<div class="pagination-wh pagination-left">
 
<script type="text/javascript">
 
  var data_div = 'journal';
 
  YAHOO.util.Event.onDOMReady(function(){
 
    YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('pager_link'),"click",function(){
 
            YAHOO.util.Dom.setStyle(data_div,'opacity','0.3');});});
 
</script>
0 comments (0 inline, 0 general)