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