Show More
@@ -1,93 +1,94 b'' | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # encoding: utf-8 |
|
3 | 3 | # journal controller for pylons |
|
4 | 4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; version 2 |
|
9 | 9 | # of the License or (at your opinion) any later version of the license. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 | # MA 02110-1301, USA. |
|
20 | 20 | """ |
|
21 | 21 | Created on November 21, 2010 |
|
22 | 22 | journal controller for pylons |
|
23 | 23 | @author: marcink |
|
24 | 24 | """ |
|
25 | 25 | |
|
26 | 26 | from pylons import request, response, session, tmpl_context as c, url |
|
27 | 27 | from pylons.controllers.util import abort, redirect |
|
28 | 28 | from rhodecode.lib.auth import LoginRequired |
|
29 | 29 | from rhodecode.lib.base import BaseController, render |
|
30 | 30 | from rhodecode.lib.helpers import get_token |
|
31 | 31 | from rhodecode.lib.utils import action_logger |
|
32 | 32 | from rhodecode.model.db import UserLog, UserFollowing |
|
33 | 33 | from rhodecode.model.scm import ScmModel |
|
34 | 34 | from sqlalchemy import or_ |
|
35 | 35 | import logging |
|
36 | 36 | from paste.httpexceptions import HTTPInternalServerError, HTTPNotFound |
|
37 | 37 | |
|
38 | 38 | log = logging.getLogger(__name__) |
|
39 | 39 | |
|
40 | 40 | class JournalController(BaseController): |
|
41 | 41 | |
|
42 | 42 | |
|
43 | 43 | @LoginRequired() |
|
44 | 44 | def __before__(self): |
|
45 | 45 | super(JournalController, self).__before__() |
|
46 | 46 | |
|
47 | 47 | def index(self): |
|
48 | 48 | # Return a rendered template |
|
49 | 49 | |
|
50 | 50 | c.following = self.sa.query(UserFollowing)\ |
|
51 | 51 | .filter(UserFollowing.user_id == c.rhodecode_user.user_id).all() |
|
52 | 52 | |
|
53 | 53 | repo_ids = [x.follows_repository.repo_id for x in c.following |
|
54 | 54 | if x.follows_repository is not None] |
|
55 | 55 | user_ids = [x.follows_user.user_id for x in c.following |
|
56 | 56 | if x.follows_user is not None] |
|
57 | 57 | |
|
58 | 58 | c.journal = self.sa.query(UserLog)\ |
|
59 | 59 | .filter(or_( |
|
60 | 60 | UserLog.repository_id.in_(repo_ids), |
|
61 | 61 | UserLog.user_id.in_(user_ids), |
|
62 | 62 | ))\ |
|
63 | 63 | .order_by(UserLog.action_date.desc())\ |
|
64 | .limit(20)\ | |
|
64 | 65 | .all() |
|
65 | 66 | return render('/journal.html') |
|
66 | 67 | |
|
67 | 68 | |
|
68 | 69 | def toggle_following(self): |
|
69 | 70 | |
|
70 | 71 | if request.POST.get('auth_token') == get_token(): |
|
71 | 72 | scm_model = ScmModel() |
|
72 | 73 | |
|
73 | 74 | user_id = request.POST.get('follows_user_id') |
|
74 | 75 | if user_id: |
|
75 | 76 | try: |
|
76 | 77 | scm_model.toggle_following_user(user_id, |
|
77 | 78 | c.rhodecode_user.user_id) |
|
78 | 79 | return 'ok' |
|
79 | 80 | except: |
|
80 | 81 | raise HTTPInternalServerError() |
|
81 | 82 | |
|
82 | 83 | repo_id = request.POST.get('follows_repo_id') |
|
83 | 84 | if repo_id: |
|
84 | 85 | try: |
|
85 | 86 | scm_model.toggle_following_repo(repo_id, |
|
86 | 87 | c.rhodecode_user.user_id) |
|
87 | 88 | return 'ok' |
|
88 | 89 | except: |
|
89 | 90 | raise HTTPInternalServerError() |
|
90 | 91 | |
|
91 | 92 | |
|
92 | 93 | |
|
93 | 94 | raise HTTPInternalServerError() |
General Comments 0
You need to be logged in to leave comments.
Login now