Mercurial > kallithea
annotate rhodecode/controllers/journal.py @ 734:49eb69d78988 beta
implemented user dashboards, and following system.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 22 Nov 2010 03:57:47 +0100 |
parents | |
children | dbec976d9975 |
rev | line source |
---|---|
734
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
2 # encoding: utf-8 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
3 # journal controller for pylons |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
5 # |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
6 # 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
|
7 # 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
|
8 # 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
|
9 # 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
|
10 # |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
11 # 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
|
12 # 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
|
13 # 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
|
14 # GNU General Public License for more details. |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 # |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 # 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
|
17 # 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
|
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
19 # MA 02110-1301, USA. |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 """ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 Created on November 21, 2010 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
22 journal controller for pylons |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 @author: marcink |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
24 """ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
25 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
26 from pylons import request, response, session, tmpl_context as c, url |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
27 from pylons.controllers.util import abort, redirect |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 from rhodecode.lib.auth import LoginRequired |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
29 from rhodecode.lib.base import BaseController, render |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
30 from rhodecode.lib.helpers import get_token |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
31 from rhodecode.model.db import UserLog, UserFollowing |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
32 from rhodecode.model.scm import ScmModel |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
33 import logging |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 from paste.httpexceptions import HTTPInternalServerError, HTTPNotFound |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
36 log = logging.getLogger(__name__) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 class JournalController(BaseController): |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 @LoginRequired() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 def __before__(self): |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 super(JournalController, self).__before__() |
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 def index(self): |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 # Return a rendered template |
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 c.following = self.sa.query(UserFollowing)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 .filter(UserFollowing.user_id == c.rhodecode_user.user_id).all() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 c.journal = self.sa.query(UserLog)\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 .order_by(UserLog.action_date.desc())\ |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 .all() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 return render('/journal.html') |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 def toggle_following(self): |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 print c.rhodecode_user |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 if request.POST.get('auth_token') == get_token(): |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
62 scm_model = ScmModel() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
63 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
64 user_id = request.POST.get('follows_user_id') |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
65 if user_id: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
66 try: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
67 scm_model.toggle_following_user(user_id, |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
68 c.rhodecode_user.user_id) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
69 return 'ok' |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
70 except: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
71 raise HTTPInternalServerError() |
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 repo_id = request.POST.get('follows_repo_id') |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
74 if repo_id: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
75 try: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
76 scm_model.toggle_following_repo(repo_id, |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
77 c.rhodecode_user.user_id) |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
78 return 'ok' |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
79 except: |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
80 raise HTTPInternalServerError() |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
81 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
82 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
83 |
49eb69d78988
implemented user dashboards, and following system.
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
84 raise HTTPInternalServerError() |