annotate rhodecode/controllers/journal.py @ 995:d14723711d17 beta

fixes for journal, added paging now it's possible to view whole journal fixed tooltip events for shortlog and journal paging. Moved journal to it's own templates
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 04 Feb 2011 17:36:41 +0100
parents 7f9d23f6a526
children 229437211bef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
1 # -*- coding: utf-8 -*-
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
2 """
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
3 rhodecode.controllers.journal
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
5
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
6 Journal controller for pylons
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
7
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
8 :created_on: Nov 21, 2010
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
9 :author: marcink
902
07a6e8c65526 fixed copyright year to 2011
Marcin Kuzminski <marcin@python-works.com>
parents: 875
diff changeset
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
11 :license: GPLv3, see COPYING for more details.
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
12 """
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # This program is free software; you can redistribute it and/or
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # modify it under the terms of the GNU General Public License
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # as published by the Free Software Foundation; version 2
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # of the License or (at your opinion) any later version of the license.
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 #
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 #
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # along with this program; if not, write to the Free Software
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 # MA 02110-1301, USA.
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
27
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
28 import logging
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
29 from sqlalchemy import or_
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
31 from pylons import request, response, session, tmpl_context as c, url
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
32
995
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
33 from webhelpers.paginate import Page
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
34
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
35 from rhodecode.lib.auth import LoginRequired, NotAnonymous
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 from rhodecode.lib.base import BaseController, render
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from rhodecode.lib.helpers import get_token
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 from rhodecode.model.db import UserLog, UserFollowing
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
39 from rhodecode.model.scm import ScmModel
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
40
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
41 from paste.httpexceptions import HTTPInternalServerError
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43 log = logging.getLogger(__name__)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 class JournalController(BaseController):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 @LoginRequired()
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
49 @NotAnonymous()
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 def __before__(self):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 super(JournalController, self).__before__()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 def index(self):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 # Return a rendered template
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 c.following = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 .filter(UserFollowing.user_id == c.rhodecode_user.user_id).all()
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
58
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
59 repo_ids = [x.follows_repository.repo_id for x in c.following
736
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
60 if x.follows_repository is not None]
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
61 user_ids = [x.follows_user.user_id for x in c.following
736
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
62 if x.follows_user is not None]
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
63
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
64 journal = self.sa.query(UserLog)\
736
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
65 .filter(or_(
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
66 UserLog.repository_id.in_(repo_ids),
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
67 UserLog.user_id.in_(user_ids),
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
68 ))\
995
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
69 .order_by(UserLog.action_date.desc())
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
70
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
71
995
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
72 p = int(request.params.get('page', 1))
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
73 c.journal_pager = Page(journal, page=p, items_per_page=10)
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
74 c.journal_day_aggreagate = self._get_daily_aggregate(c.journal_pager)
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
75 c.journal_data = render('journal/journal_data.html')
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
76 if request.params.get('partial'):
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
77 return c.journal_data
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
78
995
d14723711d17 fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents: 994
diff changeset
79 return render('journal/journal.html')
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80
994
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
81
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
82 def _get_daily_aggregate(self, journal):
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
83 from itertools import groupby
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
84 groups = []
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
85 for k, g in groupby(journal, lambda x:x.action_as_day):
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
86 groups.append((k, list(g),)) # Store group iterator as a list
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
87
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
88 return groups
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
89
7f9d23f6a526 Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
90
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 def toggle_following(self):
875
0765fd5bf668 tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
92 cur_token = request.POST.get('auth_token')
0765fd5bf668 tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
93 token = get_token()
0765fd5bf668 tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
94 if cur_token == token:
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95 scm_model = ScmModel()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97 user_id = request.POST.get('follows_user_id')
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
98 if user_id:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
99 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
100 scm_model.toggle_following_user(user_id,
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
101 c.rhodecode_user.user_id)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
102 return 'ok'
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
103 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
104 raise HTTPInternalServerError()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
105
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
106 repo_id = request.POST.get('follows_repo_id')
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
107 if repo_id:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
108 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
109 scm_model.toggle_following_repo(repo_id,
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
110 c.rhodecode_user.user_id)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
111 return 'ok'
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
112 except:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
113 raise HTTPInternalServerError()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
114
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
115
875
0765fd5bf668 tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
116 log.debug('token mismatch %s vs %s', cur_token, token)
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
117 raise HTTPInternalServerError()