annotate rhodecode/controllers/journal.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl

old style: show the full link box on summary page - no overlap or truncation
author Mads Kiilerich <madski@unity3d.com>
date Wed, 02 Jul 2014 19:03:23 -0400
parents ffd45b185016
children 7e5f8c12a3fc
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 -*-
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
2 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
3 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
5 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
6 #
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
7 # 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
8 # 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
9 # 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
10 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1175
diff changeset
11 #
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
12 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
14 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
15 rhodecode.controllers.journal
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
18 Journal controller for pylons
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
20 :created_on: Nov 21, 2010
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
22 :copyright: (c) 2013 RhodeCode GmbH.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
23 :license: GPLv3, see LICENSE for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
24
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
25 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
26
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
27 import logging
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1421
diff changeset
28 from itertools import groupby
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29
1041
98be43b888c4 Updated new Journal with users and dates aggregates
Marcin Kuzminski <marcin@python-works.com>
parents: 1019
diff changeset
30 from sqlalchemy import or_
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1421
diff changeset
31 from sqlalchemy.orm import joinedload
3154
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
32 from sqlalchemy.sql.expression import func
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
33
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1421
diff changeset
34 from webhelpers.feedgenerator import Atom1Feed, Rss201rev2Feed
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
35
2242
87e9718ab4a2 Use webob exception as often as possible
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
36 from webob.exc import HTTPBadRequest
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
37 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
38 from pylons.i18n.translation import _
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
39
3776
13241a4075e9 Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents: 3749
diff changeset
40 from rhodecode.controllers.admin.admin import _journal_filter
13241a4075e9 Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents: 3749
diff changeset
41 from rhodecode.model.db import UserLog, UserFollowing, Repository, User
13241a4075e9 Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents: 3749
diff changeset
42 from rhodecode.model.meta import Session
13241a4075e9 Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents: 3749
diff changeset
43 from rhodecode.model.repo import RepoModel
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
44 import rhodecode.lib.helpers as h
3776
13241a4075e9 Unified the paginators for pylons and YUI.
Marcin Kuzminski <marcin@python-works.com>
parents: 3749
diff changeset
45 from rhodecode.lib.helpers import Page
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
46 from rhodecode.lib.auth import LoginRequired, NotAnonymous
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 from rhodecode.lib.base import BaseController, render
3075
25029d6f4b47 fixed issue with public journal rss/atom feeds after journal filter implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3070
diff changeset
48 from rhodecode.lib.utils2 import safe_int, AttributeDict
3154
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
49 from rhodecode.lib.compat import json
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
50
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 log = logging.getLogger(__name__)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
53
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 class JournalController(BaseController):
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 def __before__(self):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
57 super(JournalController, self).__before__()
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
58 self.language = 'en-us'
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
59 self.ttl = "5"
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
60 self.feed_nr = 20
3075
25029d6f4b47 fixed issue with public journal rss/atom feeds after journal filter implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 3070
diff changeset
61 c.search_term = request.GET.get('filter')
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62
3749
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
63 def _get_daily_aggregate(self, journal):
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
64 groups = []
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
65 for k, g in groupby(journal, lambda x: x.action_as_day):
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
66 user_group = []
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
67 #groupby username if it's a present value, else fallback to journal username
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
68 for _, g2 in groupby(list(g), lambda x: x.user.username if x.user else x.username):
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
69 l = list(g2)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
70 user_group.append((l[0].user, l))
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
71
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
72 groups.append((k, user_group,))
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
73
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
74 return groups
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
75
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
76 def _get_journal_data(self, following_repos):
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
77 repo_ids = [x.follows_repository.repo_id for x in following_repos
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
78 if x.follows_repository is not None]
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
79 user_ids = [x.follows_user.user_id for x in following_repos
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
80 if x.follows_user is not None]
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
81
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
82 filtering_criterion = None
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
83
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
84 if repo_ids and user_ids:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
85 filtering_criterion = or_(UserLog.repository_id.in_(repo_ids),
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
86 UserLog.user_id.in_(user_ids))
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
87 if repo_ids and not user_ids:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
88 filtering_criterion = UserLog.repository_id.in_(repo_ids)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
89 if not repo_ids and user_ids:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
90 filtering_criterion = UserLog.user_id.in_(user_ids)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
91 if filtering_criterion is not None:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
92 journal = self.sa.query(UserLog)\
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
93 .options(joinedload(UserLog.user))\
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
94 .options(joinedload(UserLog.repository))
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
95 #filter
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
96 try:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
97 journal = _journal_filter(journal, c.search_term)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
98 except Exception:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
99 # we want this to crash for now
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
100 raise
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
101 journal = journal.filter(filtering_criterion)\
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
102 .order_by(UserLog.action_date.desc())
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
103 else:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
104 journal = []
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
105
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
106 return journal
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
107
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
108 def _atom_feed(self, repos, public=True):
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
109 journal = self._get_journal_data(repos)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
110 if public:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
111 _link = url('public_journal_atom', qualified=True)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
112 _desc = '%s %s %s' % (c.rhodecode_name, _('public journal'),
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
113 'atom feed')
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
114 else:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
115 _link = url('journal_atom', qualified=True)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
116 _desc = '%s %s %s' % (c.rhodecode_name, _('journal'), 'atom feed')
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
117
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
118 feed = Atom1Feed(title=_desc,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
119 link=_link,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
120 description=_desc,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
121 language=self.language,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
122 ttl=self.ttl)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
123
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
124 for entry in journal[:self.feed_nr]:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
125 user = entry.user
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
126 if user is None:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
127 #fix deleted users
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
128 user = AttributeDict({'short_contact': entry.username,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
129 'email': '',
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
130 'full_contact': ''})
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
131 action, action_extra, ico = h.action_parser(entry, feed=True)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
132 title = "%s - %s %s" % (user.short_contact, action(),
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
133 entry.repository.repo_name)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
134 desc = action_extra()
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
135 _url = None
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
136 if entry.repository is not None:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
137 _url = url('changelog_home',
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
138 repo_name=entry.repository.repo_name,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
139 qualified=True)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
140
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
141 feed.add_item(title=title,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
142 pubdate=entry.action_date,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
143 link=_url or url('', qualified=True),
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
144 author_email=user.email,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
145 author_name=user.full_contact,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
146 description=desc)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
147
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
148 response.content_type = feed.mime_type
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
149 return feed.writeString('utf-8')
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
150
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
151 def _rss_feed(self, repos, public=True):
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
152 journal = self._get_journal_data(repos)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
153 if public:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
154 _link = url('public_journal_atom', qualified=True)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
155 _desc = '%s %s %s' % (c.rhodecode_name, _('public journal'),
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
156 'rss feed')
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
157 else:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
158 _link = url('journal_atom', qualified=True)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
159 _desc = '%s %s %s' % (c.rhodecode_name, _('journal'), 'rss feed')
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
160
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
161 feed = Rss201rev2Feed(title=_desc,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
162 link=_link,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
163 description=_desc,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
164 language=self.language,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
165 ttl=self.ttl)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
166
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
167 for entry in journal[:self.feed_nr]:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
168 user = entry.user
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
169 if user is None:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
170 #fix deleted users
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
171 user = AttributeDict({'short_contact': entry.username,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
172 'email': '',
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
173 'full_contact': ''})
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
174 action, action_extra, ico = h.action_parser(entry, feed=True)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
175 title = "%s - %s %s" % (user.short_contact, action(),
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
176 entry.repository.repo_name)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
177 desc = action_extra()
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
178 _url = None
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
179 if entry.repository is not None:
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
180 _url = url('changelog_home',
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
181 repo_name=entry.repository.repo_name,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
182 qualified=True)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
183
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
184 feed.add_item(title=title,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
185 pubdate=entry.action_date,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
186 link=_url or url('', qualified=True),
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
187 author_email=user.email,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
188 author_name=user.full_contact,
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
189 description=desc)
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
190
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
191 response.content_type = feed.mime_type
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
192 return feed.writeString('utf-8')
b950b884ab87 auth decorators are not used anymore on __before__
Marcin Kuzminski <marcin@python-works.com>
parents: 3748
diff changeset
193
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
194 @LoginRequired()
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
195 @NotAnonymous()
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
196 def index(self):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
197 # Return a rendered template
3748
9d743ca9cede usage of request.GET is now more consistent
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
198 p = safe_int(request.GET.get('page', 1), 1)
1741
fcbc35ecb024 personal Journal UI
Marcin Kuzminski <marcin@python-works.com>
parents: 1722
diff changeset
199 c.user = User.get(self.rhodecode_user.user_id)
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
200 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
201 .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
202 .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
203 .all()
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
204
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
205 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
206
3070
cc7eedb5323c final implementation of #210 journal filtering.
Marcin Kuzminski <marcin@python-works.com>
parents: 3068
diff changeset
207 def url_generator(**kw):
cc7eedb5323c final implementation of #210 journal filtering.
Marcin Kuzminski <marcin@python-works.com>
parents: 3068
diff changeset
208 return url.current(filter=c.search_term, **kw)
cc7eedb5323c final implementation of #210 journal filtering.
Marcin Kuzminski <marcin@python-works.com>
parents: 3068
diff changeset
209
cc7eedb5323c final implementation of #210 journal filtering.
Marcin Kuzminski <marcin@python-works.com>
parents: 3068
diff changeset
210 c.journal_pager = Page(journal, page=p, items_per_page=20, url=url_generator)
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
211 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
212
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
213 c.journal_data = render('journal/journal_data.html')
1421
c6b811f11c94 Javascripts rewrite: updated yui to latest 2.9, simplified ajax loading for multiple pages. Removed YUI dev package
Marcin Kuzminski <marcin@python-works.com>
parents: 1212
diff changeset
214 if request.environ.get('HTTP_X_PARTIAL_XHR'):
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
215 return c.journal_data
3154
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
216
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
217 repos_list = Session().query(Repository)\
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
218 .filter(Repository.user_id ==
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
219 self.rhodecode_user.user_id)\
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
220 .order_by(func.lower(Repository.repo_name)).all()
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
221
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
222 repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list,
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
223 admin=True)
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
224 #json used to render the grid
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
225 c.data = json.dumps(repos_data)
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
226
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
227 watched_repos_data = []
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
228
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
229 ## watched repos
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
230 _render = RepoModel._render_datatable
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
231
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
232 def quick_menu(repo_name):
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
233 return _render('quick_menu', repo_name)
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
234
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
235 def repo_lnk(name, rtype, rstate, private, fork_of):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
236 return _render('repo_name', name, rtype, rstate, private, fork_of,
3154
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
237 short_name=False, admin=False)
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
238
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
239 def last_rev(repo_name, cs_cache):
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
240 return _render('revision', repo_name, cs_cache.get('revision'),
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
241 cs_cache.get('raw_id'), cs_cache.get('author'),
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
242 cs_cache.get('message'))
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
243
3154
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
244 def desc(desc):
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
245 from pylons import tmpl_context as c
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
246 if c.visual.stylify_metatags:
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
247 return h.urlify_text(h.desc_stylize(h.truncate(desc, 60)))
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
248 else:
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
249 return h.urlify_text(h.truncate(desc, 60))
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
250
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
251 def repo_actions(repo_name):
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
252 return _render('repo_actions', repo_name)
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
253
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
254 def owner_actions(user_id, username):
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
255 return _render('user_name', user_id, username)
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
256
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
257 def toogle_follow(repo_id):
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
258 return _render('toggle_follow', repo_id)
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
259
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
260 for entry in c.following:
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
261 repo = entry.follows_repository
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
262 cs_cache = repo.changeset_cache
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
263 row = {
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
264 "menu": quick_menu(repo.repo_name),
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
265 "raw_name": repo.repo_name.lower(),
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
266 "name": repo_lnk(repo.repo_name, repo.repo_type,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
267 repo.repo_state, repo.private, repo.fork),
3154
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
268 "last_changeset": last_rev(repo.repo_name, cs_cache),
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
269 "last_rev_raw": cs_cache.get('revision'),
3154
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
270 "action": toogle_follow(repo.repo_id)
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
271 }
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
272
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
273 watched_repos_data.append(row)
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
274
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
275 c.watched_data = json.dumps({
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
276 "totalRecords": len(c.following),
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
277 "startIndex": 0,
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
278 "sort": "name",
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
279 "dir": "asc",
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
280 "records": watched_repos_data
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
281 })
0226b6d6b2b5 Use common function for generation of grid data
Marcin Kuzminski <marcin@python-works.com>
parents: 3075
diff changeset
282 return render('journal/journal.html')
2951
301773d07012 Lazy loading on my journal page
Marcin Kuzminski <marcin@python-works.com>
parents: 2845
diff changeset
283
2397
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
284 @LoginRequired(api_access=True)
2410
a1595b6e1445 Add API access to personal journal, and forbid anonymous access on them
Marcin Kuzminski <marcin@python-works.com>
parents: 2397
diff changeset
285 @NotAnonymous()
2397
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
286 def journal_atom(self):
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
287 """
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
288 Produce an atom-1.0 feed via feedgenerator module
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
289 """
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
290 following = self.sa.query(UserFollowing)\
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
291 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
292 .options(joinedload(UserFollowing.follows_repository))\
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
293 .all()
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
294 return self._atom_feed(following, public=False)
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
295
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
296 @LoginRequired(api_access=True)
2410
a1595b6e1445 Add API access to personal journal, and forbid anonymous access on them
Marcin Kuzminski <marcin@python-works.com>
parents: 2397
diff changeset
297 @NotAnonymous()
2397
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
298 def journal_rss(self):
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
299 """
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
300 Produce an rss feed via feedgenerator module
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
301 """
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
302 following = self.sa.query(UserFollowing)\
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
303 .filter(UserFollowing.user_id == self.rhodecode_user.user_id)\
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
304 .options(joinedload(UserFollowing.follows_repository))\
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
305 .all()
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
306 return self._rss_feed(following, public=False)
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
307
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
308 @LoginRequired()
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
309 @NotAnonymous()
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
310 def toggle_following(self):
875
0765fd5bf668 tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
311 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
312 token = h.get_token()
875
0765fd5bf668 tests update
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
313 if cur_token == token:
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
314
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
315 user_id = request.POST.get('follows_user_id')
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
316 if user_id:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
317 try:
1045
3fc9183e05dd another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents: 1041
diff changeset
318 self.scm_model.toggle_following_user(user_id,
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
319 self.rhodecode_user.user_id)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1741
diff changeset
320 Session.commit()
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
321 return 'ok'
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 3154
diff changeset
322 except Exception:
1175
8c0a57a4b89b Journal Should not return 500 errors on failure, rather better is to return bad request error
Marcin Kuzminski <marcin@python-works.com>
parents: 1121
diff changeset
323 raise HTTPBadRequest()
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
324
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
325 repo_id = request.POST.get('follows_repo_id')
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
326 if repo_id:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
327 try:
1045
3fc9183e05dd another major codes rewrite:
Marcin Kuzminski <marcin@python-works.com>
parents: 1041
diff changeset
328 self.scm_model.toggle_following_repo(repo_id,
1212
50e41777675d pep8ify
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
329 self.rhodecode_user.user_id)
1749
8ecc6b8229a5 commit less models
Marcin Kuzminski <marcin@python-works.com>
parents: 1741
diff changeset
330 Session.commit()
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
331 return 'ok'
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 3154
diff changeset
332 except Exception:
1175
8c0a57a4b89b Journal Should not return 500 errors on failure, rather better is to return bad request error
Marcin Kuzminski <marcin@python-works.com>
parents: 1121
diff changeset
333 raise HTTPBadRequest()
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
334
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
335 log.debug('token mismatch %s vs %s' % (cur_token, token))
1175
8c0a57a4b89b Journal Should not return 500 errors on failure, rather better is to return bad request error
Marcin Kuzminski <marcin@python-works.com>
parents: 1121
diff changeset
336 raise HTTPBadRequest()
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
337
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
338 @LoginRequired()
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
339 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
340 # Return a rendered template
3748
9d743ca9cede usage of request.GET is now more consistent
Marcin Kuzminski <marcin@python-works.com>
parents: 3631
diff changeset
341 p = safe_int(request.GET.get('page', 1), 1)
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
342
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
343 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
344 .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
345 .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
346 .all()
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
347
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
348 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
349
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
350 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
351
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
352 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
353
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
354 c.journal_data = render('journal/journal_data.html')
1421
c6b811f11c94 Javascripts rewrite: updated yui to latest 2.9, simplified ajax loading for multiple pages. Removed YUI dev package
Marcin Kuzminski <marcin@python-works.com>
parents: 1212
diff changeset
355 if request.environ.get('HTTP_X_PARTIAL_XHR'):
1085
3fe3285868d1 implemented public journal for anonymous users, admin can control which repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1045
diff changeset
356 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
357 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
358
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
359 @LoginRequired(api_access=True)
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
360 def public_journal_atom(self):
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
361 """
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
362 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
363 """
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
364 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
365 .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
366 .options(joinedload(UserFollowing.follows_repository))\
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
367 .all()
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
368
2397
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
369 return self._atom_feed(c.following)
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
370
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
371 @LoginRequired(api_access=True)
1088
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
372 def public_journal_rss(self):
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
373 """
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
374 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
375 """
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
376 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
377 .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
378 .options(joinedload(UserFollowing.follows_repository))\
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
379 .all()
fee472613dfa made simple global rss and atom feed
Marcin Kuzminski <marcin@python-works.com>
parents: 1085
diff changeset
380
2397
d815d617eb5e added rss/atom feeds into personalized journal
Marcin Kuzminski <marcin@python-works.com>
parents: 2390
diff changeset
381 return self._rss_feed(c.following)