2014-02-21 13:16:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2013-Today OpenERP SA (<http://www.openerp.com>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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 Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2014-02-22 17:37:59 +00:00
|
|
|
import werkzeug.urls
|
|
|
|
|
|
|
|
from openerp import tools
|
2014-02-21 13:16:08 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
|
|
|
from openerp.addons.web import http
|
|
|
|
|
2014-02-22 17:37:59 +00:00
|
|
|
from openerp.tools.translate import _
|
2014-02-21 13:16:08 +00:00
|
|
|
from datetime import datetime, timedelta
|
2014-02-22 17:37:59 +00:00
|
|
|
from openerp.addons.web.http import request
|
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
from dateutil.relativedelta import relativedelta
|
2014-02-22 17:37:59 +00:00
|
|
|
from openerp.addons.website.controllers.main import Website as controllers
|
2014-03-04 12:53:50 +00:00
|
|
|
from openerp.addons.website.models.website import slug
|
2014-02-22 17:37:59 +00:00
|
|
|
|
|
|
|
controllers = controllers()
|
2014-02-21 13:16:08 +00:00
|
|
|
|
|
|
|
class website_forum(http.Controller):
|
2014-03-04 10:49:30 +00:00
|
|
|
|
|
|
|
@http.route(['/forum/'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def forum(self, **searches):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-04 12:40:02 +00:00
|
|
|
Forum = request.registry['website.forum']
|
|
|
|
obj_ids = Forum.search(cr, uid, [], context=context)
|
|
|
|
forum_ids = Forum.browse(cr, uid, obj_ids, context=context)
|
2014-03-04 10:49:30 +00:00
|
|
|
|
|
|
|
values = {
|
|
|
|
'forum_ids': forum_ids,
|
|
|
|
'searches': {},
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.forum_index", values)
|
|
|
|
|
2014-03-04 12:40:02 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/view'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def view_forum(self, forum, **searches):
|
2014-03-07 11:03:29 +00:00
|
|
|
return request.website.render("website_forum.forum", {'forum': forum })
|
2014-03-04 12:40:02 +00:00
|
|
|
|
|
|
|
@http.route('/forum/add_forum/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def add_forum(self, forum_name="New Forum", **kwargs):
|
2014-03-07 11:03:29 +00:00
|
|
|
forum_id = request.registry['website.forum'].create(request.cr, request.uid, {
|
2014-03-04 12:40:02 +00:00
|
|
|
'name': forum_name,
|
|
|
|
'faq': 'F.A.Q'
|
2014-03-07 11:03:29 +00:00
|
|
|
}, context=request.context)
|
2014-03-04 12:40:02 +00:00
|
|
|
return request.redirect("/forum/%s/view/?enable_editor=1" % forum_id)
|
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/', '/forum/<model("website.forum"):forum>/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def questions(self, forum, page=1, **searches):
|
2014-02-21 13:16:08 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-07 11:03:29 +00:00
|
|
|
Forum = request.registry['website.forum.post']
|
2014-03-04 12:40:02 +00:00
|
|
|
domain = [('forum_id', '=', forum.id), ('parent_id', '=', False)]
|
2014-03-05 13:07:24 +00:00
|
|
|
|
2014-03-07 11:03:29 +00:00
|
|
|
search = searches.get('search',False)
|
2014-02-25 07:23:56 +00:00
|
|
|
if search:
|
|
|
|
domain += ['|',
|
|
|
|
('name', 'ilike', search),
|
|
|
|
('content', 'ilike', search)]
|
2014-03-07 11:03:29 +00:00
|
|
|
|
|
|
|
type = searches.get('type',False)
|
|
|
|
if not type:
|
|
|
|
searches['type'] = 'all'
|
2014-03-03 06:28:18 +00:00
|
|
|
if type == 'unanswered':
|
|
|
|
domain += [ ('child_ids', '=', False) ]
|
|
|
|
#TODO: update domain to show followed questions of user
|
|
|
|
if type == 'followed':
|
2014-03-07 11:03:29 +00:00
|
|
|
domain += [ ('create_uid', '=', uid) ]
|
2014-02-24 07:02:06 +00:00
|
|
|
|
2014-03-07 12:38:55 +00:00
|
|
|
step = 10
|
2014-03-07 11:03:29 +00:00
|
|
|
question_count = Forum.search(cr, uid, domain, count=True, context=context)
|
2014-03-07 12:38:55 +00:00
|
|
|
pager = request.website.pager(url="/forum/%s/" % slug(forum), total=question_count, page=page, step=step, scope=10)
|
2014-02-24 07:02:06 +00:00
|
|
|
|
2014-03-07 11:03:29 +00:00
|
|
|
obj_ids = Forum.search(cr, uid, domain, limit=step, offset=pager['offset'], context=context)
|
|
|
|
question_ids = Forum.browse(cr, uid, obj_ids, context=context)
|
2014-03-03 06:28:18 +00:00
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
values = {
|
2014-02-24 12:36:44 +00:00
|
|
|
'total_questions': question_count,
|
2014-02-21 13:16:08 +00:00
|
|
|
'question_ids': question_ids,
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum': forum,
|
2014-02-21 13:16:08 +00:00
|
|
|
'pager': pager,
|
|
|
|
'searches': searches,
|
|
|
|
}
|
|
|
|
|
|
|
|
return request.website.render("website_forum.index", values)
|
|
|
|
|
2014-03-03 19:36:54 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/faq'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def faq(self, forum, **post):
|
|
|
|
values = { 'searches': {}, 'forum':forum }
|
|
|
|
return request.website.render("website_forum.faq", values)
|
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/ask'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def question_ask(self, forum, **post):
|
2014-03-07 11:03:29 +00:00
|
|
|
values = { 'searches': {}, 'forum': forum }
|
2014-03-03 19:17:48 +00:00
|
|
|
return request.website.render("website_forum.ask_question", values)
|
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):question>/page/<page:page>'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def question(self, forum, question, page, **post):
|
2014-02-21 13:16:08 +00:00
|
|
|
values = {
|
|
|
|
'question': question,
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum': forum
|
2014-02-21 13:16:08 +00:00
|
|
|
}
|
|
|
|
return request.website.render(page, values)
|
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):question>'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def open_question(self, forum, question, **post):
|
2014-02-27 12:57:01 +00:00
|
|
|
answer_done = False
|
|
|
|
for answer in question.child_ids:
|
|
|
|
if answer.create_uid.id == request.uid:
|
|
|
|
answer_done = True
|
2014-02-24 07:02:06 +00:00
|
|
|
values = {
|
|
|
|
'question': question,
|
2014-02-27 12:57:01 +00:00
|
|
|
'searches': post,
|
2014-03-04 10:49:30 +00:00
|
|
|
'answer_done': answer_done,
|
|
|
|
'forum': forum,
|
2014-02-24 07:02:06 +00:00
|
|
|
}
|
2014-02-24 11:33:00 +00:00
|
|
|
return request.website.render("website_forum.post_description_full", values)
|
2014-02-21 13:16:08 +00:00
|
|
|
|
2014-03-06 11:28:16 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/comment'], type='http', auth="public", methods=['POST'], website=True)
|
2014-03-08 18:08:59 +00:00
|
|
|
def post_comment(self, forum, post_id, **kwargs):
|
2014-03-06 11:28:16 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
if kwargs.get('comment'):
|
|
|
|
user = request.registry['res.users'].browse(cr, SUPERUSER_ID, uid, context=context)
|
|
|
|
group_ids = user.groups_id
|
|
|
|
group_id = request.registry["ir.model.data"].get_object_reference(cr, uid, 'website_mail', 'group_comment')[1]
|
|
|
|
if group_id in [group.id for group in group_ids]:
|
|
|
|
Post = request.registry['website.forum.post']
|
|
|
|
Post.check_access_rights(cr, uid, 'read')
|
|
|
|
Post.message_post(
|
|
|
|
cr, SUPERUSER_ID, int(post_id),
|
|
|
|
body=kwargs.get('comment'),
|
|
|
|
type='comment',
|
|
|
|
subtype='mt_comment',
|
2014-03-08 18:08:59 +00:00
|
|
|
content_subtype='plaintext',
|
2014-03-06 11:28:16 +00:00
|
|
|
author_id=user.partner_id.id,
|
|
|
|
context=dict(context, mail_create_nosubcribe=True))
|
|
|
|
|
|
|
|
post = request.registry['website.forum.post'].browse(cr, uid, int(post_id), context=context)
|
|
|
|
question_id = post.parent_id.id if post.parent_id else post.id
|
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),question_id))
|
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/user/<model("res.users"):user>'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def open_user(self, forum, user, **post):
|
2014-03-07 11:03:29 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
User = request.registry['res.users']
|
|
|
|
Post = request.registry['website.forum.post']
|
|
|
|
Vote = request.registry['website.forum.post.vote']
|
|
|
|
Activity = request.registry['website.forum.activity']
|
|
|
|
|
|
|
|
question_ids = Post.search(cr, uid, [('create_uid', '=', user.id), ('parent_id', '=', False)], context=context)
|
|
|
|
questions = Post.browse(cr, uid, question_ids, context=context)
|
|
|
|
|
|
|
|
#TODO: showing questions in which user answered
|
|
|
|
obj_ids = Post.search(cr, uid, [('create_uid', '=', user.id), ('parent_id', '!=', False)], context=context)
|
|
|
|
answer_ids = Post.browse(cr, uid, obj_ids, context=context)
|
|
|
|
answers = [answer.parent_id for answer in answer_ids]
|
|
|
|
|
|
|
|
total_votes = Vote.search(cr, uid, [('post_id.create_uid', '=', user.id)], count=True, context=context)
|
|
|
|
up_votes = Vote.search(cr, uid, [('post_id.create_uid', '=', user.id), ('vote', '=', '1')], count=True, context=context)
|
|
|
|
down_votes = Vote.search(cr, uid, [('post_id.create_uid', '=', user.id), ('vote', '=', '-1')], count=True, context=context)
|
|
|
|
|
|
|
|
activity_ids = Activity.search(cr, uid, [('user_id', '=', user.id)], context=context)
|
|
|
|
activities = Activity.browse(cr, uid, activity_ids, context=context)
|
|
|
|
|
2014-02-26 06:58:45 +00:00
|
|
|
values = {
|
|
|
|
'user': user,
|
|
|
|
'main_object': user,
|
2014-03-03 20:22:24 +00:00
|
|
|
'searches': post,
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum': forum,
|
2014-03-07 11:03:29 +00:00
|
|
|
'questions': questions,
|
|
|
|
'answers': answers,
|
|
|
|
'total_votes': total_votes,
|
|
|
|
'up_votes': up_votes,
|
|
|
|
'down_votes': down_votes,
|
|
|
|
'activities': activities
|
2014-02-26 06:58:45 +00:00
|
|
|
}
|
|
|
|
return request.website.render("website_forum.user_detail_full", values)
|
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/question/ask/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def register_question(self, forum, **question):
|
2014-02-23 07:15:16 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
create_context = dict(context)
|
2014-02-25 09:34:18 +00:00
|
|
|
new_question_id = request.registry['website.forum.post'].create(
|
2014-02-23 07:15:16 +00:00
|
|
|
request.cr, request.uid, {
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum_id': forum.id,
|
2014-02-25 09:34:18 +00:00
|
|
|
'name': question.get('question_name'),
|
|
|
|
'content': question.get('question_content'),
|
|
|
|
#'tags' : question.get('question_tags'),
|
2014-02-23 07:15:16 +00:00
|
|
|
'state': 'active',
|
|
|
|
'active': True,
|
|
|
|
}, context=create_context)
|
2014-03-04 12:53:50 +00:00
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),new_question_id))
|
2014-02-24 07:02:06 +00:00
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/question/postanswer/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def post_answer(self, forum ,post_id, **question):
|
2014-02-23 07:15:16 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-03 20:34:25 +00:00
|
|
|
request.registry['res.users'].write(cr, uid, uid, {'forum': True}, context=context)
|
|
|
|
|
2014-02-23 07:15:16 +00:00
|
|
|
create_context = dict(context)
|
2014-02-25 09:34:18 +00:00
|
|
|
new_question_id = request.registry['website.forum.post'].create(
|
2014-02-23 07:15:16 +00:00
|
|
|
request.cr, request.uid, {
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum_id': forum.id,
|
2014-02-25 09:58:45 +00:00
|
|
|
'parent_id': post_id,
|
|
|
|
'content': question.get('answer_content'),
|
2014-02-23 07:15:16 +00:00
|
|
|
'state': 'active',
|
|
|
|
'active': True,
|
|
|
|
}, context=create_context)
|
2014-03-04 12:53:50 +00:00
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post_id))
|
2014-02-24 10:32:56 +00:00
|
|
|
|
2014-03-05 07:33:58 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):post>/editanswer'], type='http', auth="user", website=True, multilang=True)
|
|
|
|
def edit_answer(self, forum, post, **kwargs):
|
2014-02-27 12:57:01 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-03 20:34:25 +00:00
|
|
|
request.registry['res.users'].write(cr, uid, uid, {'forum': True}, context=context)
|
2014-02-27 12:57:01 +00:00
|
|
|
for answer in post.child_ids:
|
|
|
|
if answer.create_uid.id == request.uid:
|
|
|
|
post_answer = answer
|
|
|
|
values = {
|
|
|
|
'post': post,
|
|
|
|
'post_answer': post_answer,
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum': forum,
|
2014-02-27 12:57:01 +00:00
|
|
|
'searches': kwargs
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.edit_answer", values)
|
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/question/saveanswer/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def save_edited_answer(self, forum, **post):
|
2014-02-27 12:57:01 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-03 20:34:25 +00:00
|
|
|
request.registry['res.users'].write(cr, uid, uid, {'forum': True}, context=context)
|
2014-02-27 12:57:01 +00:00
|
|
|
answer_id = int(post.get('answer_id'))
|
|
|
|
new_question_id = request.registry['website.forum.post'].write( cr, uid, [answer_id], {
|
|
|
|
'content': post.get('answer_content'),
|
|
|
|
}, context=context)
|
2014-03-04 12:53:50 +00:00
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id')))
|
2014-02-27 12:57:01 +00:00
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/tag/<model("website.forum.tag"):tag>'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def tag_questions(self, forum, tag, page=1, **kwargs):
|
2014-03-07 11:03:29 +00:00
|
|
|
pager = request.website.pager(url="/forum/%s/tag" % slug(forum), total=len(tag.post_ids), page=page, step=10, scope=10)
|
2014-02-24 10:32:56 +00:00
|
|
|
|
|
|
|
values = {
|
|
|
|
'question_ids': tag.post_ids,
|
|
|
|
'pager': pager,
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum': forum,
|
2014-02-26 09:34:59 +00:00
|
|
|
'searches': kwargs
|
2014-02-24 10:32:56 +00:00
|
|
|
}
|
|
|
|
return request.website.render("website_forum.index", values)
|
2014-03-03 11:06:20 +00:00
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/tags'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def tags(self, forum, page=1, **searches):
|
2014-03-03 11:06:20 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-07 11:03:29 +00:00
|
|
|
Tag = request.registry['website.forum.tag']
|
|
|
|
obj_ids = Tag.search(cr, uid, [], limit=None, context=context)
|
|
|
|
tags = Tag.browse(cr, uid, obj_ids, context=context)
|
2014-03-03 11:06:20 +00:00
|
|
|
values = {
|
|
|
|
'tags': tags,
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum': forum,
|
2014-03-05 13:07:24 +00:00
|
|
|
'searches': {'tags': True}
|
2014-03-03 11:06:20 +00:00
|
|
|
}
|
|
|
|
return request.website.render("website_forum.tag", values)
|
|
|
|
|
2014-03-07 09:34:30 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/badges'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def badges(self, forum, **searches):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
Badge = request.registry['gamification.badge']
|
|
|
|
badge_ids = Badge.search(cr, uid, [('forum', '=', True)], context=context)
|
|
|
|
badges = Badge.browse(cr, uid, badge_ids, context=context)
|
|
|
|
values = {
|
|
|
|
'badges': badges,
|
|
|
|
'forum': forum,
|
|
|
|
'searches': {'badges': True}
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.badge", values)
|
|
|
|
|
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/badge/<model("gamification.badge"):badge>'], type='http', auth="public", website=True, multilang=True)
|
2014-03-07 11:03:29 +00:00
|
|
|
def badge_users(self, forum, badge, **kwargs):
|
2014-03-07 09:34:30 +00:00
|
|
|
users = [badge_user.user_id for badge_user in badge.owner_ids]
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-03-07 09:34:30 +00:00
|
|
|
values = {
|
|
|
|
'badge': badge,
|
|
|
|
'users': users,
|
|
|
|
'forum': forum,
|
|
|
|
'searches': kwargs
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.badge_user", values)
|
|
|
|
|
2014-03-04 10:49:30 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/users', '/forum/users/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def users(self, forum, page=1, **searches):
|
2014-03-03 11:06:20 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-07 11:03:29 +00:00
|
|
|
User = request.registry['res.users']
|
2014-03-03 11:06:20 +00:00
|
|
|
|
|
|
|
step = 30
|
2014-03-07 11:03:29 +00:00
|
|
|
tag_count = User.search(cr, uid, [('forum','=',True)], count=True, context=context)
|
2014-03-03 11:06:20 +00:00
|
|
|
pager = request.website.pager(url="/forum/users/", total=tag_count, page=page, step=step, scope=30)
|
|
|
|
|
2014-03-07 11:03:29 +00:00
|
|
|
obj_ids = User.search(cr, uid, [('forum','=',True)], limit=step, offset=pager['offset'], context=context)
|
|
|
|
users = User.browse(cr, uid, obj_ids, context=context)
|
2014-03-03 11:06:20 +00:00
|
|
|
searches['users'] = 'True'
|
|
|
|
|
|
|
|
values = {
|
|
|
|
'users': users,
|
|
|
|
'pager': pager,
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum': forum,
|
2014-03-03 11:06:20 +00:00
|
|
|
'searches': searches,
|
|
|
|
}
|
|
|
|
|
|
|
|
return request.website.render("website_forum.users", values)
|
2014-03-06 09:40:42 +00:00
|
|
|
|
|
|
|
@http.route('/forum/<model("website.forum"):forum>/post_vote/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def post_vote(self, forum, **post):
|
2014-03-06 13:17:36 +00:00
|
|
|
cr, uid, context, post_id = request.cr, request.uid, request.context, int(post.get('post_id'))
|
|
|
|
Vote = request.registry['website.forum.post.vote']
|
|
|
|
vote_ids = Vote.search(cr, uid, [('post_id', '=', post_id)], context=context)
|
|
|
|
|
|
|
|
if vote_ids:
|
|
|
|
Vote.unlink(cr, uid, vote_ids, context=context)
|
|
|
|
else:
|
|
|
|
Vote.create(cr, uid, {
|
2014-03-07 09:34:30 +00:00
|
|
|
'post_id': post_id,
|
|
|
|
'user_id': uid,
|
|
|
|
'vote': post.get('vote'),
|
|
|
|
}, context=context)
|
2014-03-06 09:40:42 +00:00
|
|
|
|
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('question_id')))
|