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)
|
2014-03-09 08:45:52 +00:00
|
|
|
forums = Forum.browse(cr, uid, obj_ids, context=context)
|
|
|
|
values = { 'forums': forums }
|
2014-03-04 10:49:30 +00:00
|
|
|
return request.website.render("website_forum.forum_index", values)
|
|
|
|
|
2014-03-18 09:01:54 +00:00
|
|
|
@http.route('/forum/add_forum/', type='http', auth="user", multilang=True, website=True)
|
2014-03-04 12:40:02 +00:00
|
|
|
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,
|
2014-03-07 11:03:29 +00:00
|
|
|
}, context=request.context)
|
2014-03-09 18:41:19 +00:00
|
|
|
return request.redirect("/forum/%s" % forum_id)
|
2014-03-04 12:40:02 +00:00
|
|
|
|
2014-03-09 18:41:19 +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)
|
2014-03-12 09:16:02 +00:00
|
|
|
def questions(self, forum, page=1, filters='', sorting='', **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-12 09:16:02 +00:00
|
|
|
order = "id desc"
|
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
|
|
|
|
2014-03-12 07:07:35 +00:00
|
|
|
if not filters:
|
|
|
|
filters = 'all'
|
|
|
|
if filters == 'unanswered':
|
2014-03-03 06:28:18 +00:00
|
|
|
domain += [ ('child_ids', '=', False) ]
|
|
|
|
#TODO: update domain to show followed questions of user
|
2014-03-12 07:07:35 +00:00
|
|
|
if filters == 'followed':
|
2014-03-07 11:03:29 +00:00
|
|
|
domain += [ ('create_uid', '=', uid) ]
|
2014-02-24 07:02:06 +00:00
|
|
|
|
2014-03-18 09:01:54 +00:00
|
|
|
# Note: default sorting should be based on last activity
|
|
|
|
if not sorting or sorting == 'date':
|
|
|
|
sorting = 'date'
|
2014-03-12 09:16:02 +00:00
|
|
|
order = 'write_date desc'
|
|
|
|
if sorting == 'answered':
|
|
|
|
order = 'child_count desc'
|
|
|
|
if sorting == 'vote':
|
|
|
|
order = 'vote_count desc'
|
|
|
|
|
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-12 09:16:02 +00:00
|
|
|
obj_ids = Forum.search(cr, uid, domain, limit=step, offset=pager['offset'], order=order, context=context)
|
2014-03-07 11:03:29 +00:00
|
|
|
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-03-18 09:01:54 +00:00
|
|
|
'uid': uid,
|
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,
|
2014-03-12 07:07:35 +00:00
|
|
|
'filters': filters,
|
2014-03-12 09:16:02 +00:00
|
|
|
'sorting': sorting,
|
2014-02-21 13:16:08 +00:00
|
|
|
'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>'], type='http', auth="public", website=True, multilang=True)
|
2014-03-10 09:43:02 +00:00
|
|
|
def 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-03-12 09:16:02 +00:00
|
|
|
filters = 'question'
|
2014-02-24 07:02:06 +00:00
|
|
|
values = {
|
|
|
|
'question': question,
|
2014-02-27 12:57:01 +00:00
|
|
|
'searches': post,
|
2014-03-12 09:16:02 +00:00
|
|
|
'filters': filters,
|
2014-03-04 10:49:30 +00:00
|
|
|
'answer_done': answer_done,
|
2014-03-09 18:41:19 +00:00
|
|
|
'reversed': reversed,
|
2014-03-04 10:49:30 +00:00
|
|
|
'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']
|
2014-03-11 12:59:49 +00:00
|
|
|
Activity = request.registry['mail.message']
|
2014-03-13 08:41:30 +00:00
|
|
|
Data = request.registry["ir.model.data"]
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-03-18 12:06:59 +00:00
|
|
|
#questions asked by user.
|
2014-03-10 05:49:32 +00:00
|
|
|
question_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('create_uid', '=', user.id), ('parent_id', '=', False)], context=context)
|
2014-03-11 12:59:49 +00:00
|
|
|
user_questions = Post.browse(cr, uid, question_ids, context=context)
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-03-11 12:59:49 +00:00
|
|
|
#showing questions in which user answered
|
2014-03-10 05:49:32 +00:00
|
|
|
obj_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('create_uid', '=', user.id), ('parent_id', '!=', False)], context=context)
|
2014-03-11 12:59:49 +00:00
|
|
|
user_answers = Post.browse(cr, uid, obj_ids, context=context)
|
|
|
|
answers = [answer.parent_id for answer in user_answers]
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-03-18 12:06:59 +00:00
|
|
|
#votes which given on users questions and answers.
|
2014-03-10 05:49:32 +00:00
|
|
|
total_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id)], count=True, context=context)
|
|
|
|
up_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id), ('vote', '=', '1')], count=True, context=context)
|
|
|
|
down_votes = Vote.search(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id), ('vote', '=', '-1')], count=True, context=context)
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-03-18 12:06:59 +00:00
|
|
|
#Votes which given by users on others questions and answers.
|
|
|
|
post_votes = Vote.search(cr, uid, [('user_id', '=', uid)], context=context)
|
|
|
|
vote_ids = Vote.browse(cr, uid, post_votes, context=context)
|
|
|
|
|
|
|
|
#activity by user.
|
2014-03-13 08:41:30 +00:00
|
|
|
user_post_ids = question_ids + obj_ids
|
|
|
|
model, comment = Data.get_object_reference(cr, uid, 'mail', 'mt_comment')
|
|
|
|
activity_ids = Activity.search(cr, uid, [('res_id', 'in', user_post_ids), ('model', '=', 'website.forum.post'), '|', ('subtype_id', '!=', comment), ('subtype_id', '=', False)], context=context)
|
2014-03-07 11:03:29 +00:00
|
|
|
activities = Activity.browse(cr, uid, activity_ids, context=context)
|
2014-03-16 15:09:31 +00:00
|
|
|
|
2014-03-11 12:59:49 +00:00
|
|
|
posts = {}
|
2014-03-16 15:09:31 +00:00
|
|
|
for act in activities:
|
|
|
|
posts[act.res_id] = True
|
|
|
|
posts_ids = Post.browse(cr, uid, posts.keys(), context=context)
|
|
|
|
posts = dict(map(lambda x: (x.id, (x.parent_id or x, x.parent_id and x or False)), posts_ids))
|
|
|
|
|
2014-03-10 09:43:02 +00:00
|
|
|
post['users'] = 'True'
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-02-26 06:58:45 +00:00
|
|
|
values = {
|
2014-03-18 11:20:50 +00:00
|
|
|
'uid': uid,
|
2014-02-26 06:58:45 +00:00
|
|
|
'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-11 12:59:49 +00:00
|
|
|
'questions': user_questions,
|
2014-03-07 11:03:29 +00:00
|
|
|
'answers': answers,
|
|
|
|
'total_votes': total_votes,
|
|
|
|
'up_votes': up_votes,
|
|
|
|
'down_votes': down_votes,
|
2014-03-11 12:59:49 +00:00
|
|
|
'activities': activities,
|
2014-03-18 11:12:29 +00:00
|
|
|
'posts': posts,
|
|
|
|
'vote_post':vote_ids,
|
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-10 05:49:32 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
Post = request.registry['website.forum.post']
|
2014-03-12 09:54:13 +00:00
|
|
|
obj_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('tags', '=', tag.id)], context=context)
|
2014-03-10 05:49:32 +00:00
|
|
|
question_ids = Post.browse(cr, uid, obj_ids, context=context)
|
2014-03-12 09:54:13 +00:00
|
|
|
pager = request.website.pager(url="/forum/%s/tag" % slug(forum), total=len(obj_ids), page=page, step=10, scope=10)
|
2014-03-10 09:43:02 +00:00
|
|
|
kwargs['tags'] = 'True'
|
2014-02-24 10:32:56 +00:00
|
|
|
|
|
|
|
values = {
|
2014-03-10 05:49:32 +00:00
|
|
|
'question_ids': question_ids,
|
2014-02-24 10:32:56 +00:00
|
|
|
'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-12 09:54:13 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/tag'], type='http', auth="public", website=True, multilang=True)
|
2014-03-04 10:49:30 +00:00
|
|
|
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']
|
2014-03-10 05:49:32 +00:00
|
|
|
obj_ids = Tag.search(cr, uid, [('forum_id', '=', forum.id)], limit=None, context=context)
|
2014-03-07 11:03:29 +00:00
|
|
|
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-12 09:54:13 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/badge'], type='http', auth="public", website=True, multilang=True)
|
2014-03-07 09:34:30 +00:00
|
|
|
def badges(self, forum, **searches):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
Badge = request.registry['gamification.badge']
|
2014-03-12 09:54:13 +00:00
|
|
|
badge_ids = Badge.search(cr, uid, [('level', '!=', False)], context=context)
|
2014-03-07 09:34:30 +00:00
|
|
|
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-10 09:43:02 +00:00
|
|
|
kwargs['badges'] = 'True'
|
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
|
|
|
|
2014-03-10 13:24:30 +00:00
|
|
|
@http.route('/forum/post_vote/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def post_vote(self, **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']
|
2014-03-12 08:46:47 +00:00
|
|
|
return Vote.vote(cr, uid, post_id, post.get('vote'), context)
|
2014-03-11 09:12:28 +00:00
|
|
|
|
|
|
|
@http.route('/forum/post_delete/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def delete_answer(self, **kwarg):
|
2014-03-13 09:04:54 +00:00
|
|
|
request.registry['website.forum.post'].unlink(request.cr, request.uid, [int(kwarg.get('post_id'))], context=request.context)
|
2014-03-11 09:12:28 +00:00
|
|
|
return True
|
2014-03-18 09:01:54 +00:00
|
|
|
|
2014-03-11 09:12:28 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/delete/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
|
|
|
|
def delete_question(self, forum, post, **kwarg):
|
2014-03-13 09:04:54 +00:00
|
|
|
request.registry['website.forum.post'].unlink(request.cr, request.uid, [post.id], context=request.context)
|
2014-03-11 09:12:28 +00:00
|
|
|
return werkzeug.utils.redirect("/forum/%s/" % (slug(forum)))
|
2014-03-12 06:34:07 +00:00
|
|
|
|
2014-03-18 09:01:54 +00:00
|
|
|
@http.route('/forum/message_delete/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def delete_comment(self, **kwarg):
|
|
|
|
request.registry['mail.message'].unlink(request.cr, request.uid, [int(kwarg.get('message_id'))], context=request.context)
|
|
|
|
return True
|
|
|
|
|
2014-03-12 06:34:07 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/edit/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
|
|
|
|
def edit_question(self, forum, post, **kwarg):
|
|
|
|
values = {
|
|
|
|
'post': post,
|
|
|
|
'forum': forum,
|
|
|
|
'searches': kwarg
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.edit_question", values)
|
|
|
|
|
|
|
|
@http.route('/forum/<model("website.forum"):forum>/question/savequestion/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def save_edited_question(self, forum, **post):
|
2014-03-13 09:04:54 +00:00
|
|
|
request.registry['website.forum.post'].write( request.cr, request.uid, [int(post.get('post_id'))], {
|
|
|
|
'content': post.get('answer_content'),
|
|
|
|
'name': post.get('question_name'),
|
|
|
|
}, context=request.context)
|
2014-03-12 06:34:07 +00:00
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id')))
|
|
|
|
|
|
|
|
@http.route('/forum/<model("website.forum"):forum>/answer/<model("website.forum.post"):post>/edit/<model("website.forum.post"):answer>', type='http', auth="user", multilang=True, website=True)
|
|
|
|
def edit_ans(self, forum, post, answer, **kwarg):
|
|
|
|
values = {
|
|
|
|
'post': post,
|
|
|
|
'post_answer': answer,
|
|
|
|
'forum': forum,
|
|
|
|
'searches': kwarg
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.edit_answer", values)
|
|
|
|
|
2014-03-12 12:05:44 +00:00
|
|
|
@http.route('/forum/correct_answer/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def correct_answer(self, **kwarg):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
Post = request.registry['website.forum.post']
|
|
|
|
post = Post.browse(cr, uid, int(kwarg.get('post_id')), context=context)
|
|
|
|
if post.create_uid.id == uid:
|
|
|
|
correct = False if post.correct else True
|
2014-03-18 09:01:54 +00:00
|
|
|
#Note: only one answer can be right.
|
|
|
|
for child in post.parent_id.child_ids:
|
|
|
|
if child.correct:
|
|
|
|
Post.write( cr, uid, [child.id], {
|
|
|
|
'correct': False,
|
|
|
|
}, context=context)
|
2014-03-12 12:05:44 +00:00
|
|
|
Post.write( cr, uid, [int(kwarg.get('post_id'))], {
|
|
|
|
'correct': correct,
|
|
|
|
}, context=context)
|
|
|
|
return correct
|
2014-03-14 11:39:13 +00:00
|
|
|
|
|
|
|
@http.route('/forum/<model("website.forum"):forum>/edit/profile/<model("res.users"):user>', type='http', auth="user", multilang=True, website=True)
|
|
|
|
def edit_profile(self, forum, user, **kwarg):
|
|
|
|
cr,context = request.cr, request.context
|
|
|
|
country = request.registry['res.country']
|
|
|
|
country_ids = country.search(cr, SUPERUSER_ID, [], context=context)
|
|
|
|
countries = country.browse(cr, SUPERUSER_ID, country_ids, context)
|
|
|
|
values = {
|
|
|
|
'user': user,
|
|
|
|
'forum': forum,
|
|
|
|
'searches': kwarg,
|
|
|
|
'countries': countries,
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.edit_profile", values)
|
|
|
|
|
|
|
|
@http.route('/forum/<model("website.forum"):forum>/save/profile/', type='http', auth="user", multilang=True, website=True)
|
|
|
|
def save_edited_profile(self, forum, **post):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
request.registry['res.users'].write( cr, uid, [int(post.get('user_id'))], {
|
2014-03-14 13:27:43 +00:00
|
|
|
'name': post.get('name'),
|
|
|
|
}, context=context)
|
2014-03-14 11:39:13 +00:00
|
|
|
record_id = request.registry['res.users'].browse(cr, uid, int(post.get('user_id')),context=context).partner_id.id
|
|
|
|
request.registry['res.partner'].write( cr, uid, [record_id], {
|
2014-03-14 13:27:43 +00:00
|
|
|
'website': post.get('website'),
|
|
|
|
'city': post.get('city'),
|
|
|
|
'country_id':post.get('country'),
|
|
|
|
'birthdate':post.get('dob'),
|
2014-03-18 11:20:50 +00:00
|
|
|
'website_description': post.get('description'),
|
2014-03-14 13:27:43 +00:00
|
|
|
}, context=context)
|
2014-03-14 11:39:13 +00:00
|
|
|
return werkzeug.utils.redirect("/forum/%s/user/%s" % (slug(forum),post.get('user_id')))
|