2014-02-21 13:16:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-02-22 17:37:59 +00:00
|
|
|
import werkzeug.urls
|
2014-03-26 13:09:50 +00:00
|
|
|
import simplejson
|
2014-02-22 17:37:59 +00:00
|
|
|
|
|
|
|
from openerp import tools
|
2014-02-21 13:16:08 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
|
|
|
from openerp.addons.web import http
|
2014-03-25 06:48:04 +00:00
|
|
|
from openerp.tools import html2plaintext
|
2014-02-21 13:16:08 +00:00
|
|
|
|
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-03-24 13:20:32 +00:00
|
|
|
from openerp.addons.web.controllers.main import login_redirect
|
2014-02-22 17:37:59 +00:00
|
|
|
|
|
|
|
controllers = controllers()
|
2014-02-21 13:16:08 +00:00
|
|
|
|
2014-04-09 16:50:59 +00:00
|
|
|
|
|
|
|
class WebsiteForum(http.Controller):
|
2014-03-04 10:49:30 +00:00
|
|
|
|
2014-04-04 07:10:43 +00:00
|
|
|
@http.route(['/forum'], type='http', auth="public", website=True, multilang=True)
|
2014-03-04 10:49:30 +00:00
|
|
|
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)
|
2014-04-09 16:50:59 +00:00
|
|
|
return request.website.render("website_forum.forum_index", {'forums': forums})
|
2014-03-04 10:49:30 +00:00
|
|
|
|
2014-04-09 16:50:59 +00:00
|
|
|
@http.route('/forum/new', type='http', auth="user", multilang=True, website=True)
|
|
|
|
def forum_create(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-04-09 16:50:59 +00:00
|
|
|
return request.redirect("/forum/%s" % slug(forum_id))
|
2014-03-04 12:40:02 +00:00
|
|
|
|
2014-04-09 16:50:59 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>',
|
2014-03-27 07:28:42 +00:00
|
|
|
'/forum/<model("website.forum"):forum>/page/<int:page>',
|
|
|
|
'/forum/<model("website.forum"):forum>/tag/<model("website.forum.tag"):tag>/questions'
|
2014-04-09 16:50:59 +00:00
|
|
|
], type='http', auth="public", website=True, multilang=True)
|
2014-03-27 07:28:42 +00:00
|
|
|
def questions(self, forum, tag='', 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-28 09:56:36 +00:00
|
|
|
user = request.registry['res.users'].browse(cr, uid, uid, context=context)
|
2014-04-09 16:50:59 +00:00
|
|
|
|
2014-03-12 09:16:02 +00:00
|
|
|
order = "id desc"
|
2014-03-05 13:07:24 +00:00
|
|
|
|
2014-04-09 16:50:59 +00:00
|
|
|
domain = [('forum_id', '=', forum.id), ('parent_id', '=', False)]
|
|
|
|
if searches.get('search'):
|
|
|
|
domain += ['|', ('name', 'ilike', searches['search']), ('content', 'ilike', searches['search'])]
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-03-27 07:28:42 +00:00
|
|
|
#filter questions for tag.
|
|
|
|
if tag:
|
2014-03-28 09:56:36 +00:00
|
|
|
if not filters:
|
|
|
|
filters = 'tag'
|
2014-04-09 16:50:59 +00:00
|
|
|
domain += [('tag_ids', 'in', tag.id)]
|
2014-03-27 07:28:42 +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) ]
|
2014-03-12 07:07:35 +00:00
|
|
|
if filters == 'followed':
|
2014-03-28 09:56:36 +00:00
|
|
|
domain += [ ('message_follower_ids', '=', user.partner_id.id) ]
|
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-26 12:27:44 +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-28 09:56:36 +00:00
|
|
|
'uid': request.session.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-19 09:07:35 +00:00
|
|
|
'notifications': self._get_notifications(),
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum': forum,
|
2014-02-21 13:16:08 +00:00
|
|
|
'pager': pager,
|
2014-03-27 07:28:42 +00:00
|
|
|
'tag': tag,
|
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-28 09:56:36 +00:00
|
|
|
def _get_notifications(self, **kwargs):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
Message = request.registry['mail.message']
|
|
|
|
BadgeUser = request.registry['gamification.badge.user']
|
|
|
|
#notification to user.
|
|
|
|
badgeuser_ids = BadgeUser.search(cr, uid, [('user_id', '=', uid)], context=context)
|
|
|
|
notification_ids = Message.search(cr, uid, [('res_id', 'in', badgeuser_ids), ('model', '=', 'gamification.badge.user'), ('to_read', '=', True)], context=context)
|
|
|
|
notifications = Message.browse(cr, uid, notification_ids, context=context)
|
|
|
|
user = request.registry['res.users'].browse(cr, uid, uid, context=context)
|
|
|
|
return {"user": user, "notifications": notifications}
|
|
|
|
|
2014-04-04 07:10:43 +00:00
|
|
|
@http.route('/forum/notification_read', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
2014-03-19 09:07:35 +00:00
|
|
|
def notification_read(self, **kwarg):
|
|
|
|
request.registry['mail.message'].set_message_read(request.cr, request.uid, [int(kwarg.get('notification_id'))], read=True, context=request.context)
|
|
|
|
return True
|
|
|
|
|
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):
|
2014-03-19 09:07:35 +00:00
|
|
|
values = {
|
|
|
|
'searches': {},
|
|
|
|
'forum':forum,
|
|
|
|
'notifications': self._get_notifications(),
|
|
|
|
}
|
2014-03-03 19:36:54 +00:00
|
|
|
return request.website.render("website_forum.faq", 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-03-25 11:34:09 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
|
|
|
|
#maintain total views on post.
|
2014-04-09 16:50:59 +00:00
|
|
|
# Statistics = request.registry['website.forum.post.statistics']
|
|
|
|
# post_obj = request.registry['website.forum.post']
|
|
|
|
# if request.session.uid:
|
|
|
|
# view_ids = Statistics.search(cr, uid, [('user_id', '=', request.session.uid), ('post_id', '=', question.id)], context=context)
|
|
|
|
# if not view_ids:
|
|
|
|
# Statistics.create(cr, SUPERUSER_ID, {'user_id': request.session.uid, 'post_id': question.id }, context=context)
|
|
|
|
# else:
|
|
|
|
# request.session[request.session_id] = request.session.get(request.session_id, [])
|
|
|
|
# if not (question.id in request.session[request.session_id]):
|
|
|
|
# request.session[request.session_id].append(question.id)
|
|
|
|
# post_obj._set_view_count(cr, SUPERUSER_ID, [question.id], 'views', 1, {}, context=context)
|
2014-03-25 11:34:09 +00:00
|
|
|
|
2014-03-28 05:16:06 +00:00
|
|
|
#Check that user have answered question or not.
|
2014-02-27 12:57:01 +00:00
|
|
|
answer_done = False
|
|
|
|
for answer in question.child_ids:
|
2014-03-19 05:06:35 +00:00
|
|
|
if answer.user_id.id == request.uid:
|
2014-02-27 12:57:01 +00:00
|
|
|
answer_done = True
|
2014-03-28 05:16:06 +00:00
|
|
|
|
|
|
|
#Check that user is following question or not
|
|
|
|
partner_id = request.registry['res.users'].browse(cr, uid, request.uid, context=context).partner_id.id
|
|
|
|
message_follower_ids = [follower.id for follower in question.message_follower_ids]
|
|
|
|
following = True if partner_id in message_follower_ids else False
|
|
|
|
|
2014-03-12 09:16:02 +00:00
|
|
|
filters = 'question'
|
2014-03-28 10:19:15 +00:00
|
|
|
user = request.registry['res.users'].browse(cr, uid, uid, context=None)
|
2014-02-24 07:02:06 +00:00
|
|
|
values = {
|
|
|
|
'question': question,
|
2014-03-28 05:16:06 +00:00
|
|
|
'question_data': True,
|
2014-03-19 09:07:35 +00:00
|
|
|
'notifications': self._get_notifications(),
|
2014-02-27 12:57:01 +00:00
|
|
|
'searches': post,
|
2014-03-12 09:16:02 +00:00
|
|
|
'filters': filters,
|
2014-03-28 05:16:06 +00:00
|
|
|
'following': following,
|
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-03-28 10:19:15 +00:00
|
|
|
'user': user,
|
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-24 13:20:32 +00:00
|
|
|
if not request.session.uid:
|
|
|
|
return login_redirect()
|
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.message_post(
|
2014-03-26 10:26:54 +00:00
|
|
|
cr, uid, int(post_id),
|
2014-03-06 11:28:16 +00:00
|
|
|
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-28 05:16:06 +00:00
|
|
|
Followers = request.registry['mail.followers']
|
2014-03-13 08:41:30 +00:00
|
|
|
Data = request.registry["ir.model.data"]
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-03-28 05:16:06 +00:00
|
|
|
#questions and answers by user.
|
|
|
|
user_questions, user_answers = [], []
|
|
|
|
user_post_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('user_id', '=', user.id),
|
2014-03-24 06:06:50 +00:00
|
|
|
'|', ('active', '=', False), ('active', '=', True)], context=context)
|
2014-03-28 05:16:06 +00:00
|
|
|
user_posts = Post.browse(cr, uid, user_post_ids, context=context)
|
|
|
|
for record in user_posts:
|
|
|
|
if record.parent_id:
|
|
|
|
user_answers.append(record)
|
|
|
|
else:
|
|
|
|
user_questions.append(record)
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-03-28 05:16:06 +00:00
|
|
|
#showing questions which user following
|
|
|
|
obj_ids = Followers.search(cr, SUPERUSER_ID, [('res_model', '=', 'website.forum.post'),('partner_id' , '=' , user.partner_id.id)], context=context)
|
2014-04-01 06:50:36 +00:00
|
|
|
post_ids = [follower.res_id for follower in Followers.browse(cr, SUPERUSER_ID, obj_ids, context=context)]
|
2014-03-28 05:16:06 +00:00
|
|
|
que_ids = Post.search(cr, uid, [('id', 'in', post_ids), ('forum_id', '=', forum.id), ('parent_id', '=', False)], context=context)
|
|
|
|
followed = Post.browse(cr, uid, que_ids, context=context)
|
2014-03-07 11:03:29 +00:00
|
|
|
|
2014-04-07 11:56:50 +00:00
|
|
|
#showing Favourite questions of user.
|
|
|
|
fav_que_ids = Post.search(cr, uid, [('favourite_ids', '=', user.id), ('forum_id', '=', forum.id), ('parent_id', '=', False)], context=context)
|
|
|
|
favourite = Post.browse(cr, uid, fav_que_ids, context=context)
|
|
|
|
|
2014-03-18 12:06:59 +00:00
|
|
|
#votes which given on users questions and answers.
|
2014-03-28 05:16:06 +00:00
|
|
|
data = Vote.read_group(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.user_id', '=', user.id)], ["vote"], groupby=["vote"], context=context)
|
2014-03-28 09:03:57 +00:00
|
|
|
up_votes, down_votes = 0, 0
|
2014-03-28 05:16:06 +00:00
|
|
|
for rec in data:
|
|
|
|
if rec['vote'] == '1':
|
|
|
|
up_votes = rec['vote_count']
|
|
|
|
elif rec['vote'] == '-1':
|
|
|
|
down_votes = rec['vote_count']
|
|
|
|
total_votes = up_votes + down_votes
|
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.
|
2014-03-19 12:40:26 +00:00
|
|
|
post_votes = Vote.search(cr, uid, [('user_id', '=', user.id)], context=context)
|
2014-03-18 12:06:59 +00:00
|
|
|
vote_ids = Vote.browse(cr, uid, post_votes, context=context)
|
|
|
|
|
|
|
|
#activity by user.
|
2014-03-13 08:41:30 +00:00
|
|
|
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-21 13:21:40 +00:00
|
|
|
'answers': user_answers,
|
2014-03-28 05:16:06 +00:00
|
|
|
'followed': followed,
|
2014-04-07 11:56:50 +00:00
|
|
|
'favourite': favourite,
|
2014-03-07 11:03:29 +00:00
|
|
|
'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,
|
2014-03-19 12:40:26 +00:00
|
|
|
'vote_post': vote_ids,
|
2014-03-19 09:07:35 +00:00
|
|
|
'notifications': self._get_notifications(),
|
2014-02-26 06:58:45 +00:00
|
|
|
}
|
|
|
|
return request.website.render("website_forum.user_detail_full", values)
|
|
|
|
|
2014-03-27 07:28:42 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/ask'], type='http', auth="public", website=True, multilang=True)
|
|
|
|
def question_ask(self, forum, **post):
|
|
|
|
if not request.session.uid:
|
|
|
|
return login_redirect()
|
2014-04-01 08:46:31 +00:00
|
|
|
user = request.registry['res.users'].browse(request.cr, request.uid, request.uid, context=request.context)
|
2014-03-27 07:28:42 +00:00
|
|
|
values = {
|
|
|
|
'searches': {},
|
|
|
|
'forum': forum,
|
2014-04-01 08:46:31 +00:00
|
|
|
'user': user,
|
2014-04-04 07:10:43 +00:00
|
|
|
'ask_question': True,
|
2014-03-27 07:28:42 +00:00
|
|
|
'notifications': self._get_notifications(),
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.ask_question", values)
|
|
|
|
|
2014-04-04 07:10:43 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/question/ask', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
2014-03-04 10:49:30 +00:00
|
|
|
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-03-24 13:21:37 +00:00
|
|
|
|
2014-03-26 13:09:50 +00:00
|
|
|
Tag = request.registry['website.forum.tag']
|
2014-03-24 13:21:37 +00:00
|
|
|
question_tags = []
|
2014-04-07 13:35:09 +00:00
|
|
|
if question.get('question_tags').strip('[]'):
|
|
|
|
tags = question.get('question_tags').strip('[]').replace('"','').split(",")
|
|
|
|
for tag in tags:
|
|
|
|
tag_ids = Tag.search(cr, uid, [('name', '=', tag)], context=context)
|
|
|
|
if tag_ids:
|
|
|
|
question_tags.append((4,tag_ids[0]))
|
|
|
|
else:
|
|
|
|
question_tags.append((0,0,{'name' : tag,'forum_id' : forum.id}))
|
|
|
|
|
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-19 12:40:26 +00:00
|
|
|
'user_id': 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'),
|
2014-04-01 08:46:31 +00:00
|
|
|
'content': question.get('content'),
|
2014-04-09 16:50:59 +00:00
|
|
|
'tag_idss' : 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-04-04 07:10:43 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/question/postanswer', type='http', auth="public", multilang=True, methods=['POST'], website=True)
|
2014-04-02 12:04:22 +00:00
|
|
|
def post_answer(self, forum , post_id, **question):
|
2014-03-24 13:20:32 +00:00
|
|
|
if not request.session.uid:
|
|
|
|
return login_redirect()
|
2014-03-25 09:12:40 +00:00
|
|
|
|
2014-02-23 07:15:16 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-26 10:26:54 +00:00
|
|
|
request.registry['res.users'].write(cr, SUPERUSER_ID, uid, {'forum': True}, context=context)
|
2014-03-03 20:34:25 +00:00
|
|
|
|
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-03-20 13:00:14 +00:00
|
|
|
cr, uid, {
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum_id': forum.id,
|
2014-03-20 13:00:14 +00:00
|
|
|
'user_id': uid,
|
2014-02-25 09:58:45 +00:00
|
|
|
'parent_id': post_id,
|
2014-04-01 08:46:31 +00:00
|
|
|
'content': question.get('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-04-02 12:04:22 +00:00
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):question>/editanswer']
|
2014-03-31 12:32:43 +00:00
|
|
|
, type='http', auth="user", website=True, multilang=True)
|
2014-04-02 12:04:22 +00:00
|
|
|
def edit_answer(self, forum, question, **kwargs):
|
|
|
|
for record in question.child_ids:
|
|
|
|
if record.user_id.id == request.uid:
|
2014-03-31 12:32:43 +00:00
|
|
|
answer = record
|
2014-04-02 12:04:22 +00:00
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s/edit/%s" % (slug(forum), question.id, answer.id))
|
|
|
|
|
|
|
|
@http.route(['/forum/<model("website.forum"):forum>/edit/question/<model("website.forum.post"):question>',
|
|
|
|
'/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):question>/edit/<model("website.forum.post"):answer>']
|
|
|
|
, type='http', auth="user", website=True, multilang=True)
|
|
|
|
def edit_post(self, forum, question, answer=None, **kwargs):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-31 12:32:43 +00:00
|
|
|
|
|
|
|
history_obj = request.registry['website.forum.post.history']
|
2014-04-02 12:04:22 +00:00
|
|
|
User = request.registry['res.users']
|
|
|
|
User.write(cr, SUPERUSER_ID, uid, {'forum': True}, context=context)
|
|
|
|
user = User.browse(cr, uid, uid, context=context)
|
|
|
|
|
|
|
|
post_id = answer.id if answer else question.id
|
|
|
|
history_ids = history_obj.search(cr, uid, [('post_id', '=', post_id)], order = "id desc", context=context)
|
2014-03-31 12:32:43 +00:00
|
|
|
post_history = history_obj.browse(cr, uid, history_ids, context=context)
|
|
|
|
|
2014-04-02 12:04:22 +00:00
|
|
|
tags = ""
|
|
|
|
for tag_name in question.tags:
|
|
|
|
tags += tag_name.name + ","
|
|
|
|
|
2014-02-27 12:57:01 +00:00
|
|
|
values = {
|
2014-04-02 12:04:22 +00:00
|
|
|
'question': question,
|
2014-04-01 08:46:31 +00:00
|
|
|
'user': user,
|
2014-04-02 12:04:22 +00:00
|
|
|
'tags': tags,
|
|
|
|
'answer': answer,
|
|
|
|
'is_answer': True if answer else False,
|
2014-03-19 09:07:35 +00:00
|
|
|
'notifications': self._get_notifications(),
|
2014-03-04 10:49:30 +00:00
|
|
|
'forum': forum,
|
2014-03-31 12:32:43 +00:00
|
|
|
'post_history': post_history,
|
2014-02-27 12:57:01 +00:00
|
|
|
'searches': kwargs
|
|
|
|
}
|
2014-04-02 12:04:22 +00:00
|
|
|
return request.website.render("website_forum.edit_post", values)
|
2014-02-27 12:57:01 +00:00
|
|
|
|
2014-04-02 12:04:22 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/post/save', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def save_edited_post(self, forum, **post):
|
2014-02-27 12:57:01 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-03-26 10:26:54 +00:00
|
|
|
request.registry['res.users'].write(cr, SUPERUSER_ID, uid, {'forum': True}, context=context)
|
2014-04-02 12:04:22 +00:00
|
|
|
vals = {
|
|
|
|
'content': post.get('content'),
|
|
|
|
}
|
2014-04-07 13:35:09 +00:00
|
|
|
question_tags = []
|
|
|
|
if post.get('question_tag').strip('[]'):
|
2014-04-02 12:04:22 +00:00
|
|
|
Tag = request.registry['website.forum.tag']
|
|
|
|
tags = post.get('question_tag').strip('[]').replace('"','').split(",")
|
|
|
|
for tag in tags:
|
2014-04-04 07:10:43 +00:00
|
|
|
tag_ids = Tag.search(cr, uid, [('name', '=', tag)], context=context)
|
2014-04-02 12:04:22 +00:00
|
|
|
if tag_ids:
|
2014-04-04 07:10:43 +00:00
|
|
|
question_tags += tag_ids
|
2014-04-02 12:04:22 +00:00
|
|
|
else:
|
2014-04-04 07:10:43 +00:00
|
|
|
new_tag = Tag.create(cr, uid, {'name' : tag,'forum_id' : forum.id}, context=context)
|
|
|
|
question_tags.append(new_tag)
|
2014-04-09 16:50:59 +00:00
|
|
|
vals.update({'tag_ids': [(6, 0, question_tags)], 'name': post.get('question_name')})
|
2014-04-02 12:04:22 +00:00
|
|
|
|
|
|
|
post_id = post.get('answer_id') if post.get('answer_id') else post.get('question_id')
|
|
|
|
new_question_id = request.registry['website.forum.post'].write( cr, uid, [int(post_id)], vals, context=context)
|
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('question_id')))
|
2014-02-27 12:57:01 +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-19 09:07:35 +00:00
|
|
|
'notifications': self._get_notifications(),
|
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,
|
2014-03-24 12:26:45 +00:00
|
|
|
'notifications': {},
|
2014-03-07 09:34:30 +00:00
|
|
|
'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,
|
2014-03-24 12:26:45 +00:00
|
|
|
'notifications': {},
|
2014-03-07 09:34:30 +00:00
|
|
|
'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-04-09 16:50:59 +00:00
|
|
|
tag_count = User.search(cr, uid, [('karma', '>', 1)], count=True, context=context)
|
2014-03-26 12:27:44 +00:00
|
|
|
pager = request.website.pager(url="/forum/users", total=tag_count, page=page, step=step, scope=30)
|
2014-03-03 11:06:20 +00:00
|
|
|
|
2014-04-09 16:50:59 +00:00
|
|
|
obj_ids = User.search(cr, uid, [('karma', '>', 1)], limit=step, offset=pager['offset'], context=context)
|
2014-03-07 11:03:29 +00:00
|
|
|
users = User.browse(cr, uid, obj_ids, context=context)
|
2014-03-03 11:06:20 +00:00
|
|
|
searches['users'] = 'True'
|
|
|
|
|
|
|
|
values = {
|
|
|
|
'users': users,
|
2014-03-19 09:07:35 +00:00
|
|
|
'notifications': self._get_notifications(),
|
2014-03-03 11:06:20 +00:00
|
|
|
'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-04-04 07:10:43 +00:00
|
|
|
@http.route('/forum/post_vote', type='json', auth="public", multilang=True, methods=['POST'], website=True)
|
2014-03-10 13:24:30 +00:00
|
|
|
def post_vote(self, **post):
|
2014-03-26 12:14:24 +00:00
|
|
|
if not request.session.uid:
|
|
|
|
return {'error': 'anonymous_user'}
|
2014-03-06 13:17:36 +00:00
|
|
|
cr, uid, context, post_id = request.cr, request.uid, request.context, int(post.get('post_id'))
|
2014-04-09 16:50:59 +00:00
|
|
|
return request.registry['website.forum.post'].vote(cr, uid, [post_id], post.get('vote'), context)
|
2014-03-11 09:12:28 +00:00
|
|
|
|
2014-04-04 07:10:43 +00:00
|
|
|
@http.route('/forum/post_delete', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
2014-03-11 09:12:28 +00:00
|
|
|
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-25 09:12:40 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/delete/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
|
2014-03-11 09:12:28 +00:00
|
|
|
def delete_question(self, forum, post, **kwarg):
|
2014-03-24 06:06:50 +00:00
|
|
|
#instead of unlink record just change 'active' to false so user can undelete it.
|
|
|
|
request.registry['website.forum.post'].write( request.cr, request.uid, [post.id], {
|
|
|
|
'active': False,
|
|
|
|
}, context=request.context)
|
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|
|
|
|
|
|
|
|
@http.route('/forum/<model("website.forum"):forum>/undelete/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
|
|
|
|
def undelete_question(self, forum, post, **kwarg):
|
|
|
|
request.registry['website.forum.post'].write( request.cr, request.uid, [post.id], {
|
|
|
|
'active': True,
|
|
|
|
}, context=request.context)
|
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|
2014-03-12 06:34:07 +00:00
|
|
|
|
2014-04-04 07:10:43 +00:00
|
|
|
@http.route('/forum/message_delete', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
2014-03-18 09:01:54 +00:00
|
|
|
def delete_comment(self, **kwarg):
|
2014-03-26 10:26:54 +00:00
|
|
|
request.registry['mail.message'].unlink(request.cr, SUPERUSER_ID, [int(kwarg.get('message_id'))], context=request.context)
|
2014-03-18 09:01:54 +00:00
|
|
|
return True
|
|
|
|
|
2014-04-01 08:46:31 +00:00
|
|
|
@http.route('/forum/selecthistory', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def post_history(self, **kwarg):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
post_history = request.registry['website.forum.post.history'].browse(cr, uid, int(kwarg.get('history_id')), context=context)
|
|
|
|
tags = ""
|
|
|
|
for tag_name in post_history.tags:
|
|
|
|
tags += tag_name.name + ","
|
|
|
|
data = {
|
|
|
|
'name': post_history.post_name,
|
|
|
|
'content': post_history.content,
|
|
|
|
'tags': tags,
|
|
|
|
}
|
|
|
|
return data
|
|
|
|
|
2014-04-04 07:10:43 +00:00
|
|
|
@http.route('/forum/correct_answer', type='json', auth="public", multilang=True, methods=['POST'], website=True)
|
2014-03-12 12:05:44 +00:00
|
|
|
def correct_answer(self, **kwarg):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-04-01 13:28:06 +00:00
|
|
|
if not request.session.uid:
|
|
|
|
return {'error': 'anonymous_user'}
|
|
|
|
|
2014-03-12 12:05:44 +00:00
|
|
|
Post = request.registry['website.forum.post']
|
|
|
|
post = Post.browse(cr, uid, int(kwarg.get('post_id')), context=context)
|
2014-03-28 10:19:15 +00:00
|
|
|
user = request.registry['res.users'].browse(cr, uid, uid, context=None)
|
2014-04-01 13:28:06 +00:00
|
|
|
|
|
|
|
#if user have not access to accept answer then reise warning
|
|
|
|
if not (post.parent_id.user_id.id == uid or user.karma >= 500):
|
|
|
|
return {'error': 'user'}
|
|
|
|
|
|
|
|
#Note: only one answer can be right.
|
|
|
|
correct = False if post.correct else True
|
|
|
|
for child in post.parent_id.child_ids:
|
|
|
|
if child.correct and child.id != post.id:
|
|
|
|
Post.write( cr, uid, [child.id], { 'correct': False }, context=context)
|
|
|
|
Post.write( cr, uid, [post.id, post.parent_id.id], { 'correct': correct }, context=context)
|
|
|
|
return correct
|
2014-03-14 11:39:13 +00:00
|
|
|
|
2014-04-07 07:20:32 +00:00
|
|
|
@http.route('/forum/favourite_question', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
|
|
|
def favourite_question(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)
|
|
|
|
favourite = False if post.user_favourite else True
|
|
|
|
favourite_ids = [(4, uid)]
|
|
|
|
if post.user_favourite:
|
|
|
|
favourite_ids = [(3, uid)]
|
|
|
|
Post.write( cr, uid, [post.id], { 'favourite_ids': favourite_ids }, context=context)
|
|
|
|
return favourite
|
|
|
|
|
2014-03-25 09:12:40 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/close/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
|
2014-03-21 12:57:47 +00:00
|
|
|
def close_question(self, forum, post, **kwarg):
|
2014-03-24 07:11:52 +00:00
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
Reason = request.registry['website.forum.post.reason']
|
|
|
|
reason_ids = Reason.search(cr, uid, [], context=context)
|
|
|
|
reasons = Reason.browse(cr, uid, reason_ids, context)
|
2014-03-21 12:57:47 +00:00
|
|
|
|
|
|
|
values = {
|
|
|
|
'post': post,
|
|
|
|
'forum': forum,
|
|
|
|
'searches': kwarg,
|
|
|
|
'reasons': reasons,
|
|
|
|
'notifications': self._get_notifications(),
|
|
|
|
}
|
|
|
|
return request.website.render("website_forum.close_question", values)
|
|
|
|
|
2014-04-04 07:10:43 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/question/close', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
2014-03-24 06:06:50 +00:00
|
|
|
def close(self, forum, **post):
|
2014-03-21 12:57:47 +00:00
|
|
|
request.registry['website.forum.post'].write( request.cr, request.uid, [int(post.get('post_id'))], {
|
|
|
|
'state': 'close',
|
|
|
|
'closed_by': request.uid,
|
|
|
|
'closed_date': datetime.today().strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT),
|
2014-03-24 07:11:52 +00:00
|
|
|
'reason_id': post.get('reason'),
|
2014-03-21 12:57:47 +00:00
|
|
|
}, context=request.context)
|
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id')))
|
|
|
|
|
2014-03-24 06:06:50 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/reopen/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
|
|
|
|
def reopen(self, forum, post, **kwarg):
|
|
|
|
request.registry['website.forum.post'].write( request.cr, request.uid, [post.id], {
|
|
|
|
'state': 'active',
|
|
|
|
}, context=request.context)
|
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|
|
|
|
|
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,
|
2014-03-19 09:07:35 +00:00
|
|
|
'notifications': self._get_notifications(),
|
2014-03-14 11:39:13 +00:00
|
|
|
}
|
|
|
|
return request.website.render("website_forum.edit_profile", values)
|
|
|
|
|
2014-04-04 07:10:43 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/save/profile', type='http', auth="user", multilang=True, website=True)
|
2014-03-14 11:39:13 +00:00
|
|
|
def save_edited_profile(self, forum, **post):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
2014-04-01 11:57:27 +00:00
|
|
|
user = request.registry['res.users'].browse(cr, uid, int(post.get('user_id')),context=context)
|
|
|
|
request.registry['res.partner'].write( cr, uid, [user.partner_id.id], {
|
2014-03-14 13:27:43 +00:00
|
|
|
'name': post.get('name'),
|
|
|
|
'website': post.get('website'),
|
2014-04-02 09:25:49 +00:00
|
|
|
'email': post.get('email'),
|
2014-03-14 13:27:43 +00:00
|
|
|
'city': post.get('city'),
|
2014-04-01 11:57:27 +00:00
|
|
|
'country_id': post.get('country'),
|
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')))
|
2014-03-24 12:26:45 +00:00
|
|
|
|
2014-03-25 07:06:48 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/post/<model("website.forum.post"):post>/commet/<model("mail.message"):comment>/converttoanswer', type='http', auth="public", multilang=True, website=True)
|
2014-03-24 12:26:45 +00:00
|
|
|
def convert_to_answer(self, forum, post, comment, **kwarg):
|
|
|
|
values = {
|
2014-04-04 07:10:43 +00:00
|
|
|
'content': comment.body,
|
2014-03-24 12:26:45 +00:00
|
|
|
}
|
|
|
|
request.registry['mail.message'].unlink(request.cr, request.uid, [comment.id], context=request.context)
|
|
|
|
return self.post_answer(forum, post.parent_id and post.parent_id.id or post.id, **values)
|
|
|
|
|
2014-03-25 09:12:40 +00:00
|
|
|
@http.route('/forum/<model("website.forum"):forum>/post/<model("website.forum.post"):post>/converttocomment', type='http', auth="user", multilang=True, website=True)
|
2014-03-24 12:26:45 +00:00
|
|
|
def convert_to_comment(self, forum, post, **kwarg):
|
|
|
|
values = {
|
2014-03-25 06:48:04 +00:00
|
|
|
'comment': html2plaintext(post.content),
|
2014-03-24 12:26:45 +00:00
|
|
|
}
|
2014-03-25 06:48:04 +00:00
|
|
|
question = post.parent_id.id
|
2014-03-26 10:26:54 +00:00
|
|
|
request.registry['website.forum.post'].unlink(request.cr, SUPERUSER_ID, [post.id], context=request.context)
|
2014-03-25 06:48:04 +00:00
|
|
|
return self.post_comment(forum, question, **values)
|
2014-03-24 12:26:45 +00:00
|
|
|
|
2014-03-26 13:09:50 +00:00
|
|
|
@http.route('/forum/get_tags', type='http', auth="public", multilang=True, methods=['GET'], website=True)
|
2014-03-24 13:21:37 +00:00
|
|
|
def tag_read(self, **kwarg):
|
2014-03-26 13:09:50 +00:00
|
|
|
tags = request.registry['website.forum.tag'].search_read(request.cr, request.uid, [], ['name'], context=request.context)
|
|
|
|
data = [tag['name'] for tag in tags]
|
|
|
|
return simplejson.dumps(data)
|
2014-03-28 05:16:06 +00:00
|
|
|
|
|
|
|
@http.route('/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):post>/subscribe', type='http', auth="public", multilang=True, website=True)
|
|
|
|
def subscribe(self, forum, post, **kwarg):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
if not request.session.uid:
|
|
|
|
return login_redirect()
|
|
|
|
partner_id = request.registry['res.users'].browse(cr, uid, request.uid, context=context).partner_id.id
|
|
|
|
post_ids = [child.id for child in post.child_ids]
|
|
|
|
post_ids.append(post.id)
|
|
|
|
request.registry['website.forum.post'].message_subscribe( cr, uid, post_ids, [partner_id], context=context)
|
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|
|
|
|
|
|
|
|
@http.route('/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):post>/unsubscribe', type='http', auth="user", multilang=True, website=True)
|
|
|
|
def unsubscribe(self, forum, post, **kwarg):
|
|
|
|
cr, uid, context = request.cr, request.uid, request.context
|
|
|
|
partner_id = request.registry['res.users'].browse(cr, uid, request.uid, context=context).partner_id.id
|
|
|
|
post_ids = [child.id for child in post.child_ids]
|
|
|
|
post_ids.append(post.id)
|
|
|
|
request.registry['website.forum.post'].message_unsubscribe( cr, uid, post_ids, [partner_id], context=context)
|
|
|
|
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|