Mercurial > kallithea
annotate rhodecode/controllers/journal.py @ 1173:f2b5279a5c77 beta
Added tag v1.1.7 for changeset 2ab211e0aecd
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 23 Mar 2011 20:56:05 +0100 |
parents | f3f847712f87 |
children | 8c0a57a4b89b |
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 import logging |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 |
1041
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
29 from sqlalchemy import or_ |
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
30 from sqlalchemy.orm import joinedload, make_transient |
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
31 from webhelpers.paginate import Page |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1041
diff
changeset
|
32 from itertools import groupby |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
793
diff
changeset
|
33 |
1041
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
34 from paste.httpexceptions import HTTPInternalServerError |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
35 from pylons import request, tmpl_context as c, response, url |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
36 from pylons.i18n.translation import _ |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
37 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed |
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
|
38 |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
39 import rhodecode.lib.helpers as h |
793
3025b0f9475e
disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
738
diff
changeset
|
40 from rhodecode.lib.auth import LoginRequired, NotAnonymous |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 from rhodecode.lib.base import BaseController, render |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 from rhodecode.model.db import UserLog, UserFollowing |
861
fd2ea6ceadc8
updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents:
793
diff
changeset
|
43 |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 log = logging.getLogger(__name__) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 class JournalController(BaseController): |
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 |
1120
a8d759613d8f
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal
Marcin Kuzminski <marcin@python-works.com>
parents:
1117
diff
changeset
|
49 |
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__() |
1121
f3f847712f87
replaced all global calls to template context (rhodecode_user), into instance attributes
Marcin Kuzminski <marcin@python-works.com>
parents:
1120
diff
changeset
|
52 self.rhodecode_user = self.rhodecode_user |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
53 self.title = _('%s public journal %s feed') % (c.rhodecode_name, '%s') |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
54 self.language = 'en-us' |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
55 self.ttl = "5" |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
56 self.feed_nr = 20 |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 |
1120
a8d759613d8f
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal
Marcin Kuzminski <marcin@python-works.com>
parents:
1117
diff
changeset
|
58 @LoginRequired() |
1085
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
59 @NotAnonymous() |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 def index(self): |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 # Return a rendered template |
1085
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
62 p = int(request.params.get('page', 1)) |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1041
diff
changeset
|
63 |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 c.following = self.sa.query(UserFollowing)\ |
1117
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1088
diff
changeset
|
65 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\ |
1000
229437211bef
Optimized queries on journal, and added quick stop following action button in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
995
diff
changeset
|
66 .options(joinedload(UserFollowing.follows_repository))\ |
229437211bef
Optimized queries on journal, and added quick stop following action button in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
995
diff
changeset
|
67 .all() |
793
3025b0f9475e
disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents:
738
diff
changeset
|
68 |
1085
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
69 journal = self._get_journal_data(c.following) |
994
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
70 |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1041
diff
changeset
|
71 c.journal_pager = Page(journal, page=p, items_per_page=20) |
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1041
diff
changeset
|
72 |
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
|
73 c.journal_day_aggreagate = self._get_daily_aggregate(c.journal_pager) |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1041
diff
changeset
|
74 |
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
|
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 |
d14723711d17
fixes for journal, added paging now it's possible to view whole journal
Marcin Kuzminski <marcin@python-works.com>
parents:
994
diff
changeset
|
78 return render('journal/journal.html') |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 |
994
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
80 |
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
81 def _get_daily_aggregate(self, journal): |
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
82 groups = [] |
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
83 for k, g in groupby(journal, lambda x:x.action_as_day): |
1041
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
84 user_group = [] |
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
85 for k2, g2 in groupby(list(g), lambda x:x.user.email): |
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
86 l = list(g2) |
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
87 user_group.append((l[0].user, l)) |
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
88 |
98be43b888c4
Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents:
1019
diff
changeset
|
89 groups.append((k, user_group,)) |
994
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
90 |
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
91 return groups |
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
92 |
7f9d23f6a526
Added grouping by days in journal
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
93 |
1085
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
94 def _get_journal_data(self, following_repos): |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
95 repo_ids = [x.follows_repository.repo_id for x in following_repos |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
96 if x.follows_repository is not None] |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
97 user_ids = [x.follows_user.user_id for x in following_repos |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
98 if x.follows_user is not None] |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
99 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
100 filtering_criterion = None |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
101 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
102 if repo_ids and user_ids: |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
103 filtering_criterion = or_(UserLog.repository_id.in_(repo_ids), |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
104 UserLog.user_id.in_(user_ids)) |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
105 if repo_ids and not user_ids: |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
106 filtering_criterion = UserLog.repository_id.in_(repo_ids) |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
107 if not repo_ids and user_ids: |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
108 filtering_criterion = UserLog.user_id.in_(user_ids) |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
109 if filtering_criterion is not None: |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
110 journal = self.sa.query(UserLog)\ |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
111 .options(joinedload(UserLog.user))\ |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
112 .options(joinedload(UserLog.repository))\ |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
113 .filter(filtering_criterion)\ |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
114 .order_by(UserLog.action_date.desc()) |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
115 else: |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
116 journal = [] |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
117 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
118 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
119 return journal |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
120 |
1120
a8d759613d8f
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal
Marcin Kuzminski <marcin@python-works.com>
parents:
1117
diff
changeset
|
121 @LoginRequired() |
1085
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
122 @NotAnonymous() |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
123 def toggle_following(self): |
875 | 124 cur_token = request.POST.get('auth_token') |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
125 token = h.get_token() |
875 | 126 if cur_token == token: |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
127 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
128 user_id = request.POST.get('follows_user_id') |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
129 if user_id: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
130 try: |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1041
diff
changeset
|
131 self.scm_model.toggle_following_user(user_id, |
1117
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1088
diff
changeset
|
132 self.rhodecode_user.user_id) |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
133 return 'ok' |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
134 except: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
135 raise HTTPInternalServerError() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
137 repo_id = request.POST.get('follows_repo_id') |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
138 if repo_id: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
139 try: |
1045
3fc9183e05dd
another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents:
1041
diff
changeset
|
140 self.scm_model.toggle_following_repo(repo_id, |
1117
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1088
diff
changeset
|
141 self.rhodecode_user.user_id) |
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
142 return 'ok' |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
143 except: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
144 raise HTTPInternalServerError() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
145 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
146 |
875 | 147 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
|
148 raise HTTPInternalServerError() |
1085
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
149 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
150 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
151 |
1120
a8d759613d8f
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal
Marcin Kuzminski <marcin@python-works.com>
parents:
1117
diff
changeset
|
152 @LoginRequired() |
1085
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
153 def public_journal(self): |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
154 # Return a rendered template |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
155 p = int(request.params.get('page', 1)) |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
156 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
157 c.following = self.sa.query(UserFollowing)\ |
1117
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1088
diff
changeset
|
158 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\ |
1085
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
159 .options(joinedload(UserFollowing.follows_repository))\ |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
160 .all() |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
161 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
162 journal = self._get_journal_data(c.following) |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
163 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
164 c.journal_pager = Page(journal, page=p, items_per_page=20) |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
165 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
166 c.journal_day_aggreagate = self._get_daily_aggregate(c.journal_pager) |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
167 |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
168 c.journal_data = render('journal/journal_data.html') |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
169 if request.params.get('partial'): |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
170 return c.journal_data |
3fe3285868d1
implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents:
1045
diff
changeset
|
171 return render('journal/public_journal.html') |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
172 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
173 |
1120
a8d759613d8f
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal
Marcin Kuzminski <marcin@python-works.com>
parents:
1117
diff
changeset
|
174 @LoginRequired(api_access=True) |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
175 def public_journal_atom(self): |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
176 """ |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
177 Produce an atom-1.0 feed via feedgenerator module |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
178 """ |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
179 c.following = self.sa.query(UserFollowing)\ |
1117
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1088
diff
changeset
|
180 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\ |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
181 .options(joinedload(UserFollowing.follows_repository))\ |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
182 .all() |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
183 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
184 journal = self._get_journal_data(c.following) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
185 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
186 feed = Atom1Feed(title=self.title % 'atom', |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
187 link=url('public_journal_atom', qualified=True), |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
188 description=_('Public journal'), |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
189 language=self.language, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
190 ttl=self.ttl) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
191 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
192 for entry in journal[:self.feed_nr]: |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
193 #tmpl = h.action_parser(entry)[0] |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
194 action, action_extra = h.action_parser(entry, feed=True) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
195 title = "%s - %s %s" % (entry.user.short_contact, action, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
196 entry.repository.repo_name) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
197 desc = action_extra() |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
198 feed.add_item(title=title, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
199 pubdate=entry.action_date, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
200 link=url('', qualified=True), |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
201 author_email=entry.user.email, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
202 author_name=entry.user.full_contact, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
203 description=desc) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
204 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
205 response.content_type = feed.mime_type |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
206 return feed.writeString('utf-8') |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
207 |
1120
a8d759613d8f
fixed some bugs in api key auth, added access by api key into rss/atom feeds in global journal
Marcin Kuzminski <marcin@python-works.com>
parents:
1117
diff
changeset
|
208 @LoginRequired(api_access=True) |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
209 def public_journal_rss(self): |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
210 """ |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
211 Produce an rss2 feed via feedgenerator module |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
212 """ |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
213 c.following = self.sa.query(UserFollowing)\ |
1117
6eb5bb24a948
Major rewrite of auth objects. Moved parts of filling user data into user model.
Marcin Kuzminski <marcin@python-works.com>
parents:
1088
diff
changeset
|
214 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\ |
1088
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
215 .options(joinedload(UserFollowing.follows_repository))\ |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
216 .all() |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
217 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
218 journal = self._get_journal_data(c.following) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
219 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
220 feed = Rss201rev2Feed(title=self.title % 'rss', |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
221 link=url('public_journal_rss', qualified=True), |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
222 description=_('Public journal'), |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
223 language=self.language, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
224 ttl=self.ttl) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
225 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
226 for entry in journal[:self.feed_nr]: |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
227 #tmpl = h.action_parser(entry)[0] |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
228 action, action_extra = h.action_parser(entry, feed=True) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
229 title = "%s - %s %s" % (entry.user.short_contact, action, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
230 entry.repository.repo_name) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
231 desc = action_extra() |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
232 feed.add_item(title=title, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
233 pubdate=entry.action_date, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
234 link=url('', qualified=True), |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
235 author_email=entry.user.email, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
236 author_name=entry.user.full_contact, |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
237 description=desc) |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
238 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
239 response.content_type = feed.mime_type |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
240 return feed.writeString('utf-8') |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
241 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
242 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
243 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
244 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
245 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
246 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
247 |
fee472613dfa
made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents:
1085
diff
changeset
|
248 |