annotate rhodecode/controllers/journal.py @ 1235:d85614773113

fixed broken yui script during one of the merges
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 09 Apr 2011 19:12:43 +0200
parents a3b2b4b4e440
children bf263968da47
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
1 # -*- coding: utf-8 -*-
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
2 """
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
3 rhodecode.controllers.journal
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
5
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
6 Journal controller for pylons
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
7
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
8 :created_on: Nov 21, 2010
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
9 :author: marcink
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
10 :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
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 """
1217
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
13 # This program is free software: you can redistribute it and/or modify
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
14 # it under the terms of the GNU General Public License as published by
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
15 # the Free Software Foundation, either version 3 of the License, or
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
16 # (at your option) any later version.
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
17 #
734
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.
1217
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
22 #
734
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
1217
a3b2b4b4e440 fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1136
diff changeset
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
25
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
26 import logging
1136
93b980ebee55 changes for release 1.1.5
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
27 import traceback
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
28
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
29 from pylons import request, response, session, tmpl_context as c, url
1136
93b980ebee55 changes for release 1.1.5
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
30 from paste.httpexceptions import HTTPInternalServerError, HTTPBadRequest
93b980ebee55 changes for release 1.1.5
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
31
93b980ebee55 changes for release 1.1.5
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
32 from sqlalchemy import or_
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
33
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
34 from rhodecode.lib.auth import LoginRequired, NotAnonymous
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
35 from rhodecode.lib.base import BaseController, render
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36 from rhodecode.lib.helpers import get_token
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 from rhodecode.model.db import UserLog, UserFollowing
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
38 from rhodecode.model.scm import ScmModel
861
fd2ea6ceadc8 updated docs on every controller
Marcin Kuzminski <marcin@python-works.com>
parents: 793
diff changeset
39
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
40 log = logging.getLogger(__name__)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
41
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
42 class JournalController(BaseController):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
43
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 @LoginRequired()
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
46 @NotAnonymous()
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 def __before__(self):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 super(JournalController, self).__before__()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 def index(self):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
51 # Return a rendered template
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
52
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
53 c.following = self.sa.query(UserFollowing)\
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
54 .filter(UserFollowing.user_id == c.rhodecode_user.user_id).all()
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
55
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
56 repo_ids = [x.follows_repository.repo_id for x in c.following
736
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
57 if x.follows_repository is not None]
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
58 user_ids = [x.follows_user.user_id for x in c.following
736
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
59 if x.follows_user is not None]
793
3025b0f9475e disabled journal for anonymous users
Marcin Kuzminski <marcin@python-works.com>
parents: 738
diff changeset
60
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 c.journal = self.sa.query(UserLog)\
736
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
62 .filter(or_(
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
63 UserLog.repository_id.in_(repo_ids),
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
64 UserLog.user_id.in_(user_ids),
ab5c09715127 activated filters for user journal for following users/repos only
Marcin Kuzminski <marcin@python-works.com>
parents: 735
diff changeset
65 ))\
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 .order_by(UserLog.action_date.desc())\
738
ddaddffcb7dc added limit for user journal
Marcin Kuzminski <marcin@python-works.com>
parents: 736
diff changeset
67 .limit(20)\
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
68 .all()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
69 return render('/journal.html')
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
70
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
71 def toggle_following(self):
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
72
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
73 if request.POST.get('auth_token') == get_token():
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
74 scm_model = ScmModel()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
75
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
76 user_id = request.POST.get('follows_user_id')
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
77 if user_id:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
78 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
79 scm_model.toggle_following_user(user_id,
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
80 c.rhodecode_user.user_id)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
81 return 'ok'
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
82 except:
1136
93b980ebee55 changes for release 1.1.5
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
83 log.error(traceback.format_exc())
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
84 raise HTTPInternalServerError()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
85
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
86 repo_id = request.POST.get('follows_repo_id')
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
87 if repo_id:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
88 try:
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
89 scm_model.toggle_following_repo(repo_id,
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
90 c.rhodecode_user.user_id)
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
91 return 'ok'
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
92 except:
1136
93b980ebee55 changes for release 1.1.5
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
93 log.error(traceback.format_exc())
734
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
94 raise HTTPInternalServerError()
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
95
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
96
49eb69d78988 implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
97
1136
93b980ebee55 changes for release 1.1.5
Marcin Kuzminski <marcin@python-works.com>
parents: 861
diff changeset
98 raise HTTPBadRequest()