# -*- coding: utf-8 -*-""" rhodecode.controllers.journal ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Journal controller for pylons :created_on: Nov 21, 2010 :author: marcink :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> :license: GPLv3, see COPYING for more details."""# This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; version 2# of the License or (at your opinion) any later version of the license.# # This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# # You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,# MA 02110-1301, USA.importloggingfromsqlalchemyimportor_frompylonsimportrequest,response,session,tmpl_contextasc,urlfromrhodecode.lib.authimportLoginRequired,NotAnonymousfromrhodecode.lib.baseimportBaseController,renderfromrhodecode.lib.helpersimportget_tokenfromrhodecode.model.dbimportUserLog,UserFollowingfromrhodecode.model.scmimportScmModelfrompaste.httpexceptionsimportHTTPInternalServerErrorlog=logging.getLogger(__name__)classJournalController(BaseController):@LoginRequired()@NotAnonymous()def__before__(self):super(JournalController,self).__before__()defindex(self):# Return a rendered templatec.following=self.sa.query(UserFollowing)\
.filter(UserFollowing.user_id==c.rhodecode_user.user_id).all()repo_ids=[x.follows_repository.repo_idforxinc.followingifx.follows_repositoryisnotNone]user_ids=[x.follows_user.user_idforxinc.followingifx.follows_userisnotNone]c.journal=self.sa.query(UserLog)\
.filter(or_(UserLog.repository_id.in_(repo_ids),UserLog.user_id.in_(user_ids),))\
.order_by(UserLog.action_date.desc())\
.limit(20)\
.all()returnrender('/journal.html')deftoggle_following(self):ifrequest.POST.get('auth_token')==get_token():scm_model=ScmModel()user_id=request.POST.get('follows_user_id')ifuser_id:try:scm_model.toggle_following_user(user_id,c.rhodecode_user.user_id)return'ok'except:raiseHTTPInternalServerError()repo_id=request.POST.get('follows_repo_id')ifrepo_id:try:scm_model.toggle_following_repo(repo_id,c.rhodecode_user.user_id)return'ok'except:raiseHTTPInternalServerError()raiseHTTPInternalServerError()