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
|
|
|
|
|
|
|
|
controllers = controllers()
|
2014-02-21 13:16:08 +00:00
|
|
|
|
|
|
|
class website_forum(http.Controller):
|
2014-02-24 07:02:06 +00:00
|
|
|
|
2014-02-26 13:25:47 +00:00
|
|
|
@http.route(['/forum/', '/forum/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
2014-02-21 13:16:08 +00:00
|
|
|
def questions(self, page=1, **searches):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
forum_obj = request.registry['website.forum.post']
|
2014-02-25 07:23:56 +00:00
|
|
|
domain = [('parent_id', '=', False)]
|
|
|
|
search = searches.get('search',False)
|
|
|
|
if search:
|
|
|
|
domain += ['|',
|
|
|
|
('name', 'ilike', search),
|
|
|
|
('content', 'ilike', search)]
|
2014-02-24 07:02:06 +00:00
|
|
|
|
2014-02-24 10:32:56 +00:00
|
|
|
step = 10
|
2014-02-21 13:16:08 +00:00
|
|
|
question_count = forum_obj.search(
|
2014-02-25 07:23:56 +00:00
|
|
|
request.cr, request.uid, domain, count=True,
|
2014-02-21 13:16:08 +00:00
|
|
|
context=request.context)
|
2014-02-26 13:25:47 +00:00
|
|
|
pager = request.website.pager(url="/forum/", total=question_count, page=page, step=step, scope=10)
|
2014-02-24 07:02:06 +00:00
|
|
|
|
2014-02-21 13:16:08 +00:00
|
|
|
obj_ids = forum_obj.search(
|
2014-02-25 07:23:56 +00:00
|
|
|
request.cr, request.uid, domain, limit=step,
|
2014-02-21 13:16:08 +00:00
|
|
|
offset=pager['offset'], context=request.context)
|
|
|
|
question_ids = forum_obj.browse(request.cr, request.uid, obj_ids,
|
|
|
|
context=request.context)
|
2014-02-25 09:34:18 +00:00
|
|
|
#If dose not get any related question then redirect to ask question form.
|
|
|
|
if search and not question_ids:
|
|
|
|
values = {
|
|
|
|
'question_name': search,
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.ask_question", values)
|
|
|
|
|
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,
|
|
|
|
'pager': pager,
|
|
|
|
'searches': searches,
|
|
|
|
}
|
|
|
|
|
|
|
|
return request.website.render("website_forum.index", values)
|
|
|
|
|
2014-02-26 13:25:47 +00:00
|
|
|
@http.route(['/forum/question/<model("website.forum.post"):question>/page/<page:page>'], type='http', auth="public", website=True, multilang=True)
|
2014-02-23 07:15:16 +00:00
|
|
|
def question(self, question, page, **post):
|
2014-02-21 13:16:08 +00:00
|
|
|
values = {
|
|
|
|
'question': question,
|
|
|
|
'main_object': question
|
|
|
|
}
|
|
|
|
return request.website.render(page, values)
|
|
|
|
|
2014-02-26 13:25:47 +00:00
|
|
|
@http.route(['/forum/question/<model("website.forum.post"):question>'], type='http', auth="public", website=True, multilang=True)
|
2014-02-24 10:32:56 +00:00
|
|
|
def open_question(self, 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,
|
|
|
|
'main_object': question,
|
2014-02-27 12:57:01 +00:00
|
|
|
'searches': post,
|
|
|
|
'answer_done': answer_done
|
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-02-26 13:25:47 +00:00
|
|
|
@http.route(['/forum/user/<model("res.users"):user>'], type='http', auth="public", website=True, multilang=True)
|
2014-02-26 06:58:45 +00:00
|
|
|
def open_user(self, user, **post):
|
|
|
|
values = {
|
|
|
|
'user': user,
|
|
|
|
'main_object': user,
|
|
|
|
'searches': post
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.user_detail_full", values)
|
|
|
|
|
2014-02-26 13:25:47 +00:00
|
|
|
@http.route('/forum/question/ask/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
2014-02-23 07:15:16 +00:00
|
|
|
def register_question(self, forum_id=1, **question):
|
|
|
|
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-02-25 09:34:18 +00:00
|
|
|
#'forum_id': forum_id,
|
|
|
|
'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-02-26 13:25:47 +00:00
|
|
|
return werkzeug.utils.redirect("/forum/question/%s" % new_question_id)
|
2014-02-24 07:02:06 +00:00
|
|
|
|
2014-02-26 13:25:47 +00:00
|
|
|
@http.route('/forum/question/postanswer/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
2014-02-23 07:15:16 +00:00
|
|
|
def post_answer(self, post_id, forum_id=1, **question):
|
|
|
|
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-02-25 09:58:45 +00:00
|
|
|
#'forum_id': forum_id,
|
|
|
|
'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-02-26 13:25:47 +00:00
|
|
|
return werkzeug.utils.redirect("/forum/question/%s" % post_id)
|
2014-02-24 10:32:56 +00:00
|
|
|
|
2014-02-27 12:57:01 +00:00
|
|
|
@http.route(['/forum/question/editanswer'], type='http', auth="user", website=True, multilang=True)
|
|
|
|
def edit_answer(self, post_id, **kwargs):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
post = request.registry['website.forum.post'].browse(cr, uid, int(post_id), context=context)
|
|
|
|
for answer in post.child_ids:
|
|
|
|
if answer.create_uid.id == request.uid:
|
|
|
|
post_answer = answer
|
|
|
|
values = {
|
|
|
|
'post': post,
|
|
|
|
'post_answer': post_answer,
|
|
|
|
'searches': kwargs
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.edit_answer", values)
|
|
|
|
|
|
|
|
@http.route('/forum/question/saveanswer/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def save_edited_answer(self, forum_id=1, **post):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
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)
|
|
|
|
return werkzeug.utils.redirect("/forum/question/%s" % post.get('post_id'))
|
|
|
|
|
2014-02-26 13:25:47 +00:00
|
|
|
@http.route(['/forum/tag/<model("website.forum.tag"):tag>'], type='http', auth="public", website=True, multilang=True)
|
2014-02-24 10:32:56 +00:00
|
|
|
def tag_questions(self, tag, page=1, **kwargs):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
step = 10
|
2014-02-26 13:25:47 +00:00
|
|
|
pager = request.website.pager(url="/forum/", total=len(tag.post_ids), page=page, step=step, scope=10)
|
2014-02-24 10:32:56 +00:00
|
|
|
|
|
|
|
values = {
|
|
|
|
'question_ids': tag.post_ids,
|
|
|
|
'pager': pager,
|
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)
|