diff options
| author | Thibault Delavallée <tde@openerp.com> | 2014-04-11 15:29:39 +0200 |
|---|---|---|
| committer | Thibault Delavallée <tde@openerp.com> | 2014-04-11 15:29:39 +0200 |
| commit | cd4afee17e77d5d5de8dc27f7dbe56be6d8fe7a2 (patch) | |
| tree | 70f6a320d9359206621887dc46e3d2ff5f431fac /addons/website_forum | |
| parent | 4b776a90c0c65a1e0cfecfcdbc638462a9ece8e5 (diff) | |
[CLEAN] website_forum: cleaning before merging
- cleaned models
- cleaned controllers: lots of cleaning, rewriting, simplfiication + updated in views
- added an override of the contact widget, to be able to display partner-related
stuff about karma and badges
- some css tweaking
- badges cleaning
bzr revid: tde@openerp.com-20140411132939-bmvyc9bqpqpkk843
Diffstat (limited to 'addons/website_forum')
| -rw-r--r-- | addons/website_forum/__openerp__.py | 1 | ||||
| -rw-r--r-- | addons/website_forum/controllers/main.py | 826 | ||||
| -rw-r--r-- | addons/website_forum/data/badges_answer.xml | 16 | ||||
| -rw-r--r-- | addons/website_forum/data/badges_moderation.xml | 15 | ||||
| -rw-r--r-- | addons/website_forum/data/badges_question.xml | 18 | ||||
| -rw-r--r-- | addons/website_forum/data/forum_demo.xml | 6 | ||||
| -rw-r--r-- | addons/website_forum/models/forum.py | 23 | ||||
| -rw-r--r-- | addons/website_forum/static/src/css/Makefile | 7 | ||||
| -rw-r--r-- | addons/website_forum/static/src/css/website_forum.css | 15 | ||||
| -rw-r--r-- | addons/website_forum/static/src/css/website_forum.sass | 10 | ||||
| -rw-r--r-- | addons/website_forum/static/src/js/website_forum.js | 122 | ||||
| -rw-r--r-- | addons/website_forum/views/ir_qweb.xml | 24 | ||||
| -rw-r--r-- | addons/website_forum/views/website_forum.xml | 1645 |
13 files changed, 1353 insertions, 1375 deletions
diff --git a/addons/website_forum/__openerp__.py b/addons/website_forum/__openerp__.py index 439c3df15a4..0fce7b6fe05 100644 --- a/addons/website_forum/__openerp__.py +++ b/addons/website_forum/__openerp__.py @@ -39,6 +39,7 @@ Ask questions, get answers, no distractions 'views/forum.xml', 'views/res_users.xml', 'views/website_forum.xml', + 'views/ir_qweb.xml', 'security/ir.model.access.csv', 'data/badges_question.xml', 'data/badges_answer.xml', diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 6804e293b4c..6225698094d 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -1,360 +1,352 @@ # -*- coding: utf-8 -*- +from datetime import datetime import werkzeug.urls import simplejson from openerp import tools from openerp import SUPERUSER_ID from openerp.addons.web import http -from openerp.tools import html2plaintext - -from openerp.tools.translate import _ -from datetime import datetime, timedelta +from openerp.addons.web.controllers.main import login_redirect from openerp.addons.web.http import request - -from dateutil.relativedelta import relativedelta from openerp.addons.website.controllers.main import Website as controllers from openerp.addons.website.models.website import slug -from openerp.addons.web.controllers.main import login_redirect +from openerp.tools import html2plaintext +from openerp.tools.translate import _ controllers = controllers() class WebsiteForum(http.Controller): + _post_per_page = 10 + _user_per_page = 30 + + def _get_notifications(self): + 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) + return notifications + + def _prepare_forum_values(self, forum=None, **kwargs): + user = request.registry['res.users'].browse(request.cr, request.uid, request.uid, context=request.context) + public_uid = request.registry['website'].get_public_user(request.cr, request.uid, request.context) + values = {'user': user, 'is_public_user': user.id == public_uid, + 'notifications': self._get_notifications(), + 'header': kwargs.get('header', dict()), + 'searches': kwargs.get('searches', dict())} + values.update(kwargs) + if forum: + values['forum'] = forum + elif kwargs.get('forum_id'): + values['forum'] = request.registry['forum.forum'].browse(request.cr, request.uid, kwargs['forum_id'], context=request.context) + return values + + # Forum + # -------------------------------------------------- @http.route(['/forum'], type='http', auth="public", website=True, multilang=True) - def forum(self, **searches): + def forum(self, **kwargs): cr, uid, context = request.cr, request.uid, request.context - Forum = request.registry['website.forum'] + Forum = request.registry['forum.forum'] obj_ids = Forum.search(cr, uid, [], context=context) forums = Forum.browse(cr, uid, obj_ids, context=context) - return request.website.render("website_forum.forum_index", {'forums': forums}) + return request.website.render("website_forum.forum_all", {'forums': forums}) @http.route('/forum/new', type='http', auth="user", multilang=True, website=True) def forum_create(self, forum_name="New Forum", **kwargs): - forum_id = request.registry['website.forum'].create(request.cr, request.uid, { + forum_id = request.registry['forum.forum'].create(request.cr, request.uid, { 'name': forum_name, }, context=request.context) return request.redirect("/forum/%s" % slug(forum_id)) - @http.route(['/forum/<model("website.forum"):forum>', - '/forum/<model("website.forum"):forum>/page/<int:page>', - '/forum/<model("website.forum"):forum>/tag/<model("website.forum.tag"):tag>/questions' + @http.route('/forum/notification_read', type='json', auth="user", multilang=True, methods=['POST'], website=True) + def notification_read(self, **kwargs): + request.registry['mail.message'].set_message_read(request.cr, request.uid, [int(kwargs.get('notification_id'))], read=True, context=request.context) + return True + + @http.route(['/forum/<model("forum.forum"):forum>', + '/forum/<model("forum.forum"):forum>/page/<int:page>', + '/forum/<model("forum.forum"):forum>/tag/<model("forum.tag"):tag>/questions' ], type='http', auth="public", website=True, multilang=True) - def questions(self, forum, tag='', page=1, filters='', sorting='', search='', **searches): + def questions(self, forum, tag=None, page=1, filters='all', sorting='date', search='', **post): cr, uid, context = request.cr, request.uid, request.context - Forum = request.registry['website.forum.post'] + Post = request.registry['forum.post'] user = request.registry['res.users'].browse(cr, uid, uid, context=context) - order = "id desc" - domain = [('forum_id', '=', forum.id), ('parent_id', '=', False)] if search: domain += ['|', ('name', 'ilike', search), ('content', 'ilike', search)] - - #filter questions for tag. if tag: - if not filters: - filters = 'tag' domain += [('tag_ids', 'in', tag.id)] - - if not filters: - filters = 'all' if filters == 'unanswered': - domain += [ ('child_ids', '=', False) ] - if filters == 'followed': - domain += [ ('message_follower_ids', '=', user.partner_id.id) ] + domain += [('child_ids', '=', False)] + elif filters == 'followed': + domain += [('message_follower_ids', '=', user.partner_id.id)] + else: + filters = 'all' - # Note: default sorting should be based on last activity - if not sorting or sorting == 'date': - sorting = 'date' - order = 'write_date desc' if sorting == 'answered': order = 'child_count desc' - if sorting == 'vote': + elif sorting == 'vote': order = 'vote_count desc' + else: + sorting = 'date' + order = 'write_date desc' - step = 10 - question_count = Forum.search(cr, uid, domain, count=True, context=context) - pager = request.website.pager(url="/forum/%s" % slug(forum), total=question_count, page=page, step=step, scope=10) + question_count = Post.search(cr, uid, domain, count=True, context=context) + pager = request.website.pager(url="/forum/%s" % slug(forum), total=question_count, page=page, step=self._post_per_page, scope=self._post_per_page) - obj_ids = Forum.search(cr, uid, domain, limit=step, offset=pager['offset'], order=order, context=context) - question_ids = Forum.browse(cr, uid, obj_ids, context=context) + obj_ids = Post.search(cr, uid, domain, limit=self._post_per_page, offset=pager['offset'], order=order, context=context) + question_ids = Post.browse(cr, uid, obj_ids, context=context) - values = { - 'uid': request.session.uid, - 'total_questions': question_count, + values = self._prepare_forum_values(forum=forum, searches=post) + values.update({ 'question_ids': question_ids, - 'notifications': self._get_notifications(), - 'forum': forum, 'pager': pager, 'tag': tag, 'filters': filters, 'sorting': sorting, 'search': search, - 'searches': searches, - } + }) + return request.website.render("website_forum.forum_index", values) - return request.website.render("website_forum.index", values) + @http.route(['/forum/<model("forum.forum"):forum>/faq'], type='http', auth="public", website=True, multilang=True) + def faq(self, forum, **post): + values = self._prepare_forum_values(forum=forum, searches=dict(), **post) + return request.website.render("website_forum.faq", values) + + @http.route('/forum/get_tags', type='http', auth="public", multilang=True, methods=['GET'], website=True) + def tag_read(self, **post): + tags = request.registry['forum.tag'].search_read(request.cr, request.uid, [], ['name'], context=request.context) + data = [tag['name'] for tag in tags] + return simplejson.dumps(data) - def _get_notifications(self, **kwargs): + @http.route(['/forum/<model("forum.forum"):forum>/tag'], type='http', auth="public", website=True, multilang=True) + def tags(self, forum, page=1, **post): 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} + Tag = request.registry['forum.tag'] + obj_ids = Tag.search(cr, uid, [('forum_id', '=', forum.id)], limit=None, context=context) + tags = Tag.browse(cr, uid, obj_ids, context=context) + values = self._prepare_forum_values(forum=forum, searches={'tags': True}, **post) + values.update({ + 'tags': tags, + }) + return request.website.render("website_forum.tag", values) - @http.route('/forum/notification_read', type='json', auth="user", multilang=True, methods=['POST'], website=True) - 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 + # Questions + # -------------------------------------------------- - @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, - 'notifications': self._get_notifications(), - } - return request.website.render("website_forum.faq", values) + @http.route(['/forum/<model("forum.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() + values = self._prepare_forum_values(forum=forum, searches={}, header={'ask_hide': True}) + return request.website.render("website_forum.ask_question", values) - @http.route(['/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):question>'], type='http', auth="public", website=True, multilang=True) + @http.route('/forum/<model("forum.forum"):forum>/question/new', type='http', auth="user", multilang=True, methods=['POST'], website=True) + def register_question(self, forum, **post): + cr, uid, context = request.cr, request.uid, request.context + Tag = request.registry['forum.tag'] + question_tag_ids = [] + if post.get('question_tags').strip('[]'): + tags = post.get('question_tags').strip('[]').replace('"', '').split(",") + for tag in tags: + tag_ids = Tag.search(cr, uid, [('name', '=', tag)], context=context) + if tag_ids: + question_tag_ids.append((4, tag_ids[0])) + else: + question_tag_ids.append((0, 0, {'name': tag, 'forum_id': forum.id})) + + new_question_id = request.registry['forum.post'].create( + request.cr, request.uid, { + 'forum_id': forum.id, + 'name': post.get('question_name'), + 'content': post.get('content'), + 'tag_ids': question_tag_ids, + }, context=context) + return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), new_question_id)) + + @http.route(['/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>'], type='http', auth="public", website=True, multilang=True) def question(self, forum, question, **post): cr, uid, context = request.cr, request.uid, request.context # increment view counter - request.registry['website.forum.post'].set_viewed(cr, uid, [question.id], context=context) - - #Check that user have answered question or not. - answer_done = False - for answer in question.child_ids: - if answer.user_id.id == request.uid: - answer_done = True + request.registry['forum.post'].set_viewed(cr, SUPERUSER_ID, [question.id], context=context) filters = 'question' - user = request.registry['res.users'].browse(cr, uid, uid, context=None) - values = { + values = self._prepare_forum_values(forum=forum, searches=post) + values.update({ 'question': question, - 'question_data': True, - 'notifications': self._get_notifications(), - 'searches': post, + 'header': {'question_data': True}, 'filters': filters, - 'following': question.message_is_follower, - 'answer_done': answer_done, 'reversed': reversed, - 'forum': forum, - 'user': user, - } + }) return request.website.render("website_forum.post_description_full", values) - @http.route(['/forum/<model("website.forum"):forum>/comment'], type='http', auth="public", methods=['POST'], website=True) - def post_comment(self, forum, post_id, **kwargs): + @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/comment', type='http', auth="public", methods=['POST'], website=True) + def post_comment(self, forum, post, **kwargs): + # tde: fix post / question if not request.session.uid: return login_redirect() 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( - cr, uid, int(post_id), + # TDE FIXME: check that post_id is the question or one of its answers + if request.registry['res.users'].has_group(cr, uid, 'website_mail.group_comment'): + request.registry['forum.post'].message_post( + cr, uid, post.id, body=kwargs.get('comment'), type='comment', subtype='mt_comment', - content_subtype='plaintext', - author_id=user.partner_id.id, context=dict(context, mail_create_nosubcribe=True)) + return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post))) - 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)) - - @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): - 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['mail.message'] - Followers = request.registry['mail.followers'] - Data = request.registry["ir.model.data"] + @http.route('/forum/<int:forum_id>/question/<int:question_id>/toggle_favourite', type='json', auth="user", multilang=True, website=True) + def question_toggle_favorite_tmp(self, forum_id, question_id, **post): + if not request.session.uid: + return {'error': 'anonymous_user'} + # forum = request.registry['forum.forum'].browse(request.cr, request.uid, forum_id, context=request.context) + question = request.registry['forum.post'].browse(request.cr, request.uid, question_id, context=request.context) + # TDE: add check for not public + favourite = False if question.user_favourite else True + print favourite + if favourite: + favourite_ids = [(4, request.uid)] + else: + favourite_ids = [(3, request.uid)] + request.registry['forum.post'].write(request.cr, request.uid, [question.id], {'favourite_ids': favourite_ids}, context=request.context) + print favourite_ids + return favourite - #questions and answers by user. - user_questions, user_answers = [], [] - user_post_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('user_id', '=', user.id), - '|', ('active', '=', False), ('active', '=', True)], context=context) - 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) + @http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>/toggle_favourite', type='json', auth="user", multilang=True, methods=['POST'], website=True) + def question_toggle_favorite(self, forum, question, **post): + # TDE: add check for not public + favourite = False if question.user_favourite else True + if favourite: + favourite_ids = [(4, request.uid)] + else: + favourite_ids = [(3, request.uid)] + request.registry['forum.post'].write( + request.cr, request.uid, [question.id], {'favourite_ids': favourite_ids}, context=request.context) + return favourite - #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) - post_ids = [follower.res_id for follower in Followers.browse(cr, SUPERUSER_ID, obj_ids, context=context)] - 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) + @http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>/ask_for_close', type='http', auth="user", multilang=True, website=True) + def question_ask_for_close(self, forum, question, **post): + cr, uid, context = request.cr, request.uid, request.context + Reason = request.registry['forum.post.reason'] + reason_ids = Reason.search(cr, uid, [], context=context) + reasons = Reason.browse(cr, uid, reason_ids, context) - #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) + values = self._prepare_forum_values(**post) + values.update({ + 'post': question, + 'forum': forum, + 'reasons': reasons, + }) + return request.website.render("website_forum.close_question", values) - #votes which given on users questions and answers. - data = Vote.read_group(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.user_id', '=', user.id)], ["vote"], groupby=["vote"], context=context) - up_votes, down_votes = 0, 0 - 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 + @http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>/edit_answer', type='http', auth="user", website=True, multilang=True) + def question_edit_answer(self, forum, question, **kwargs): + for record in question.child_ids: + if record.create_uid.id == request.uid: + answer = record + break + return werkzeug.utils.redirect("/forum/%s/post/%s/edit" % (slug(forum), slug(answer))) - #Votes which given by users on others questions and answers. - post_votes = Vote.search(cr, uid, [('user_id', '=', user.id)], context=context) - vote_ids = Vote.browse(cr, uid, post_votes, context=context) + @http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>/close', type='http', auth="user", multilang=True, methods=['POST'], website=True) + def question_close(self, forum, question, **post): + request.registry['forum.post'].write(request.cr, request.uid, [question.id], { + 'state': 'close', + 'closed_uid': request.uid, + 'closed_date': datetime.today().strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT), + 'closed_reason_id': post.get('reason_id', False), + }, context=request.context) + return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question))) - #activity by user. - 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)], context=context) - activities = Activity.browse(cr, uid, activity_ids, context=context) + @http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>/reopen', type='http', auth="user", multilang=True, website=True) + def question_reopen(self, forum, question, **kwarg): + request.registry['forum.post'].write(request.cr, request.uid, [question.id], {'state': 'active'}, context=request.context) + return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question))) - posts = {} - 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)) + @http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>/delete', type='http', auth="user", multilang=True, website=True) + def question_delete(self, forum, question, **kwarg): + #instead of unlink record just change 'active' to false so user can undelete it. + request.registry['forum.post'].write(request.cr, request.uid, [question.id], {'active': False}, context=request.context) + return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question))) - post['users'] = 'True' + @http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):question>/undelete', type='http', auth="user", multilang=True, website=True) + def question_undelete(self, forum, question, **kwarg): + request.registry['forum.post'].write(request.cr, request.uid, [question.id], {'active': True}, context=request.context) + return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question))) - values = { - 'uid': uid, - 'user': user, - 'main_object': user, - 'searches': post, - 'forum': forum, - 'questions': user_questions, - 'answers': user_answers, - 'followed': followed, - 'favourite': favourite, - 'total_votes': total_votes, - 'up_votes': up_votes, - 'down_votes': down_votes, - 'activities': activities, - 'posts': posts, - 'vote_post': vote_ids, - 'notifications': self._get_notifications(), - } - return request.website.render("website_forum.user_detail_full", values) + # Post + # -------------------------------------------------- - @http.route(['/forum/<model("website.forum"):forum>/ask'], type='http', auth="public", website=True, multilang=True) - def question_ask(self, forum, **post): + @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/new', type='http', auth="public", multilang=True, methods=['POST'], website=True) + def post_new(self, forum, post, **kwargs): if not request.session.uid: return login_redirect() - user = request.registry['res.users'].browse(request.cr, request.uid, request.uid, context=request.context) - values = { - 'searches': {}, - 'forum': forum, - 'user': user, - 'ask_question': True, - 'notifications': self._get_notifications(), - } - return request.website.render("website_forum.ask_question", values) - - @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): - cr, uid, context = request.cr, request.uid, request.context - create_context = dict(context) - - Tag = request.registry['website.forum.tag'] - question_tags = [] - 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})) - - new_question_id = request.registry['website.forum.post'].create( + request.registry['forum.post'].create( request.cr, request.uid, { - 'user_id': uid, 'forum_id': forum.id, - 'name': question.get('question_name'), - 'content': question.get('content'), - 'tag_idss' : question_tags, - 'state': 'active', - 'active': True, - }, context=create_context) - return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),new_question_id)) - - @http.route('/forum/<model("website.forum"):forum>/question/postanswer', type='http', auth="public", multilang=True, methods=['POST'], website=True) - def post_answer(self, forum , post_id, **question): - if not request.session.uid: - return login_redirect() + 'parent_id': post.id, + 'content': kwargs.get('content'), + }, context=request.context) + return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post))) + @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/toggle_correct', type='json', auth="public", website=True) + def post_toggle_correct(self, form, post, **kwargs): cr, uid, context = request.cr, request.uid, request.context - - create_context = dict(context) - new_question_id = request.registry['website.forum.post'].create( - cr, uid, { - 'forum_id': forum.id, - 'user_id': uid, - 'parent_id': post_id, - 'content': question.get('content'), - 'state': 'active', - 'active': True, - }, context=create_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"):question>/editanswer'] - , type='http', auth="user", website=True, multilang=True) - def edit_answer(self, forum, question, **kwargs): - for record in question.child_ids: - if record.user_id.id == request.uid: - answer = record - 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): + if not request.session.uid: + return {'error': 'anonymous_user'} + # user = request.registry['res.users'].browse(cr, uid, uid, context=None) + + # # if user have not access to accept answer then reise warning + # if not (post.parent_id.create_uid.id == uid or user.karma >= 500): + # return {'error': 'user'} + + # set all answers to False, only one can be accepted + request.registry['forum.post'].write(cr, uid, [c.id for c in post.parent_id.child_ids], {'is_correct': False}, context=context) + request.registry['forum.post'].write(cr, uid, [post.id, post.parent_id.id], {'is_correct': not post.correct}, context=context) + return not post.correct + + @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/delete', type='http', auth="user", multilang=True, website=True) + def post_delete(self, forum, post, **kwargs): + question = post.parent_id + request.registry['forum.post'].unlink(request.cr, request.uid, [post.id], context=request.context) + if question: + werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question))) + return werkzeug.utils.redirect("/forum/%s" % slug(forum)) + + @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/edit', type='http', auth="user", website=True, multilang=True) + def post_edit(self, forum, post, **kwargs): cr, uid, context = request.cr, request.uid, request.context - User = request.registry['res.users'] - user = User.browse(cr, uid, uid, context=context) - tags = "" - for tag_name in question.tag_ids: + for tag_name in post.tag_ids: tags += tag_name.name + "," - values = { - 'question': question, - 'user': user, + values = self._prepare_forum_values(forum=forum) + values.update({ + 'question': post.parent_id, 'tags': tags, - 'answer': answer, - 'is_answer': True if answer else False, - 'notifications': self._get_notifications(), - 'forum': forum, + 'answer': post, + 'is_answer': True if post else False, 'searches': kwargs - } + }) return request.website.render("website_forum.edit_post", values) - @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): + @http.route('/forum/<model("forum.forum"):forum>/post/save', type='http', auth="user", multilang=True, methods=['POST'], website=True) + def post_save(self, forum, **post): cr, uid, context = request.cr, request.uid, request.context vals = { 'content': post.get('content'), } question_tags = [] if post.get('question_tag') and post.get('question_tag').strip('[]'): - Tag = request.registry['website.forum.tag'] + Tag = request.registry['forum.tag'] tags = post.get('question_tag').strip('[]').replace('"','').split(",") for tag in tags: tag_ids = Tag.search(cr, uid, [('name', '=', tag)], context=context) @@ -366,190 +358,150 @@ class WebsiteForum(http.Controller): vals.update({'tag_ids': [(6, 0, question_tags)], 'name': post.get('question_name')}) 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) + new_question_id = request.registry['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'))) - @http.route(['/forum/<model("website.forum"):forum>/tag'], type='http', auth="public", website=True, multilang=True) - def tags(self, forum, page=1, **searches): - cr, uid, context = request.cr, request.uid, request.context - Tag = request.registry['website.forum.tag'] - obj_ids = Tag.search(cr, uid, [('forum_id', '=', forum.id)], limit=None, context=context) - tags = Tag.browse(cr, uid, obj_ids, context=context) - values = { - 'tags': tags, - 'notifications': self._get_notifications(), - 'forum': forum, - 'searches': {'tags': True} - } - return request.website.render("website_forum.tag", values) + @http.route('/forum/<int:forum_id>/post/<int:post_id>/upvote', type='json', auth="public", multilang=True, website=True) + def post_upvote_tmp(self, forum_id, post_id, **kwargs): + if not request.session.uid: + return {'error': 'anonymous_user'} + # forum = request.registry['forum.forum'].browse(request.cr, request.uid, forum_id, context=request.context) + post = request.registry['forum.post'].browse(request.cr, request.uid, post_id, context=request.context) + return request.registry['forum.post'].vote(request.cr, request.uid, [post.id], upvote=True, context=request.context) - @http.route(['/forum/<model("website.forum"):forum>/badge'], 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, [('level', '!=', False)], context=context) - badges = Badge.browse(cr, uid, badge_ids, context=context) - values = { - 'badges': badges, - 'notifications': {}, - 'forum': forum, - 'searches': {'badges': True} - } - return request.website.render("website_forum.badge", values) + @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/upvote', type='json', auth="public", multilang=True, website=True) + def post_vote(self, forum, post, **kwargs): + if not request.session.uid: + return {'error': 'anonymous_user'} + return request.registry['forum.post'].vote(request.cr, request.uid, [post.id], upvote=True, context=request.context) - @http.route(['/forum/<model("website.forum"):forum>/badge/<model("gamification.badge"):badge>'], type='http', auth="public", website=True, multilang=True) - def badge_users(self, forum, badge, **kwargs): - users = [badge_user.user_id for badge_user in badge.owner_ids] - kwargs['badges'] = 'True' + @http.route('/forum/<int:forum_id>/post/<int:post_id>/downvote', type='json', auth="public", multilang=True, website=True) + def post_downvote_tmp(self, forum_id, post_id, **kwargs): + if not request.session.uid: + return {'error': 'anonymous_user'} + # forum = request.registry['forum.forum'].browse(request.cr, request.uid, forum_id, context=request.context) + post = request.registry['forum.post'].browse(request.cr, request.uid, post_id, context=request.context) + return request.registry['forum.post'].vote(request.cr, request.uid, [post.id], upvote=False, context=request.context) - values = { - 'badge': badge, - 'notifications': {}, - 'users': users, - 'forum': forum, - 'searches': kwargs - } - return request.website.render("website_forum.badge_user", values) + @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/downvote', type='json', auth="public", multilang=True, website=True) + def post_downvote(self, forum, post, **kwargs): + if not request.session.uid: + return {'error': 'anonymous_user'} + return request.registry['forum.post'].vote(request.cr, request.uid, [post.id], upvote=False, context=request.context) + + # User + # -------------------------------------------------- - @http.route(['/forum/<model("website.forum"):forum>/users', '/forum/users/page/<int:page>'], type='http', auth="public", website=True, multilang=True) + @http.route('/forum/<model("forum.forum"):forum>/users', type='http', auth="public", website=True, multilang=True) def users(self, forum, page=1, **searches): cr, uid, context = request.cr, request.uid, request.context User = request.registry['res.users'] step = 30 - tag_count = User.search(cr, uid, [('karma', '>', 1)], count=True, context=context) + tag_count = User.search(cr, SUPERUSER_ID, [('karma', '>', 1)], count=True, context=context) pager = request.website.pager(url="/forum/users", total=tag_count, page=page, step=step, scope=30) - obj_ids = User.search(cr, uid, [('karma', '>', 1)], limit=step, offset=pager['offset'], context=context) - users = User.browse(cr, uid, obj_ids, context=context) + obj_ids = User.search(cr, SUPERUSER_ID, [('karma', '>', 1)], limit=step, offset=pager['offset'], context=context) + users = User.browse(cr, SUPERUSER_ID, obj_ids, context=context) searches['users'] = 'True' - values = { + values = self._prepare_forum_values(forum=forum, searches=searches) + values .update({ 'users': users, 'notifications': self._get_notifications(), 'pager': pager, - 'forum': forum, - 'searches': searches, - } + }) return request.website.render("website_forum.users", values) - @http.route('/forum/post_vote', type='json', auth="public", multilang=True, methods=['POST'], website=True) - def post_vote(self, **post): - if not request.session.uid: - return {'error': 'anonymous_user'} - cr, uid, context, post_id = request.cr, request.uid, request.context, int(post.get('post_id')) - return request.registry['website.forum.post'].vote(cr, uid, [post_id], upvote=(post.get('vote') == '1'), context=context) - - @http.route('/forum/post_delete', type='json', auth="user", multilang=True, methods=['POST'], website=True) - def delete_answer(self, **kwarg): - request.registry['website.forum.post'].unlink(request.cr, request.uid, [int(kwarg.get('post_id'))], context=request.context) - return True - - @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): - #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("forum.forum"):forum>/user/<int:user_id>'], type='http', auth="public", website=True, multilang=True) + def open_user(self, forum, user_id=0, **post): + cr, uid, context = request.cr, request.uid, request.context + User = request.registry['res.users'] + Post = request.registry['forum.post'] + Vote = request.registry['forum.post.vote'] + Activity = request.registry['mail.message'] + Followers = request.registry['mail.followers'] + Data = request.registry["ir.model.data"] - @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)) + user_id = User.search(cr, SUPERUSER_ID, [('id', '=', user_id), ('karma', '>', '1')], context=context) + if not user_id: + return werkzeug.utils.redirect("/forum/%s" % slug(forum)) + user = User.browse(cr, SUPERUSER_ID, user_id[0], context=context) - @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, SUPERUSER_ID, [int(kwarg.get('message_id'))], context=request.context) - return True + # questions and answers by user + user_questions, user_answers = [], [] + user_post_ids = Post.search( + cr, uid, [ + ('forum_id', '=', forum.id), ('create_uid', '=', user.id), + '|', ('active', '=', False), ('active', '=', True)], context=context) + 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) - @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 + # showing questions which user following + obj_ids = Followers.search(cr, SUPERUSER_ID, [('res_model', '=', 'forum.post'), ('partner_id', '=', user.partner_id.id)], context=context) + post_ids = [follower.res_id for follower in Followers.browse(cr, SUPERUSER_ID, obj_ids, context=context)] + 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) - @http.route('/forum/correct_answer', type='json', auth="public", multilang=True, methods=['POST'], website=True) - def correct_answer(self, **kwarg): - cr, uid, context = request.cr, request.uid, request.context - if not request.session.uid: - return {'error': 'anonymous_user'} + #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) - Post = request.registry['website.forum.post'] - post = Post.browse(cr, uid, int(kwarg.get('post_id')), context=context) - user = request.registry['res.users'].browse(cr, uid, uid, context=None) + #votes which given on users questions and answers. + data = Vote.read_group(cr, uid, [('post_id.forum_id', '=', forum.id), ('post_id.create_uid', '=', user.id)], ["vote"], groupby=["vote"], context=context) + up_votes, down_votes = 0, 0 + 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 - #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'} + #Votes which given by users on others questions and answers. + post_votes = Vote.search(cr, uid, [('user_id', '=', user.id)], context=context) + vote_ids = Vote.browse(cr, uid, post_votes, context=context) - #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 + #activity by user. + model, comment = Data.get_object_reference(cr, uid, 'mail', 'mt_comment') + activity_ids = Activity.search(cr, uid, [('res_id', 'in', user_post_ids), ('model', '=', 'forum.post'), ('subtype_id', '!=', comment)], context=context) + activities = Activity.browse(cr, uid, activity_ids, context=context) - @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 + posts = {} + 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)) - @http.route('/forum/<model("website.forum"):forum>/close/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True) - def close_question(self, forum, post, **kwarg): - 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) + post['users'] = 'True' - values = { - 'post': post, + values = self._prepare_forum_values(**post) + values.update({ + 'uid': uid, + 'user': user, + 'main_object': user, + 'searches': post, 'forum': forum, - 'searches': kwarg, - 'reasons': reasons, - 'notifications': self._get_notifications(), - } - return request.website.render("website_forum.close_question", values) - - @http.route('/forum/<model("website.forum"):forum>/question/close', type='http', auth="user", multilang=True, methods=['POST'], website=True) - def close(self, forum, **post): - 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), - 'reason_id': post.get('reason'), - }, context=request.context) - return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id'))) - - @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)) + 'questions': user_questions, + 'answers': user_answers, + 'followed': followed, + 'favourite': favourite, + 'total_votes': total_votes, + 'up_votes': up_votes, + 'down_votes': down_votes, + 'activities': activities, + 'posts': posts, + 'vote_post': vote_ids, + }) + return request.website.render("website_forum.user_detail_full", values) - @http.route('/forum/<model("website.forum"):forum>/edit/profile/<model("res.users"):user>', type='http', auth="user", multilang=True, website=True) + @http.route('/forum/<model("forum.forum"):forum>/user/<model("res.users"):user>/edit', type='http', auth="user", multilang=True, website=True) def edit_profile(self, forum, user, **kwarg): - cr,context = request.cr, request.context + 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) @@ -562,7 +514,7 @@ class WebsiteForum(http.Controller): } 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) + @http.route('/forum/<model("forum.forum"):forum>/user/<model("res.users"):user>/save', type='http', auth="user", multilang=True, website=True) def save_edited_profile(self, forum, **post): cr, uid, context = request.cr, request.uid, request.context user = request.registry['res.users'].browse(cr, uid, int(post.get('user_id')),context=context) @@ -576,45 +528,55 @@ class WebsiteForum(http.Controller): }, context=context) return werkzeug.utils.redirect("/forum/%s/user/%s" % (slug(forum),post.get('user_id'))) - @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) - def convert_to_answer(self, forum, post, comment, **kwarg): + # Badges + # -------------------------------------------------- + + @http.route(['/forum/<model("forum.forum"):forum>/badge'], 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, [('level', '!=', False)], context=context) + badges = Badge.browse(cr, uid, badge_ids, context=context) + values = self._prepare_forum_values(forum=forum, searches={'badges': True}) + values.update({ + 'badges': badges, + }) + return request.website.render("website_forum.badge", values) + + @http.route(['/forum/<model("forum.forum"):forum>/badge/<model("gamification.badge"):badge>'], type='http', auth="public", website=True, multilang=True) + def badge_users(self, forum, badge, **kwargs): + user_ids = [badge_user.user_id.id for badge_user in badge.owner_ids] + users = request.registry['res.users'].browse(request.cr, SUPERUSER_ID, user_ids, context=request.context) + kwargs['badges'] = 'True' + + values = self._prepare_forum_values(forum=forum) + values.update({ + 'badge': badge, + 'users': users, + }) + return request.website.render("website_forum.badge_user", values) + + # Messaging + # -------------------------------------------------- + + @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/comment/<model("mail.message"):comment>/convert_to_answer', type='http', auth="public", multilang=True, website=True) + def convert_comment_to_answer(self, forum, post, comment, **kwarg): values = { 'content': comment.body, } 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) - @http.route('/forum/<model("website.forum"):forum>/post/<model("website.forum.post"):post>/converttocomment', type='http', auth="user", multilang=True, website=True) - def convert_to_comment(self, forum, post, **kwarg): + @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/convert_to_comment', type='http', auth="user", multilang=True, website=True) + def convert_answer_to_comment(self, forum, post, **kwarg): values = { 'comment': html2plaintext(post.content), } - question = post.parent_id.id - request.registry['website.forum.post'].unlink(request.cr, SUPERUSER_ID, [post.id], context=request.context) + question = post.parent_id + request.registry['forum.post'].unlink(request.cr, SUPERUSER_ID, [post.id], context=request.context) return self.post_comment(forum, question, **values) - @http.route('/forum/get_tags', type='http', auth="public", multilang=True, methods=['GET'], website=True) - def tag_read(self, **kwarg): - 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) - - @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)) + @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, SUPERUSER_ID, [int(kwarg.get('message_id'))], context=request.context) + return True diff --git a/addons/website_forum/data/badges_answer.xml b/addons/website_forum/data/badges_answer.xml index bc4af4700c5..547bf4c4ff9 100644 --- a/addons/website_forum/data/badges_answer.xml +++ b/addons/website_forum/data/badges_answer.xml @@ -15,7 +15,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 3)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 3)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_teacher"> @@ -45,7 +45,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 4)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 4)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_nice_answer"> @@ -75,7 +75,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 6)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 6)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_good_answer"> @@ -105,7 +105,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 15)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 15)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_great_answer"> @@ -137,7 +137,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')"/> - <field name="domain">[('user_id', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 3), ('is_correct', '=', True)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 3), ('is_correct', '=', True)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_enlightened"> @@ -167,7 +167,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 15), ('is_correct', '=', True)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '!=', False), ('vote_count', '>=', 15), ('is_correct', '=', True)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_guru"> @@ -199,7 +199,7 @@ <field name="compute_code">def get_posts(cr, uid, context=None): res = 1 Post = self.pool['website.forum.post'] - user_posts = Post.search(cr, uid, [('user_id','=',object.user_id.id), ('parent_id', '!=', False), ('vote_count', '>=', 2)], context=context) + user_posts = Post.search(cr, uid, [('create_uid','=',object.user_id.id), ('parent_id', '!=', False), ('vote_count', '>=', 2)], context=context) for post in Post.browse(cr, uid, user_posts, context=context): print post.parent_id.create_date question_date = datetime.strptime(post.parent_id.create_date, "%Y-%m-%d %H:%M:%S") @@ -240,7 +240,7 @@ result = get_posts(cr, uid, context=context) <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id', '=', user.id), ('parent_id', '!=', False), ('parent_id.user_id', '=', user.id), ('vote_count', '>=', 3)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '!=', False), ('parent_id.create_uid', '=', user.id), ('vote_count', '>=', 3)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_self_learner"> diff --git a/addons/website_forum/data/badges_moderation.xml b/addons/website_forum/data/badges_moderation.xml index dde6bd30196..acb49e00597 100644 --- a/addons/website_forum/data/badges_moderation.xml +++ b/addons/website_forum/data/badges_moderation.xml @@ -45,7 +45,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post_vote')"/> - <field name="domain">[('user_id', '=', user.id), ('vote', '=', '-1')]</field> + <field name="domain">[('create_uid', '=', user.id), ('vote', '=', '-1')]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_critic"> @@ -76,7 +76,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id', '=', user.id), ('vote_count', '>=', 3), ('active', '=', False)]</field> + <field name="domain">[('create_uid', '=', user.id), ('vote_count', '>=', 3), ('active', '=', False)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_disciplined"> @@ -107,7 +107,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('mail.model_mail_message')" /> - <field name="domain">[('user_id','=',user.id), '|', ('name','!=',False), ('content','!=',False)]</field> + <field name="domain">[('create_uid','=',user.id), '|', ('name','!=',False), ('content','!=',False)]</field> <field name="domain" eval="[('author_id', '=', user.partner_id.id), ('model', '=', 'forum.post'), ('subtype_id', 'in', [ref('website_forum.mt_answer_edit'), ref('website_forum.mt_question_edit')])]"/> <field name="condition">higher</field> </record> @@ -140,7 +140,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_website_forum_post_history')" /> - <field name="domain">[('user_id','=',user.id), ('tags','!=',False)]</field> + <field name="domain">[('create_uid','=',user.id), ('tags','!=',False)]</field> <field name="condition">higher</field> </record> --> @@ -176,7 +176,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_website_forum_post_history')" /> - <field name="domain">[('user_id','=',user.id), '|', ('name','!=',False), ('content','!=',False)]</field> + <field name="domain">[('create_uid','=',user.id), '|', ('name','!=',False), ('content','!=',False)]</field> <field name="condition">higher</field> </record> --> @@ -211,8 +211,7 @@ end_date = date.today() - timedelta(days=1) cr.execute('SELECT COUNT(id), create_date from forum_post_vote where create_date >= %s and create_date <= %s and user_id = %s GROUP BY create_date',(start_date,end_date, object.user_id.id,)) data = cr.dictfetchall() -result = int(len(data) >= 15) - </field> +result = int(len(data) >= 15)</field> <field name="display_mode">boolean</field> <field name="condition">higher</field> </record> @@ -278,7 +277,7 @@ result = int(len(data) >= 15) <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id','=',user.id), ('vote_count', '<=', -3), ('active', '=', False)]</field> + <field name="domain">[('create_uid','=',user.id), ('vote_count', '<=', -3), ('active', '=', False)]</field> <field name="condition">higher</field> </record> diff --git a/addons/website_forum/data/badges_question.xml b/addons/website_forum/data/badges_question.xml index d012fdb7734..90ee9b3ecf3 100644 --- a/addons/website_forum/data/badges_question.xml +++ b/addons/website_forum/data/badges_question.xml @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<!-- <?xml version="1.0" encoding="utf-8"?> --> <openerp> <data> @@ -107,7 +107,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('favorite_count', '>=', 1)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('favourite_count', '>=', 1)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_favorite_question"> @@ -137,7 +137,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('favorite_count', '>=', 5)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('favourite_count', '>=', 5)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_favorite_question"> @@ -167,7 +167,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('favorite_count', '>=', 25)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('favourite_count', '>=', 25)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_stellar_question"> @@ -199,7 +199,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id', '=', user.id), ('parent_id', '=', False), ('vote_count', '>=', 1)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('vote_count', '>=', 1)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_student"> @@ -229,7 +229,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')"/> - <field name="domain">[('user_id','=',user.id), ('parent_id', '=', False), ('vote_count', '>=', 4)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('vote_count', '>=', 4)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_nice_question"> @@ -259,7 +259,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id', '=', user.id), ('parent_id', '=', False), ('vote_count', '>=', 6)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('vote_count', '>=', 6)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_good_question"> @@ -289,7 +289,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id','=',user.id), ('parent_id', '=', False), ('vote_count', '>=', 15)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('vote_count', '>=', 15)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_great_question"> @@ -320,7 +320,7 @@ <field name="computation_mode">count</field> <field name="display_mode">boolean</field> <field name="model_id" eval="ref('website_forum.model_forum_post')" /> - <field name="domain">[('user_id','=',user.id), ('parent_id', '=', False), ('is_correct', '=', True)]</field> + <field name="domain">[('create_uid', '=', user.id), ('parent_id', '=', False), ('is_correct', '=', True)]</field> <field name="condition">higher</field> </record> <record model="gamification.challenge" id="challenge_scholar"> diff --git a/addons/website_forum/data/forum_demo.xml b/addons/website_forum/data/forum_demo.xml index 57cf87d4f08..fe8e21619ba 100644 --- a/addons/website_forum/data/forum_demo.xml +++ b/addons/website_forum/data/forum_demo.xml @@ -26,7 +26,6 @@ <field name="forum_id" ref="website_forum.forum_help"/> <field name="views">5</field> <field name="tag_ids" eval="[(4,ref('website_forum.tags_0')),(4,ref('website_forum.tags_1')),(4,ref('website_forum.tags_2'))]"/> - <field name="user_id" ref="base.user_root"/> </record> <record id="question_1" model="forum.post"> <field name="name">CMS replacement for ERP and eCommerce</field> @@ -38,7 +37,6 @@ Can I use OpenERP as a replacement CMS of Wordpress + eCommerce plugin? In simple words does OpenERP became CMS+ERP platform?</field> <field name="tag_ids" eval="[(4,ref('website_forum.tags_3'))]"/> - <field name="user_id" ref="base.user_demo"/> </record> <!-- Answer --> @@ -53,7 +51,7 @@ In simple words does OpenERP became CMS+ERP platform?</field> Step 5. Go to Scheduled Actions.. Set interval number to 1. Interval Unit to Minutes. Then Set the Next Execution date to 2 minutes from now. If your SMTP is configured correctly you will start to get a mail every minute with the reminder. </field> <field name="parent_id" ref="question_0" /> - <field name="user_id" ref="base.user_root"/> + <field name="create_uid" ref="base.user_root"/> </record> <record id="answer_1" model="forum.post"> <field name="forum_id" ref="website_forum.forum_help"/> @@ -61,7 +59,7 @@ In simple words does OpenERP became CMS+ERP platform?</field> The CMS editor in OpernERP web is nice but I prefer drupal for customization and there is a drupal module for OpenERP. I think WP is better than OpenERP web too. </field> <field name="parent_id" ref="question_1"/> - <field name="user_id" ref="base.user_root"/> + <field name="create_uid" ref="base.user_root"/> </record> <!-- Post Vote --> diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py index 4388c77e951..4c1e6c42040 100644 --- a/addons/website_forum/models/forum.py +++ b/addons/website_forum/models/forum.py @@ -65,14 +65,14 @@ class Post(osv.Model): def _get_user_favourite(self, cr, uid, ids, field_name, arg, context): res = dict.fromkeys(ids, False) for post in self.browse(cr, uid, ids, context=context): - if uid in [f.user_id.id for f in post.favourite_ids]: + if uid in [f.id for f in post.favourite_ids]: res[post.id] = True return res def _get_favorite_count(self, cr, uid, ids, field_name, arg, context): res = dict.fromkeys(ids, 0) for post in self.browse(cr, uid, ids, context=context): - res[post.id] += len(post.favorite_ids) + res[post.id] += len(post.favourite_ids) return res def _get_post_from_hierarchy(self, cr, uid, ids, context=None): @@ -91,6 +91,12 @@ class Post(osv.Model): res[post.id] = len(post.child_ids) return res + def _get_uid_answered(self, cr, uid, ids, field_name, arg, context=None): + res = dict.fromkeys(ids, False) + for post in self.browse(cr, uid, ids, context=context): + res[post.id] = any(answer.create_uid.id == uid for answer in post.child_ids) + return res + _columns = { 'name': fields.char('Title', size=128), 'forum_id': fields.many2one('forum.forum', 'Forum', required=True), @@ -122,12 +128,12 @@ class Post(osv.Model): 'forum.post.vote': (_get_post_from_vote, [], 10), }), # favorite fields - 'favourite_ids': fields.many2many('res.users', 'Favourite'), + 'favourite_ids': fields.many2many('res.users', string='Favourite'), 'user_favourite': fields.function(_get_user_favourite, string="My Favourite", type='boolean'), - 'favorite_count': fields.function( + 'favourite_count': fields.function( _get_favorite_count, string='Favorite Count', type='integer', store={ - 'forum.post': (lambda self, cr, uid, ids, c={}: ids, ['favorite_ids'], 10), + 'forum.post': (lambda self, cr, uid, ids, c={}: ids, ['favourite_ids'], 10), }), # hierarchy 'parent_id': fields.many2one('forum.post', 'Question', ondelete='cascade'), @@ -137,6 +143,9 @@ class Post(osv.Model): store={ 'forum.post': (_get_post_from_hierarchy, ['parent_id', 'child_ids'], 10), }), + 'uid_has_answered': fields.function( + _get_uid_answered, string='Has Answered', type='boolean', + ), # closing 'closed_reason_id': fields.many2one('forum.post.reason', 'Reason'), 'closed_uid': fields.many2one('res.users', 'Closed by', select=1), @@ -195,8 +204,8 @@ class Post(osv.Model): return {'error': 'lessthen_10_karma'} # user can not vote on own post posts = self.browse(cr, uid, ids, context=context) - if any(post.create_uid.id == uid for post in posts): - return {'error': 'own_post'} + # if any(post.create_uid.id == uid for post in posts): + # return {'error': 'own_post'} vote_ids = Vote.search(cr, uid, [('post_id', 'in', ids), ('user_id', '=', uid)], context=context) if vote_ids: diff --git a/addons/website_forum/static/src/css/Makefile b/addons/website_forum/static/src/css/Makefile index 867a1fedb38..ceee4ae3f7a 100644 --- a/addons/website_forum/static/src/css/Makefile +++ b/addons/website_forum/static/src/css/Makefile @@ -1,2 +1,5 @@ -sass: - sass --compass --unix-newlines -t expanded website_forum.sass:website_forum.css +all: website_forum.css +%.css: %.sass + sass -t expanded --compass --unix-newlines $< $@ +watch: + sass -t expanded --compass --unix-newlines --watch .:. diff --git a/addons/website_forum/static/src/css/website_forum.css b/addons/website_forum/static/src/css/website_forum.css index 6548e8d01b1..e83242c1484 100644 --- a/addons/website_forum/static/src/css/website_forum.css +++ b/addons/website_forum/static/src/css/website_forum.css @@ -1,17 +1,16 @@ .box { padding-left: 8px; padding-right: 8px; + margin-left: 4px; + margin-right: 4px; border-radius: 4px; + min-width: 80px; } .box span { font-size: 200%; font-weight: bold; } -.question div.pull-left { - margin-right: 14px; - min-width: 80px; -} .question .question-name { font-size: 150%; } @@ -64,13 +63,11 @@ a.no-decoration { } .oe_comment_grey { - -moz-box-shadow: 0px 4px 6px 2px #eeeeee; - -webkit-box-shadow: 0px 4px 6px 2px #eeeeee; - box-shadow: 0px 4px 6px 2px #eeeeee; + color: whitesmoke; } -.forum_user_flag { - max-width: 25px; +.country_flag { + max-height: 16px; display: inline-block; margin-left: 2px; } diff --git a/addons/website_forum/static/src/css/website_forum.sass b/addons/website_forum/static/src/css/website_forum.sass index 555250bd6f3..d3c239b7dc4 100644 --- a/addons/website_forum/static/src/css/website_forum.sass +++ b/addons/website_forum/static/src/css/website_forum.sass @@ -1,15 +1,15 @@ .box padding-left: 8px padding-right: 8px + margin-left: 4px + margin-right: 4px border-radius: 4px + min-width: 80px span font-size: 200% font-weight: bold .question - div.pull-left - margin-right: 14px - min-width: 80px .question-name font-size: 150% @@ -52,8 +52,8 @@ a.no-decoration .oe_comment_grey color: #f5f5f5 -.forum_user_flag - max-width: 25px +.country_flag + max-height: 16px display: inline-block margin-left: 2px diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index 907e5d47a01..202b0a7d90d 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -3,11 +3,11 @@ $(document).ready(function () { $('.vote_up ,.vote_down').on('click', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); - var value = $link.attr("value") - - openerp.jsonRpc("/forum/post_vote", 'call', { - 'post_id': $link.attr("id"), - 'vote': value}) + var url_target = $link.data("value") == '1' ? 'upvote' : 'downvote'; + var forum_id = $link.data('forum-id'); + var post_id = $link.data('post-id'); + + openerp.jsonRpc("/forum/" + forum_id + "/post/" + post_id + "/" + url_target, 'call', {}) .then(function (data) { if (data['error']){ if (data['error'] == 'own_post'){ @@ -38,7 +38,7 @@ $(document).ready(function () { $link.parent().find(".text-success").removeClass("text-success"); $link.parent().find(".text-warning").removeClass("text-warning"); } else { - if (value == 1) { + if (data['vote_count'] == 1) { $link.addClass("text-success"); } else { $link.addClass("text-warning"); @@ -49,75 +49,65 @@ $(document).ready(function () { return true; }); - $('.delete').on('click', function (ev) { - ev.preventDefault(); - var $link = $(ev.currentTarget); - openerp.jsonRpc("/forum/post_delete", 'call', { - 'post_id': $link.attr("id")}) - .then(function (data) { - $("div#answer_" + $link.attr('id')).remove(); - }); - return false; - }); - $('.accept_answer').on('click', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); - openerp.jsonRpc("/forum/correct_answer", 'call', { - 'post_id': $link.attr("id")}) - .then(function (data) { - if (data['error']) { - if (data['error'] == 'anonymous_user'){ - var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+ - '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+ - 'Sorry, anonymous users cannot choose correct answer.'+ - '</div>'); - } else if (data['error'] == 'user'){ - var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+ - '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+ - 'Sorry, the user who asked this question can only accept the answer as correct.'+ - '</div>'); - } - correct_answer_alert = $link.parent().find("#correct_answer_alert"); - if (correct_answer_alert.length == 0) { - $link.parent().append($warning); - } - } else { - $link.parents().find(".oe_answer_true").removeClass("oe_answer_true alert alert-info").addClass('oe_answer_false'); - $link.parents().find(".answer_correct").removeClass("answer_correct alert alert-info") - if (data) { - $link.removeClass("oe_answer_false").addClass('oe_answer_true'); - $("div#answer_" + $link.attr('id')).addClass("answer_correct alert alert-info"); - console.log("aaaaa",$("div#answer_" + $link.attr('id'))) - } + var forum_id = $link.data('forum-id'); + var post_id = $link.data('post-id'); + openerp.jsonRpc("/forum/" + forum_id + "/post/" + post_id + "/toggle_correct", 'call', {}).then(function (data) { + if (data['error']) { + if (data['error'] == 'anonymous_user'){ + var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+ + '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+ + 'Sorry, anonymous users cannot choose correct answer.'+ + '</div>'); + } else if (data['error'] == 'user'){ + var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+ + '<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+ + 'Sorry, the user who asked this question can only accept the answer as correct.'+ + '</div>'); } - }); + correct_answer_alert = $link.parent().find("#correct_answer_alert"); + if (correct_answer_alert.length == 0) { + $link.parent().append($warning); + } + } else { + $link.parents().find(".oe_answer_true").removeClass("oe_answer_true alert alert-info").addClass('oe_answer_false'); + $link.parents().find(".answer_correct").removeClass("answer_correct alert alert-info") + if (data) { + $link.removeClass("oe_answer_false").addClass('oe_answer_true'); + $("div#answer_" + $link.attr('id')).addClass("answer_correct alert alert-info"); + console.log("aaaaa",$("div#answer_" + $link.attr('id'))) + } + } + }); return true; }); $('.favourite_question').on('click', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); - openerp.jsonRpc("/forum/favourite_question", 'call', { - 'post_id': $link.attr("id")}) - .then(function (data) { - if (data) { - $link.addClass("forum_favourite_question") - } else { - $link.removeClass("forum_favourite_question") - } - }); + var forum_id = $link.data('forum-id'); + var post_id = $link.data('post-id'); + openerp.jsonRpc("/forum/" + forum_id + "/question/" + post_id + "/toggle_favourite", 'call', {}).then(function (data) { + if (data) { + $link.addClass("forum_favourite_question") + } else { + $link.removeClass("forum_favourite_question") + } + }); return true; }); $('.comment_delete').on('click', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); - openerp.jsonRpc("/forum/message_delete", 'call', { - 'message_id': $link.attr("id")}) - .then(function (data) { - $link.parents('#comment').remove(); - }); + var forum_id = $link.data('forum-id'); + var post_id = $link.data('post-id'); + var message_id = $link.data('message-id'); + openerp.jsonRpc("/forum/message_delete", 'call', {}).then(function (data) { + $link.parents('#comment').remove(); + }); return true; }); @@ -155,20 +145,6 @@ $(document).ready(function () { }); } - $('.post_history').change(function (ev) { - var $option = $(ev.currentTarget); - openerp.jsonRpc("/forum/selecthistory", 'call', { - 'history_id': $option.attr("value")}) - .then(function (data) { - var $input = $('<input type="text" name="question_tag" class="form-control col-md-9 load_tags" placeholder="Tags"/>') - $option.parent().find(".text-core").replaceWith($input); - set_tags(data['tags']); - $option.parent().find("#question_name").attr('value', data['name']); - CKEDITOR.instances['content'].setData(data['content']) - }) - return true; - }); - if ($('textarea.load_editor').length) { var editor = CKEDITOR.instances['content']; editor.on('instanceReady', CKEDITORLoadComplete); diff --git a/addons/website_forum/views/ir_qweb.xml b/addons/website_forum/views/ir_qweb.xml new file mode 100644 index 00000000000..04188b54234 --- /dev/null +++ b/addons/website_forum/views/ir_qweb.xml @@ -0,0 +1,24 @@ +<openerp> +<data> +<template id="contact" inherit_id="base.contact" name="Forum Contact Widget"> + <xpath expr="//div[@itemprop='address']" position="after"> + <div> + <div t-if="'karma' in fields" class='css_editable_mode_hidden'> + <b><t t-esc="object.karma"/></b> + <div t-if="options.get('badges')" style="display: inline-block"> + <t t-raw="separator"/> + <b>|</b> + <span class="fa fa-circle badge-gold"/> + <t t-esc="object.gold_badge"/> + <span class="fa fa-circle badge-silver"/> + <t t-esc="object.silver_badge"/> + <span class="fa fa-circle badge-bronze"/> + <t t-esc="object.bronze_badge"/> + </div> + <t t-raw="0"/> + </div> + </div> + </xpath> +</template> + </data> +</openerp> diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index bcfa4447537..dc2d7e36834 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -2,898 +2,907 @@ <openerp> <data> - <template id="editor_head" inherit_id="website.editor_head" - name="Event Editor"> - <xpath expr="//script[@id='website_tour_js']" position="after"> - <script type="text/javascript" - src="/website_forum/static/src/js/website.tour.forum.js"/> - <script type="text/javascript" - src="/website_forum/static/src/js/website_forum.editor.js"/> - </xpath> - </template> +<!-- Editor custo --> +<template id="editor_head" inherit_id="website.editor_head" + name="Event Editor"> + <xpath expr="//script[@id='website_tour_js']" position="after"> + <script type="text/javascript" src="/website_forum/static/src/js/website.tour.forum.js"/> + <script type="text/javascript" src="/website_forum/static/src/js/website_forum.editor.js"/> + </xpath> +</template> - <!-- Layout add nav and footer --> - <template id="header_footer_custom" inherit_id="website.layout" - name="Footer Questions Link"> - <xpath expr="//footer//ul[@name='products']" position="inside"> - <li> - <a t-attf-href="/forum/%(website_forum.forum_help)d">Q&A</a> - </li> - <li> - <a href="/forum">Forums</a> - </li> - </xpath> - </template> +<!-- Layout add nav and footer --> +<template id="header_footer_custom" inherit_id="website.layout" + name="Footer Questions Link"> + <xpath expr="//footer//ul[@name='products']" position="inside"> + <li><a t-attf-href="/forum/%(website_forum.forum_help)d">Q&A</a></li> + <li><a href="/forum">Forums</a></li> + </xpath> +</template> - <!-- List of Questions --> - <template id="post_list"> - <div class="question clearfix"> - <div class="pull-left text-center"> - <div t-attf-class="box #{question.child_count and 'oe_green' or 'oe_grey'}"> - <span t-esc="question.child_count"/> - <span t-if="question.is_correct" class="fa fa-2x fa-check-circle"/> - <div t-if="question.child_count>1">Answers</div> - <div t-if="question.child_count<=1">Answer</div> - </div> - <div class="text-muted text-center"> - <span t-field="question.views"/> Views - </div> +<!-- Page Index --> +<template id="header" name="Forum Index"> + <t t-call="website.layout"> + <t t-set="head"> + <link rel='stylesheet' href="/web/static/lib/jquery.textext/jquery.textext.css"/> + <link rel='stylesheet' href='/website_forum/static/src/css/website_forum.css'/> + <!-- + FP Note: Why do we need this ? Can we remove this code? + The problem is that you add your script for every page, not only for the forum + --> + <script type="text/javascript" src="/website_forum/static/src/js/website_forum.js"/> + <script type="text/javascript" src="/web/static/lib/jquery.textext/jquery.textext.js"/> + <script type="text/javascript" src="/web/static/lib/ckeditor/ckeditor.js"/> + <script type="text/javascript"> + CKEDITOR.config.toolbar = [['Bold','Italic','Underline','Strike'],['NumberedList','BulletedList', 'Blockquote'] + ,['Outdent','Indent','Link','Unlink','Image'],] ; + </script> + </t> + <div class="container mt16"> + <div class="navbar navbar-default"> + <div class="navbar-header"> + <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#oe-help-navbar-collapse"> + <span class="sr-only">Toggle navigation</span> + <span class="icon-bar"></span> + <!-- <span class="icon-bar"></span> --> + <span class="icon-bar"></span> + </button> + <a class="navbar-brand" t-attf-href="/forum/#{slug(forum)}"> + <span t-field="forum.name"/> + </a> </div> - <div style="margin-left: 95px;"> - <div class="question-name"> - <a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(question) }" t-field="question.name"/> - <span t-if="not question.active"><b> [Deleted]</b></span> - <span t-if="question.state == 'close'"><b> [Closed]</b></span> - </div> - <div class="text-muted"> - by <a t-attf-href="/forum/#{ slug(forum) }/user/#{ question.user_id.id }" t-field="question.user_id"/> - <t t-if="question.user_id.country_id"> - <span t-field="question.user_id.country_id.image" t-field-options='{"widget": "image", "class":"forum_user_flag"}'/> - </t> - on <span t-field="question.write_date" t-field-options='{"format":"short"}'/> - <div t-if="question.vote_count"> - <strong>with <span t-esc="question.vote_count"/> votes</strong> + <div class="collapse navbar-collapse" id="oe-help-navbar-collapse"> + <ul class="nav navbar-nav"> + <li t-att-class="filters in ('all', 'unanswered','followed','question','tag') and 'active' or '' "> + <a t-attf-href="/forum/#{ slug(forum) }">Questions</a> + </li> + <li t-att-class="searches.get('users') and 'active' or '' "> + <a t-attf-href="/forum/#{ slug(forum) }/users">People</a> + </li> + <li t-att-class="searches.get('tags') and 'active' or '' "> + <a t-attf-href="/forum/#{ slug(forum) }/tag">Tags</a> + </li> + <li t-att-class="searches.get('badges') and 'active' or '' "> + <a t-attf-href="/forum/#{ slug(forum) }/badge">Badges</a> + </li> + </ul> + <form class="navbar-form navbar-right" role="search" t-attf-action="/forum/#{ slug(forum) }" method="get"> + <div class="form-group"> + <input type="search" class="form-control" + name="search" placeholder="Search a question..." + t-att-value="search or ''"/> + <button type="submit" class="btn btn-default">Search</button> </div> - </div> - <t t-foreach="question.tag_ids" t-as="tag"> - <a t-attf-href="/forum/#{ slug(forum) }/tag/#{ tag.id }/questions" class="badge" t-field="tag.name"/> - </t> + </form> </div> </div> - </template> + </div> - <!-- Page Index --> - <template id="header" name="Forum Index"> - <t t-call="website.layout"> - <t t-set="head"> - <link rel='stylesheet' href="/web/static/lib/jquery.textext/jquery.textext.css"/> - <link rel='stylesheet' href='/website_forum/static/src/css/website_forum.css'/> - <!-- - FP Note: Why do we need this ? Can we remove this code? - The problem is that you add your script for every page, not only for the forum - --> - <script type="text/javascript" src="/website_forum/static/src/js/website_forum.js"/> - <script type="text/javascript" src="/web/static/lib/jquery.textext/jquery.textext.js"/> - <script type="text/javascript" src="/web/static/lib/ckeditor/ckeditor.js"/> - <script type="text/javascript"> - CKEDITOR.config.toolbar = [['Bold','Italic','Underline','Strike'],['NumberedList','BulletedList', 'Blockquote'] - ,['Outdent','Indent','Link','Unlink','Image'],] ; - </script> - </t> - <div class="container mt16"> - <div class="navbar navbar-default"> - <div class="navbar-header"> - <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#oe-help-navbar-collapse"> - <span class="sr-only">Toggle navigation</span> - <span class="icon-bar"></span> - <!-- <span class="icon-bar"></span> --> - <span class="icon-bar"></span> - </button> - <a class="navbar-brand" t-attf-href="/forum/#{slug(forum)}"> - <span t-field="forum.name"/> - </a> + <div id="wrap" class="container"> + <div class="row"> + <div class="col-sm-9"> + <div t-foreach="notifications or []" t-as="notification" class="alert alert-success alert-dismissable"> + <button type="button" class="close notification_close" t-att-id="notification.id" data-dismiss="alert" aria-hidden="true">&times;</button> + <div t-field="notification.body"/> + <a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(user) }#badges" class="fa fa-arrow-right">View Your Badges</a> + </div> + <t t-raw="0"/> + </div> + <div class="col-sm-3" id="right-column"> + <a t-if="header.get('ask_hide')" class="btn btn-primary btn-lg btn-block mb16" t-attf-href="/forum/#{slug(forum)}/ask">Ask a Question</a> + <div class="panel panel-default"> + <div class="panel-heading"> + <h3 class="panel-title">About This Forum</h3> </div> - <div class="collapse navbar-collapse" id="oe-help-navbar-collapse"> - <ul class="nav navbar-nav"> - <li t-att-class="filters in ('all', 'unanswered','followed','question','tag') and 'active' or '' "> - <a t-attf-href="/forum/#{ slug(forum) }">Questions</a> - </li> - <li t-att-class="searches.get('users') and 'active' or '' "> - <a t-attf-href="/forum/#{ slug(forum) }/users">People</a> - </li> - <li t-att-class="searches.get('tags') and 'active' or '' "> - <a t-attf-href="/forum/#{ slug(forum) }/tag">Tags</a> - </li> - <li t-att-class="searches.get('badges') and 'active' or '' "> - <a t-attf-href="/forum/#{ slug(forum) }/badge">Badges</a> - </li> - </ul> - <form class="navbar-form navbar-right" role="search" t-attf-action="/forum/#{ slug(forum) }" method="get"> - <div class="form-group"> - <input type="search" class="form-control" - name="search" placeholder="Search a question..." - t-att-value="search or ''"/> - <button type="submit" class="btn btn-default">Search</button> - </div> - </form> + <div class="panel-body"> + <t t-esc="forum.description"/><br/> + <a t-attf-href="/forum/#{slug(forum)}/faq" class="fa fa-arrow-right"> Read Guidelines</a> </div> </div> - </div> - - <div id="wrap" class="container"> - <div class="row"> - <div class="col-sm-9"> - <div t-foreach="notifications.get('notifications') or []" t-as="notification" class="alert alert-success alert-dismissable"> - <button type="button" class="close notification_close" t-att-id="notification.id" data-dismiss="alert" aria-hidden="true">&times;</button> - <div t-field="notification.body"/> - <a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(notifications.get('user')) }#badges" class="fa fa-arrow-right">View Your Badges</a> + <div t-if="header.get('question_data')"> + <div class="panel panel-default"> + <div class="panel-heading text-center"> + <h3 class="panel-title">Question tools</h3> </div> - <t t-raw="0"/> - </div> - <div class="col-sm-3" id="right-column"> - <a t-if="not ask_question" class="btn btn-primary btn-lg btn-block mb16" t-attf-href="/forum/#{ slug(forum) }/ask">Ask a Question</a> - <div class="panel panel-default"> - <div class="panel-heading"> - <h3 class="panel-title">About This Forum</h3> - </div> - <div class="panel-body"> - <t t-esc="forum.description"/><br/> - <a t-attf-href="/forum/#{slug(forum)}/faq" class="fa fa-arrow-right"> Read Guidelines</a> + <div class="panel-body text-center"> + <t t-call="website_mail.follow"><t t-set="object" t-value="question"/></t> + <div class="mt8"> + <strong><t t-raw="len(question.message_follower_ids)"/></strong> follower(s) </div> </div> - <div t-if="question_data"> - <div class="panel panel-default"> - <div class="panel-heading text-center"> - <h3 class="panel-title">Question tools</h3> - </div> - <div class="panel-body text-center"> - <a class="btn btn-block btn-default btn-md" t-if="not following" - t-attf-href="/forum/#{ slug(forum) }/question/#{ question.id }/subscribe">Follow</a> - <a class="btn btn-block btn-default btn-md" t-if="following" - t-attf-href="/forum/#{ slug(forum) }/question/#{ question.id }/unsubscribe">UnFollow</a> - <div class="mt8"> - <strong><t t-raw="len(question.message_follower_ids)"/></strong> follower - </div> - </div> - <div class="panel-heading text-center"> - <h3 class="panel-title ">Stats</h3> - </div> - <div class="panel-body"> - <table class="table"> - <thead><tr><td> Asked: <strong><span t-field="question.create_date" t-field-options='{"format":"short"}'/></strong></td></tr></thead> - <tr><td> Seen: <strong><t t-raw="question.views"/></strong> - <span t-if="question.views>1">times</span> - <span t-if="question.views<=1">time</span> - </td></tr> - <tr><td> Last updated: <strong><span t-field="question.write_date" t-field-options='{"format":"short"}'/></strong></td></tr> - </table> - </div> - </div> + <div class="panel-heading text-center"> + <h3 class="panel-title ">Stats</h3> + </div> + <div class="panel-body"> + <table class="table"> + <thead><tr><td> Asked: <strong><span t-field="question.create_date" t-field-options='{"format":"short"}'/></strong></td></tr></thead> + <tr><td> Seen: <strong><t t-raw="question.views"/></strong> + <span t-if="question.views>1">times</span> + <span t-if="question.views<=1">time</span> + </td></tr> + <tr><td> Last updated: <strong><span t-field="question.write_date" t-field-options='{"format":"short"}'/></strong></td></tr> + </table> </div> </div> </div> </div> - <div class="oe_structure"/> - </t> - </template> - - <template id="faq"> - <t t-call="website_forum.header"> - <div t-field="forum.faq"/> - </t> - </template> + </div> + </div> + <div class="oe_structure"/> + </t> +</template> - <template id="forum_index"> - <t t-call="website.layout"> - <div class="container"> - <h1 class="mb32">Our forums</h1> - <div class="row"> - <div t-foreach="forums" t-as="forum" class="col-sm-3 text-center mb32"> - <a t-attf-href="/forum/#{ slug(forum) }"> - <div class="fa fa-5x fa-comment mb16"/> - <div t-field="forum.name"/> - </a> - </div> - </div> - </div> +<!-- Display a post --> +<template id="display_post"> + <div class="question clearfix"> + <div class="pull-left text-center"> + <div t-attf-class="box #{question.child_count and 'oe_green' or 'oe_grey'}"> + <span t-esc="question.child_count"/> + <span t-if="question.is_correct" class="fa fa-2x fa-check-circle"/> + <div t-if="question.child_count>1">Answers</div> + <div t-if="question.child_count<=1">Answer</div> + </div> + <div class="text-muted text-center"> + <span t-field="question.views"/> Views + </div> + </div> + <div class="pull-right text-center"> + <div class="box oe_grey"> + <span t-esc="question.vote_count or 0"/> + <div t-if="question.vote_count>1">Votes</div> + <div t-if="question.vote_count<=1">Vote</div> + </div> + </div> + <div style="margin-left: 95px;"> + <div class="question-name"> + <a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(question) }" t-field="question.name"/> + <span t-if="not question.active"><b> [Deleted]</b></span> + <span t-if="question.state == 'close'"><b> [Closed]</b></span> + </div> + <div class="text-muted"> + by <a t-attf-href="/forum/#{ slug(forum) }/user/#{ question.create_uid.id }" + t-field="question.create_uid" t-field-options='{"widget": "contact", "country_image": true, "fields": ["name", "country_id"]}' + style="display: inline-block;"/> + on <span t-field="question.write_date" t-field-options='{"format":"short"}'/> + </div> + <t t-foreach="question.tag_ids" t-as="tag"> + <a t-attf-href="/forum/#{ slug(forum) }/tag/#{ tag.id }/questions" class="badge" t-field="tag.name"/> </t> - </template> + </div> + </div> +</template> - <template id="index" name="Forum"> - <t t-call="website_forum.header"> - <h1 class="page-header mt0"> - <t t-esc="total_questions"/> - <span>Questions</span> - <t t-esc="search"/> - <small class="dropdown" t-if="filters in ('all', 'unanswered','followed', 'tag')"> - <a href="#" class="dropdown-toggle" data-toggle="dropdown"> - <t t-if="filters == 'all'">All</t> - <t t-if="filters == 'unanswered'">Unanswered</t> - <t t-if="filters == 'followed'">Followed</t> - <t t-if="filters == 'tag'">Tag</t> - <t t-if="sorting == 'date'"> by activity date</t> - <t t-if="sorting == 'answered'"> by most answered</t> - <t t-if="sorting == 'vote'"> by most voted</t> - <b class="caret"/> - </a> - <ul class="dropdown-menu"> - <li class="dropdown-header">Filter on</li> - <li t-att-class="filters == 'all' and 'active' or '' "> - <a t-att-href="url_for('') + '?' + keep_query( 'search', 'sorting', filters='all')">All</a> - </li> - <li t-att-class="filters == 'unanswered' and 'active' or '' "> - <a t-att-href="url_for('') + '?' + keep_query( 'search', 'sorting', filters='unanswered')">Unanswered</a> - </li> - <li t-if="uid" t-att-class="filters == 'followed' and 'active' or '' "> - <a t-att-href="url_for('') + '?' + keep_query( 'search', 'sorting', filters='followed')">Followed</a> - </li> - <li t-if="tag" t-att-class="tag and 'active' or '' "> - <a href=""><t t-esc="tag.name"/> Tag</a> - </li> - <li class="dropdown-header">Sort by</li> - <li t-att-class="sorting == 'date' and 'active' or '' "> - <a t-att-href="url_for('') + '?' + keep_query( 'search', 'filters', sorting='date')">Last activity date</a> - </li> - <li t-att-class="sorting == 'answered' and 'active' or '' "> - <a t-att-href="url_for('') + '?' + keep_query( 'search', 'filters', sorting='answered')">Most answered</a> - </li> - <li t-att-class="sorting == 'vote' and 'active' or '' "> - <a t-att-href="url_for('') + '?' + keep_query( 'search', 'filters', sorting='vote')">Most voted</a> - </li> - </ul> - </small> - </h1> - <div t-foreach="question_ids" t-as="question" class="mb16"> - <t t-call="website_forum.post_list"/> - </div> - <t t-call="website.pager"/> +<!-- Display a post as an answer --> +<template id="display_post_answer"> + <div class="clearfix"> + <div t-attf-class="pull-left text-center mb16 box #{len(answer.vote_ids) and 'oe_green' or 'oe_grey'}"> + <div t-esc="len(answer.vote_ids)"/> + </div> + <div class="question-name" style="margin-left: 32px;"> + <a style="font-size: 15px;" t-attf-href="/forum/#{ slug(forum) }/question/#{ answer.parent_id.id }/#answer-#{ answer.id }" t-esc="answer.parent_id.name"/> + <t t-if="len(answer.website_message_ids)>0"> + (<t t-esc="len(answer.website_message_ids)"/> + <t t-if="len(answer.website_message_ids)>1">Comments</t> + <t t-if="len(answer.website_message_ids)<=1">Comment</t>) </t> - </template> + </div> + </div> +</template> - <template id="404"> - <t t-call="website_forum.header"> - <div class="oe_structure oe_empty"/> - <h1 class="mt32">Question not found!</h1> - <p>Sorry, this question is not available anymore.</p> - <p> - <a t-attf-href="/forum">Return to the question list.</a> - </p> - </t> - </template> +<!-- FAQ Layout --> +<template id="faq"> + <t t-call="website_forum.header"> + <div t-field="forum.faq"/> + </t> +</template> - <template id="user_detail"> - <div> - <span t-field="user.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/> - <div> - <a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(user) }" t-field="user.name"/> - <t t-if="user.country_id"> - <span t-field="user.country_id.image" t-field-options='{"widget": "image", "class":"forum_user_flag"}'/> - </t> - <b><t t-esc="user.karma"/></b> - <t t-raw="separator"/> - <div> - <b> badges:</b> - <span class="fa fa-circle badge-gold"/> - <t t-esc="user.gold_badge"/> - <span class="fa fa-circle badge-silver"/> - <t t-esc="user.silver_badge"/> - <span class="fa fa-circle badge-bronze"/> - <t t-esc="user.bronze_badge"/> - </div> - <t t-raw="0"/> +<!-- All Forums Layout --> +<template id="forum_all"> + <t t-call="website.layout"> + <div class="container"> + <h1 class="mb32">Our forums</h1> + <div class="row"> + <div t-foreach="forums" t-as="forum" class="col-sm-3 text-center mb32"> + <a t-attf-href="/forum/#{ slug(forum) }"> + <div class="fa fa-5x fa-comment mb16"/> + <div t-field="forum.name"/> + </a> </div> </div> - </template> + </div> + </t> +</template> - <template id="ask_question"> - <t t-call="website_forum.header"> - <h1 class="mt0">Ask your Question</h1> - <ul> - <li> please, try to make your question interesting to others </li> - <li> provide enough details and, if possible, give an example </li> - <li> be clear and concise, avoid unnecessary introductions (Hi, ... Thanks...) </li> - </ul> - <form t-attf-action="/forum/#{ slug(forum) }/question/ask" method="post" role="form" class="tag_text"> - <input type="text" name="question_name" required="True" t-attf-value="#{question_name}" - class="form-control" placeholder="Enter your Question"/> - <h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5> - <input type="hidden" name="karma" t-attf-value="#{user.karma}" id="karma"/> - <textarea name="content" required="True" class="form-control load_editor"> - <t t-esc="question_content"/> - </textarea> - <br/> - <input type="text" name="question_tags" t-attf-value="#{question_tag or ''}" - placeholder="Tags" class="form-control load_tags"/> - <br/> - <button class="btn btn-primary" id="btn_ask_your_question">Post Your Question</button> - </form> - <script type="text/javascript"> - CKEDITOR.replace("content"); - </script> - </t> - </template> +<!-- Specific Forum Layout --> +<template id="forum_index" name="Forum"> + <t t-call="website_forum.header"> + <h1 class="page-header mt0"> + <t t-esc="len(question_ids)"/> <span>Questions</span> + <t t-esc="search"/> + <small class="dropdown" t-if="filters in ('all', 'unanswered','followed', 'tag')"> + <a href="#" class="dropdown-toggle" data-toggle="dropdown"> + <t t-if="filters == 'all'">All</t> + <t t-if="filters == 'unanswered'">Unanswered</t> + <t t-if="filters == 'followed'">Followed</t> + <t t-if="filters == 'tag'">Tag</t> + <t t-if="sorting == 'date'"> by activity date</t> + <t t-if="sorting == 'answered'"> by most answered</t> + <t t-if="sorting == 'vote'"> by most voted</t> + <b class="caret"/> + </a> + <ul class="dropdown-menu"> + <li class="dropdown-header">Filter on</li> + <li t-att-class="filters == 'all' and 'active' or '' "> + <a t-att-href="url_for('') + '?' + keep_query( 'search', 'sorting', filters='all')">All</a> + </li> + <li t-att-class="filters == 'unanswered' and 'active' or '' "> + <a t-att-href="url_for('') + '?' + keep_query( 'search', 'sorting', filters='unanswered')">Unanswered</a> + </li> + <li t-if="uid" t-att-class="filters == 'followed' and 'active' or '' "> + <a t-att-href="url_for('') + '?' + keep_query( 'search', 'sorting', filters='followed')">Followed</a> + </li> + <li class="dropdown-header">Tags</li> + <li t-if="tag" t-att-class="tag and 'active' or '' "> + <a href=""><t t-esc="tag.name"/></a> + </li> + <li class="dropdown-header">Sort by</li> + <li t-att-class="sorting == 'date' and 'active' or '' "> + <a t-att-href="url_for('') + '?' + keep_query( 'search', 'filters', sorting='date')">Last activity date</a> + </li> + <li t-att-class="sorting == 'answered' and 'active' or '' "> + <a t-att-href="url_for('') + '?' + keep_query( 'search', 'filters', sorting='answered')">Most answered</a> + </li> + <li t-att-class="sorting == 'vote' and 'active' or '' "> + <a t-att-href="url_for('') + '?' + keep_query( 'search', 'filters', sorting='vote')">Most voted</a> + </li> + </ul> + </small> + </h1> + <div t-foreach="question_ids" t-as="question" class="mb16"> + <t t-call="website_forum.display_post"/> + </div> + <t t-call="website.pager"/> + </t> +</template> - <template id="edit_post"> - <t t-call="website_forum.header"> - <h3 t-if="not is_answer">Edit question</h3> - <h3 t-if="is_answer">Edit answer</h3> - <form t-attf-action="/forum/#{ slug(forum) }/post/save" method="post" role="form" class="tag_text"> - <div t-if="not is_answer"> - <input type="text" name="question_name" id="question_name" required="True" - t-attf-value="#{question.name}" class="form-control" placeholder="Edit your Question"/> - <h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5> - </div> - <input type="hidden" name="karma" t-attf-value="#{user.karma}" id="karma"/> - <textarea name="content" required="True" class="form-control load_editor"> - <t t-if="is_answer"> <t t-esc="answer.content"/></t> - <t t-if="not is_answer"><t t-esc="question.content"/></t> - </textarea> - <input name="question_id" t-att-value="question.id" type="hidden"/> - <div t-if="is_answer"> - <input name="answer_id" t-att-value="answer.id" type="hidden"/> - </div> - <div t-if="not is_answer"> - <br/> - <input type="text" name="question_tag" class="form-control col-md-9 load_tags" placeholder="Tags" t-attf-value="#{tags}"/> - <br/> - </div> - <button class="btn btn-primary btn-lg">Save</button> - </form> - <script type="text/javascript"> - CKEDITOR.replace("content"); - </script> - </t> - </template> +<template id="404"> + <t t-call="website_forum.header"> + <div class="oe_structure oe_empty"/> + <h1 class="mt32">Question not found!</h1> + <p>Sorry, this question is not available anymore.</p> + <p> + <a t-attf-href="/forum">Return to the question list.</a> + </p> + </t> +</template> - <template id="close_question"> - <t t-call="website_forum.header"> - <h3 class=""><b>Close question</b></h3><br/> - <form t-attf-action="/forum/#{ slug(forum) }/question/close" method="post" role="form"> - <input name="post_id" t-att-value="post.id" type="hidden"/> - <span class="pull-left">Close the question:</span> - <a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post) }" t-field="post.name"/> - <div class="mt16"> - <label class="col-md-2 control-label mb16" for="reason">Reasons:</label> - <div class="col-md-9 mb16"> - <select class="form-control" name="reason"> - <t t-foreach="reasons or []" t-as="reason"> - <option t-att-value="reason.id" t-att-selected="reason.id == post.reason_id.id"><t t-esc="reason.name"/></option> - </t> - </select> - </div> - </div> - <div> - <button class="btn btn-primary btn-lg">Close</button> - </div> - </form> - </t> - </template> +<!-- Edition: ask your question --> +<template id="ask_question"> + <t t-call="website_forum.header"> + <h1 class="mt0">Ask your Question</h1> + <ul> + <li> please, try to make your question interesting to others </li> + <li> provide enough details and, if possible, give an example </li> + <li> be clear and concise, avoid unnecessary introductions (Hi, ... Thanks...) </li> + </ul> + <form t-attf-action="/forum/#{ slug(forum) }/question/new" method="post" role="form" class="tag_text"> + <input type="text" name="question_name" required="True" t-attf-value="#{question_name}" + class="form-control" placeholder="Enter your Question"/> + <h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5> + <input type="hidden" name="karma" t-attf-value="#{user.karma}" id="karma"/> + <textarea name="content" required="True" class="form-control load_editor"> + <t t-esc="question_content"/> + </textarea> + <br/> + <input type="text" name="question_tags" placeholder="Tags" class="form-control load_tags"/> + <br/> + <button class="btn btn-primary" id="btn_ask_your_question">Post Your Question</button> + </form> + <script type="text/javascript"> + CKEDITOR.replace("content"); + </script> + </t> +</template> - <template id="post_answer"> - <h3 class="mt10">Your answer</h3> - <p> - <b>Please try to give a substantial answer.</b> If you wanted to comment on the question or answer, just - <b>use the commenting tool.</b> Please remember that you can always <b>revise your answers</b> - - no need to answer the same question twice. Also, please <b>don't forget to vote</b> - - it really helps to select the best questions and answers! - </p> - <form t-attf-action="/forum/#{ slug(forum) }/question/postanswer" method="post" role="form"> - <input type="hidden" name="karma" t-attf-value="#{user.karma}" id="karma"/> - <textarea name="content" class="form-control load_editor" required="True"/> - <input name="post_id" t-att-value="question.id" type="hidden"/> - <button class="btn btn-primary" id="btn_ask_your_question">Post Your Answer</button> - </form> - <script type="text/javascript"> - CKEDITOR.replace("content"); - </script> - </template> +<!-- Edition: edit a post --> +<template id="edit_post"> + <t t-call="website_forum.header"> + <h3 t-if="not is_answer">Edit question</h3> + <h3 t-if="is_answer">Edit answer</h3> + <form t-attf-action="/forum/#{ slug(forum) }/post/save" method="post" role="form" class="tag_text"> + <div t-if="not is_answer"> + <input type="text" name="question_name" id="question_name" required="True" + t-attf-value="#{question.name}" class="form-control" placeholder="Edit your Question"/> + <h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5> + </div> + <input type="hidden" name="karma" t-attf-value="#{user.karma}" id="karma"/> + <textarea name="content" required="True" class="form-control load_editor"> + <t t-if="is_answer"> <t t-esc="answer.content"/></t> + <t t-if="not is_answer"><t t-esc="question.content"/></t> + </textarea> + <input name="question_id" t-att-value="question.id" type="hidden"/> + <div t-if="is_answer"> + <input name="answer_id" t-att-value="answer.id" type="hidden"/> + </div> + <div t-if="not is_answer"> + <br/> + <input type="text" name="question_tag" class="form-control col-md-9 load_tags" placeholder="Tags" t-attf-value="#{tags}"/> + <br/> + </div> + <button class="btn btn-primary btn-lg">Save</button> + </form> + <script type="text/javascript"> + CKEDITOR.replace("content"); + </script> + </t> +</template> - <template id="vote"> - <div t-attf-class="box oe_grey"> - <a t-attf-class="vote_up fa fa-thumbs-up no-decoration #{post.user_vote == 1 and 'text-success' or ''}" - t-attf-id="#{post.id}" t-attf-value="1"/> - <span id="vote_count" t-esc="post.vote_count"/> - <a t-attf-class="vote_down fa fa-thumbs-down no-decoration #{post.user_vote == -1 and 'text-warning' or ''}" - t-attf-id="#{post.id}" t-attf-value="-1"/> - <div> - votes +<!-- Moderation: close a question --> +<template id="close_question"> + <t t-call="website_forum.header"> + <h3 class=""><b>Close question</b></h3><br/> + <form t-attf-action="/forum/#{ slug(forum) }/question/#{slug(question)}/close" method="post" role="form"> + <input name="post_id" t-att-value="post.id" type="hidden"/> + <span class="pull-left">Close the question:</span> + <a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post) }" t-field="post.name"/> + <div class="mt16"> + <label class="col-md-2 control-label mb16" for="reason">Reasons:</label> + <div class="col-md-9 mb16"> + <select class="form-control" name="reason"> + <t t-foreach="reasons or []" t-as="reason"> + <option t-att-value="reason.id" t-att-selected="reason.id == post.closed_reason_id.id"><t t-esc="reason.name"/></option> + </t> + </select> </div> </div> - </template> + <div> + <button class="btn btn-primary btn-lg">Close</button> + </div> + </form> + </t> +</template> - <template id="post_description_full" name="Question Navigation"> - <t t-call="website_forum.header"> +<!-- Edition: post an answer --> +<template id="post_answer"> + <h3 class="mt10">Your answer</h3> + <p> + <b>Please try to give a substantial answer.</b> If you wanted to comment on the question or answer, just + <b>use the commenting tool.</b> Please remember that you can always <b>revise your answers</b> + - no need to answer the same question twice. Also, please <b>don't forget to vote</b> + - it really helps to select the best questions and answers! + </p> + <form t-attf-action="/forum/#{ slug(forum) }/post/#{slug(question)}/new" method="post" role="form"> + <input type="hidden" name="karma" t-attf-value="#{user.karma}" id="karma"/> + <textarea name="content" class="form-control load_editor" required="True"/> + <button class="btn btn-primary" id="btn_ask_your_question">Post Your Answer</button> + </form> + <script type="text/javascript"> + CKEDITOR.replace("content"); + </script> +</template> - <div t-attf-class="question #{not question.active and 'alert alert-danger' or ''}"> - <div class="text-center pull-left"> - <t t-call="website_forum.vote"> - <t t-set="post" t-value="question"/> - </t> - <div class="text-muted"> - <span t-esc="question.child_count"/> - <span t-if="question.child_count>1">Answers</span> - <span t-if="question.child_count<=1">Answer</span> - </div> - <div> - <a t-attf-id="#{question.id}" t-attf-class="favourite_question no-decoration fa fa-2x fa-star #{question.user_favourite and 'forum_favourite_question' or ''}"/> - </div> - </div> - <div style="margin-left: 95px;"> - <h1 class="mt0"> - <span t-field="question.name"/> - <span t-if="not question.active"><b> [Deleted]</b></span> - <span t-if="question.state == 'close'"><b> [Closed]</b></span> - </h1> - <t t-raw="question.content"/> +<template id="vote"> + <div t-attf-class="box oe_grey"> + <a t-attf-class="vote_up fa fa-thumbs-up no-decoration #{post.user_vote == 1 and 'text-success' or ''}" + t-attf-data-post-id="#{post.id}" t-attf-data-forum-id="#{post.forum_id.id}" data-value="1"/> + <span id="vote_count" t-esc="post.vote_count"/> + <a t-attf-class="vote_down fa fa-thumbs-down no-decoration #{post.user_vote == -1 and 'text-warning' or ''}" + t-attf-data-post-id="#{post.id}" t-attf-data-forum-id="#{post.forum_id.id}" data-value="-1"/> + <div> + votes + </div> + </div> +</template> - <div class="mt16 clearfix"> - <div class="pull-right"> - <div class="text-right"> - <t t-foreach="question.tag_ids" t-as="tag"> - <a t-attf-href="/forum/#{ slug(forum) }/tag/#{ tag.id }/questions" class="badge" t-field="tag.name"/> - </t> - </div> - <ul class="list-inline"> - <li t-if="user.id == question.user_id.id or user.karma>=50"> - <a style="cursor: pointer" data-toggle="collapse" class="text-muted fa fa-comment-o" - t-attf-data-target="#comment#{ question._name.replace('.','') + '-' + str(question.id) }"> - comment - </a> - </li> - <li t-if="question.state != 'close' and (user.id == question.user_id.id or user.karma>=100)"> - <a class="text-muted fa fa-times" t-attf-href="/forum/#{ slug(forum) }/close/question/#{ question.id }">close</a> - </li> - <li t-if="question.state == 'close' and user.karma>=500"> - <a class="text-muted fa fa-undo" t-attf-href="/forum/#{ slug(forum) }/reopen/question/#{ question.id }">reopen</a> - </li> - <li t-if="user.id == question.user_id.id or user.karma>=300"> - <a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/edit/question/#{ question.id }">edit</a> - </li> - <li t-if="question.active and user.id == question.user_id.id or user.karma>=1000"> - <a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{ slug(forum) }/delete/question/#{ question.id }">delete</a> - </li> - <li t-if="uid == question.user_id.id and not question.active"> - <a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{ slug(forum) }/undelete/question/#{ question.id }">undelete</a> - </li> - <li><a class="text-muted fa fa-share" href="">share</a></li> - </ul> - </div> - <div> - <t t-call="website_forum.user_detail"> - <t t-set="user" t-value="question.user_id"/> - <span class="text-muted">Asked on <span t-field="question.write_date" t-field-options='{"format":"short"}'/></span> - </t> - </div> - <div class="alert alert-info" t-if="question.state == 'close'"> - <p class="mt32 mb32 text-center"> - <b>The question has been closed for the following reason "<span t-field="question.reason_id.name"/>" - <i>by <a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(question.closed_by) }" t-field="question.closed_by.name"/> </i> - <br/>close date <span t-field="question.closed_date"/></b> - </p> - </div> - </div> - <t t-call="website_forum.comments"> - <t t-set="object" t-value="question"/> - </t> - </div> +<!-- Specific Post Layout --> +<template id="post_description_full" name="Question Navigation"> + <t t-call="website_forum.header"> + + <div t-attf-class="question #{not question.active and 'alert alert-danger' or ''}"> + <div class="text-center pull-left"> + <t t-call="website_forum.vote"> + <t t-set="post" t-value="question"/> + </t> + <div class="text-muted"> + <span t-esc="question.child_count"/> + <span t-if="question.child_count>1">Answers</span> + <span t-if="question.child_count<=1">Answer</span> </div> - <hr/> + <div> + <a t-attf-data-forum-id="#{question.forum_id.id}" t-attf-data-post-id="#{question.id}" + t-attf-class="favourite_question no-decoration fa fa-2x fa-star #{question.user_favourite and 'forum_favourite_question' or ''}"/> + </div> + </div> + <div style="margin-left: 95px;"> + <h1 class="mt0"> + <span t-field="question.name"/> + <span t-if="not question.active"><b> [Deleted]</b></span> + <span t-if="question.state == 'close'"><b> [Closed]</b></span> + </h1> + <t t-raw="question.content"/> - <div t-foreach="question.child_ids" t-as="answer" class="mt16 mb32"> - <a t-attf-id="answer-#{str(answer.id)}"/> - <div t-attf-class="#{answer.is_correct and 'alert alert-info answer_correct' or ''}" t-attf-id="answer_#{answer.id}" > - <div class="text-center pull-left"> - <t t-call="website_forum.vote"> - <t t-set="post" t-value="answer"/> + <div class="mt16 clearfix"> + <div class="pull-right"> + <div class="text-right"> + <t t-foreach="question.tag_ids" t-as="tag"> + <a t-attf-href="/forum/#{ slug(forum) }/tag/#{ tag.id }/questions" class="badge" t-field="tag.name"/> </t> - <div class="text-muted"> - <a t-attf-id="#{answer.id}" t-if="answer.is_correct" class="accept_answer fa fa-2x fa-check-circle no-decoration oe_answer_true"/> - <a t-attf-id="#{answer.id}" t-if="not answer.is_correct" class="accept_answer fa fa-2x fa-check-circle no-decoration oe_answer_false"/> - </div> </div> - <div style="margin-left: 95px;" class="clearfix"> - <t t-raw="answer.content"/> - <div class="mt16"> - <ul class="list-inline pull-right"> - <li t-if="user.id == answer.user_id.id or user.karma>=50"> - <a style="cursor: pointer" data-toggle="collapse" class="text-muted fa fa-comment-o" - t-attf-data-target="#comment#{ answer._name.replace('.','') + '-' + str(answer.id) }">comment - </a> - </li> - <li t-if="user.id == answer.user_id.id or user.karma>=300"> - <a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/question/#{ question.id }/edit/#{ answer.id }">edit</a> - </li> - <li t-if="user.id == answer.user_id.id or user.karma>=1000"> - <a class="text-muted delete fa fa-trash-o" href="" t-attf-id="#{answer.id}">delete</a> - </li> - <li t-if="user.id == answer.user_id.id"> - <a class="text-muted fa fa-magic" t-attf-href="/forum/#{ slug(forum) }/post/#{ answer.id }/converttocomment">Convert as a comment</a> - </li> - <li><a class="text-muted fa fa-share" t-attf-href="/forum/#{ slug(forum) }/question/#{ question.id }/#answer-#{ answer.id }">share</a></li> - </ul> - <t t-call="website_forum.user_detail"> - <t t-set="user" t-value="answer.user_id"/> - <span class="text-muted">Answered on <span t-field="answer.create_date" t-field-options='{"format":"short"}'/></span> - </t> - </div> - <t t-call="website_forum.comments"> - <t t-set="object" t-value="answer"/> - </t> + <ul class="list-inline"> + <li t-if="user.id == question.create_uid.id or user.karma>=50"> + <a style="cursor: pointer" data-toggle="collapse" class="text-muted fa fa-comment-o" + t-attf-data-target="#comment#{ question._name.replace('.','') + '-' + str(question.id) }"> + comment + </a> + </li> + <li t-if="question.state != 'close' and (user.id == question.create_uid.id or user.karma>=100)"> + <a class="text-muted fa fa-times" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)}/ask_for_close">close</a> + </li> + <li t-if="question.state == 'close' and user.karma>=500"> + <a class="text-muted fa fa-undo" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)/reopen">reopen</a> + </li> + <li t-if="user.id == question.create_uid.id or user.karma>=300"> + <a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)}/edit">edit</a> + </li> + <li t-if="question.active and user.id == question.create_uid.id or user.karma>=1000"> + <a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)}/delete">delete</a> + </li> + <li t-if="uid == question.create_uid.id and not question.active"> + <a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)}/undelete">undelete</a> + </li> + <li><a class="text-muted fa fa-share" href="">share</a></li> + </ul> + </div> + <div> + <span t-field="question.create_uid.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/> + <div> + <a t-attf-href="/forum/#{ slug(forum) }/user/#{ user.id }" + t-field="question.create_uid" + t-field-options='{"widget": "contact", "country_image": true, "fields": ["name", "country_id"]}' + style="display: inline-block;"/> + <div t-field="question.create_uid" t-field-options='{"widget": "contact", "badges": true, "fields": ["karma"]}'/> </div> </div> + <div class="alert alert-info" t-if="question.state == 'close'"> + <p class="mt32 mb32 text-center"> + <b>The question has been closed for the following reason "<span t-field="question.closed_reason_id.name"/>" + <t t-if="question.closed_uid"> + <i>by <a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(question.closed_uid) }" t-field="question.closed_uid.name"/> </i> + </t> + <br/>close date <span t-field="question.closed_date"/></b> + </p> + </div> </div> - <div t-if="not answer_done"> - <t t-call="website_forum.post_answer"/> - </div> - <div t-if="answer_done" class="mb16"> - <a class="btn btn-primary" t-attf-href="/forum/#{ slug(forum) }/question/#{ question.id }/editanswer">Edit Your Previous Answer</a> - <span class="text-muted">(only one answer per question is allowed)</span> - </div> - </t> - </template> + <t t-call="website_forum.post_comment"> + <t t-set="object" t-value="question"/> + </t> + </div> + </div> + <hr/> - <template id="comments"> - <div class="row clearfix"> - <div class="col-sm-10 col-sm-offset-2"> - <div t-foreach="reversed(object.website_message_ids)" t-as="message" id="comment" class="oe_comment_grey" style="padding: 4px;"> - <small class="text-muted"> - <button type="button" t-if="user.id == message.create_uid.id or user.karma>=750" t-att-id="message.id" class="close comment_delete">&times;</button> - <span t-field="message.body"/> - <a t-attf-href="/forum/#{ slug(forum) }/user/#{ message.create_uid.id }" t-field="message.create_uid"/> - on <span t-field="message.date" t-field-options='{"format":"short"}'/> - <a class="fa fa-magic text-muted pull-right" t-if="uid == message.create_uid.id" - t-attf-href="/forum/#{ slug(forum) }/post/#{ object.id }/commet/#{ message.id }/converttoanswer">Convert as an answer</a> - </small> + <div t-foreach="question.child_ids" t-as="answer" class="mt16 mb32"> + <a t-attf-id="answer-#{str(answer.id)}"/> + <div t-attf-class="#{answer.is_correct and 'alert alert-info answer_correct' or ''}" t-attf-id="answer_#{answer.id}" > + <div class="text-center pull-left"> + <t t-call="website_forum.vote"> + <t t-set="post" t-value="answer"/> + </t> + <div class="text-muted"> + <a t-attf-class="accept_answer fa fa-2x fa-check-circle no-decoration oe_answer_true #{answer.is_correct and 'oe_answer_true' or 'oe_answer_false'}" + t-attf-data-forum-id="#{question.forum_id.id}" t-attf-data-post-id="#{answer.id}" + t-attf-data-accept="#{answer.is_correct}"/> </div> - <div class="css_editable_mode_hidden"> - <form t-attf-id="comment#{ object._name.replace('.','') + '-' + str(object.id) }" class="collapse" t-attf-action="/forum/#{ slug(forum) }/comment" method="POST"> - <input name="post_id" t-att-value="object.id" type="hidden"/> - <textarea name="comment" class="form-control" placeholder="Comment this post..."/> - <button type="submit" class="btn btn-primary mt8">Post</button> - </form> + </div> + <div style="margin-left: 95px;" class="clearfix"> + <t t-raw="answer.content"/> + <div class="mt16"> + <ul class="list-inline pull-right"> + <li t-if="user.id == answer.create_uid.id or user.karma>=50"> + <a style="cursor: pointer" data-toggle="collapse" class="text-muted fa fa-comment-o" + t-attf-data-target="#comment#{ answer._name.replace('.','') + '-' + str(answer.id) }">comment + </a> + </li> + <li t-if="user.id == answer.create_uid.id or user.karma>=300"> + <a class="text-muted fa fa-edit" t-attf-href="/forum/#{slug(forum)}/post/#{slug(answer)}/edit">edit</a> + </li> + <li t-if="user.id == answer.create_uid.id or user.karma>=1000"> + <a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{slug(forum)}/post/#{slug(answer)}/delete">delete</a> + </li> + <li t-if="user.id == answer.create_uid.id"> + <a class="text-muted fa fa-magic" t-attf-href="/forum/#{slug(forum)}/post/#{slug(answer)}/convert_to_comment">Convert as a comment</a> + </li> + <li><a class="text-muted fa fa-share" t-attf-href="/forum/#{slug(forum)}/question/#{slug(question)}/#answer-#{ answer.id }">share</a></li> + </ul> + <span t-field="answer.create_uid.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/> + <div> + <a t-attf-href="/forum/#{ slug(forum) }/user/#{ user.id }" + t-field="answer.create_uid" + t-field-options='{"widget": "contact", "country_image": true, "fields": ["name", "country_id"]}' + style="display: inline-block;"/> + <div t-field="answer.create_uid" t-field-options='{"widget": "contact", "badges": true, "fields": ["karma"]}'/> + <span class="text-muted">Answered on <span t-field="answer.create_date" t-field-options='{"format":"short"}'/></span> + </div> </div> + <t t-call="website_forum.post_comment"> + <t t-set="object" t-value="answer"/> + </t> </div> </div> - </template> + </div> + <div t-if="not question.uid_has_answered"> + <t t-call="website_forum.post_answer"/> + </div> + <div t-if="question.uid_has_answered" class="mb16"> + <a class="btn btn-primary" t-attf-href="/forum/#{slug(forum)}/question/#{slug(question)}/edit_answer">Edit Your Previous Answer</a> + <span class="text-muted">(only one answer per question is allowed)</span> + </div> + </t> +</template> - <template id="tag"> - <t t-call="website_forum.header"> - <h1 class="mt0"> - Tags - </h1> - <p class="text-muted"> - A tag is a label that categorizes your question with other, - similar questions. Using the right tags makes it easier for - others to find and answer your question. - </p> - <div class="row"> - <div class="col-sm-3 mt16" t-foreach="tags" t-as="tag"> - <a t-attf-href="/forum/#{ slug(forum) }/tag/#{ slug(tag) }/questions?{{ keep_query( filters='tag') }}" class="badge"> - <span t-field="tag.name"/> - </a> - <span> - X <t t-esc="tag.posts_count"/> - </span> - </div> - </div> - </t> - </template> +<!-- Utility template: Post a Comment --> +<template id="post_comment"> + <div class="row clearfix"> + <div class="col-sm-10 col-sm-offset-2"> + <div t-foreach="reversed(object.website_message_ids)" t-as="message" id="comment" class="oe_comment_grey" style="padding: 4px;"> + <small class="text-muted"> + <button type="button" t-if="user.karma>=750" t-att-id="message.id" class="close comment_delete">&times;</button> + <span t-field="message.body"/> + <a t-attf-href="/forum/#{slug(forum)}/user/#{message.id}" + t-field="message.author_id" t-field-options='{"widget": "contact", "country_image": true, "fields": ["name", "country_id"]}' + style="display: inline-block;"/> + on <span t-field="message.date" t-field-options='{"format":"short"}'/> + </small> + </div> + <div class="css_editable_mode_hidden"> + <form t-attf-id="comment#{ object._name.replace('.','') + '-' + str(object.id) }" class="collapse" + t-attf-action="/forum/#{slug(forum)}/question/#{slug(object)}/comment" method="POST"> + <input name="post_id" t-att-value="object.id" type="hidden"/> + <textarea name="comment" class="form-control" placeholder="Comment this post..."/> + <button type="submit" class="btn btn-primary mt8">Post</button> + </form> + </div> + </div> + </div> +</template> - <template id="badge"> - <t t-call="website_forum.header"> - <h1 class="mt0"> - Badges - </h1> - <p> - Besides gaining reputation with your questions and answers, - you receive badges for being especially helpful. Badges - appear on your profile page, and your posts. - </p> - <table class="table mt32 mb64"> - <tr t-foreach="badges" t-as="badge"> - <td> - <a t-attf-href="/forum/#{ slug(forum) }/badge/#{ slug(badge) }" class="badge pull-left"> - <span t-if="badge.level == 'gold'" class="fa fa-circle badge-gold"/> - <span t-if="badge.level == 'silver'" class="fa fa-circle badge-silver"/> - <span t-if="badge.level == 'bronze'" class="fa fa-circle badge-bronze"/> - <span t-field="badge.name"/> - </a> - </td><td> - <b t-esc="badge.stat_count_distinct"/> - <i class="text-muted">awarded users</i> - </td><td> - <span t-field="badge.description"/> - </td> - </tr> - </table> - </t> - </template> +<template id="tag"> + <t t-call="website_forum.header"> + <h1 class="mt0"> + Tags + </h1> + <p class="text-muted"> + A tag is a label that categorizes your question with other, + similar questions. Using the right tags makes it easier for + others to find and answer your question. + </p> + <div class="row"> + <div class="col-sm-3 mt16" t-foreach="tags" t-as="tag"> + <a t-attf-href="/forum/#{ slug(forum) }/tag/#{ slug(tag) }/questions?{{ keep_query( filters='tag') }}" class="badge"> + <span t-field="tag.name"/> + </a> + <span> + X <t t-esc="tag.posts_count"/> + </span> + </div> + </div> + </t> +</template> - <template id="badge_user"> - <t t-call="website_forum.header"> - <h3 class="mt32 mb32"> - <b>Badge "<span t-field="badge.name"/>"</b> - </h3> - <div> - <div class="pull-left badge"> +<template id="badge"> + <t t-call="website_forum.header"> + <h1 class="mt0"> + Badges + </h1> + <p> + Besides gaining reputation with your questions and answers, + you receive badges for being especially helpful. Badges + appear on your profile page, and your posts. + </p> + <table class="table mt32 mb64"> + <tr t-foreach="badges" t-as="badge"> + <td> + <a t-attf-href="/forum/#{ slug(forum) }/badge/#{ slug(badge) }" class="badge pull-left"> <span t-if="badge.level == 'gold'" class="fa fa-circle badge-gold"/> <span t-if="badge.level == 'silver'" class="fa fa-circle badge-silver"/> <span t-if="badge.level == 'bronze'" class="fa fa-circle badge-bronze"/> <span t-field="badge.name"/> - </div> - <span t-field="badge.description" style="margin-left:20px"/> + </a> + </td><td> + <b t-esc="badge.stat_count_distinct"/> + <i class="text-muted">awarded users</i> + </td><td> + <span t-field="badge.description"/> + </td> + </tr> + </table> + </t> +</template> + +<template id="badge_user"> + <t t-call="website_forum.header"> + <h3 class="mt32 mb32"> + <b>Badge "<span t-field="badge.name"/>"</b> + </h3> + <div> + <div class="pull-left badge"> + <span t-if="badge.level == 'gold'" class="fa fa-circle badge-gold"/> + <span t-if="badge.level == 'silver'" class="fa fa-circle badge-silver"/> + <span t-if="badge.level == 'bronze'" class="fa fa-circle badge-bronze"/> + <span t-field="badge.name"/> + </div> + <span t-field="badge.description" style="margin-left:20px"/> + </div> + <h4 class="mt32"> + <t class="pull-left" t-esc="badge.stat_count_distinct"/> + <span t-if="badge.stat_count_distinct>1">users</span> + <span t-if="badge.stat_count_distinct<=1">user</span> + received this badge: + </h4> + <div class="row"> + <div class="col-sm-3 mt16" t-foreach="users" t-as="user"> + <span t-field="user.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/> + <div> + <a t-attf-href="/forum/#{slug(forum)}/user/#{user.id}" t-field="user.name"/> </div> - <h4 class="mt32"> - <t class="pull-left" t-esc="badge.stat_count_distinct"/> - <span t-if="badge.stat_count_distinct>1">users</span> - <span t-if="badge.stat_count_distinct<=1">user</span> - received this badge: - </h4> - <div class="row"> - <div class="col-sm-3 mt16" t-foreach="users" t-as="user"> - <span t-field="user.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/> - <div> - <a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(user) }" t-field="user.name"/> - </div> + </div> + </div> + </t> +</template> + +<template id="users"> + <t t-call="website_forum.header"> + <div class="row"> + <div t-foreach="users" t-as="user" class="col-sm-4"> + <span t-field="user.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/> + <div> + <a t-attf-href="/forum/#{slug(forum)}/user/#{user.id}" t-field="user.name"/> + <t t-if="user.country_id"> + <span t-field="user.country_id.image" t-field-options='{"widget": "image", "class": "country_flag"}'/> + </t> + <b><t t-esc="user.karma"/></b> + <t t-raw="separator"/> + <div> + <b> badges:</b> + <span class="fa fa-circle badge-gold"/> + <t t-esc="user.gold_badge"/> + <span class="fa fa-circle badge-silver"/> + <t t-esc="user.silver_badge"/> + <span class="fa fa-circle badge-bronze"/> + <t t-esc="user.bronze_badge"/> </div> + <t t-raw="0"/> </div> - </t> - </template> + </div> + </div> + <div class="pull-left"> + <t t-call="website.pager"/> + </div> + </t> +</template> - <template id="users"> - <t t-call="website_forum.header"> - <div class="row"> - <div t-foreach="users" t-as="user" class="col-sm-4"> - <t t-set="separator"><br/></t> - <t t-call="website_forum.user_detail"/> - <span class="text-muted">Joined on <span t-field="user.create_date" t-field-options='{"format":"short"}'/></span> - </div> +<template id="edit_profile"> + <t t-call="website_forum.header"> + <h3>Edit Profile </h3> + <div class="col-md-2"> + <span t-field="user.image" t-field-options='{"widget": "image", "class": "img img-responsive img-circle"}'/> + </div> + <form t-attf-action="/forum/#{slug(forum)}/user/#{slug(user)}/save" method="post" role="form" class="form-horizontal"> + <input name="user_id" t-att-value="user.id" type="hidden"/> + <label class="col-md-2 control-label mb16" for="user.name">Real name</label> + <div class="col-md-7 mb16"> + <input type="text" class="col-md-7 mb16 form-control" name="name" required="True" t-attf-value="#{user.name}"/> + </div> + <label class="col-md-2 control-label mb16" for="user.partner_id.website">Website</label> + <div class="col-md-7 mb16"> + <input type="text" class="form-control" name="website" t-attf-value="#{user.partner_id.website or ''}"/> </div> - <div class="pull-left"> - <t t-call="website.pager"/> + <label class="col-md-4 control-label mb16" for="user.partner_id.email">Email</label> + <div class="col-md-7 mb16"> + <input type="text" class="form-control" name="email" required="True" t-attf-value="#{user.partner_id.email}"/> </div> - </t> - </template> - - <template id="edit_profile"> - <t t-call="website_forum.header"> - <h3>Edit Profile </h3> - <div class="col-md-2"> - <span t-field="user.image" t-field-options='{"widget": "image", "class": "img img-responsive img-circle"}'/> - </div> - <form t-attf-action="/forum/#{ slug(forum) }/save/profile" method="post" role="form" class="form-horizontal"> - <input name="user_id" t-att-value="user.id" type="hidden"/> - <label class="col-md-2 control-label mb16" for="user.name">Real name</label> - <div class="col-md-7 mb16"> - <input type="text" class="col-md-7 mb16 form-control" name="name" required="True" t-attf-value="#{user.name}"/> - </div> - <label class="col-md-2 control-label mb16" for="user.partner_id.website">Website</label> - <div class="col-md-7 mb16"> - <input type="text" class="form-control" name="website" t-attf-value="#{user.partner_id.website or ''}"/> - </div> - <label class="col-md-4 control-label mb16" for="user.partner_id.email">Email</label> - <div class="col-md-7 mb16"> - <input type="text" class="form-control" name="email" required="True" t-attf-value="#{user.partner_id.email}"/> - </div> - <label class="col-md-4 control-label mb16" for="user.partner_id.city">City</label> - <div class="col-md-7 mb16"> - <input type="text" class="form-control" name="city" t-attf-value="#{user.partner_id.city or ''}"/> - </div> - <label class="col-md-4 control-label mb16" for="contact_name">Country</label> - <div class="col-md-7 mb16"> - <select class="form-control" name="country"> - <option value="">Country...</option> - <t t-foreach="countries or []" t-as="country"> - <option t-att-value="country.id" t-att-selected="country.id == user.partner_id.country.id"><t t-esc="country.name"/></option> - </t> - </select> - </div> - <!--Note: using website_description fiels instead of using commnt firld of partner--> - <label class="col-md-4 control-label mb16" for="user.partner_id.website_description">Biography</label> - <div class="col-md-7 mb16"> - <textarea name="description" style="min-height: 120px" required="True" - class="form-control"><t t-esc="user.partner_id.website_description"/></textarea> - </div> - <div class="col-sm-offset-4 col-md-4 mb16"> - <button class="btn btn-primary btn-lg">Update</button> - </div> - </form> - </t> - </template> - - <template id="user_detail_full"> - <t t-call="website_forum.header"> - <h1 class="mt0 page-header"> - <span t-field="user.name"/> - <small>profile</small> - </h1> - <div class="row"> - <div class="col-sm-2"> - <span t-field="user.image" - t-field-options='{"widget": "image", "class": "img img-responsive img-circle"}'/> - </div> - <div class="col-sm-10"> - <table class="table table-condensed"> - <tr> - <td rowspan="2" valign="top"><span class="text-muted">contributions</span></td> - <td>member since</td> - <td><span t-field="user.create_date" t-field-options='{"format": "short"}'/></td> - </tr><tr> - <td>last connection</td> - <td><span t-field="user.login_date" t-field-options='{"format": "short"}'/></td> - </tr> - <tr> - <td rowspan="2" valign="top"><span class="text-muted">bio</span></td> - <td>website</td> - <td> - <a t-att-href="user.website" t-if="user.website"> - <span t-field="user.website"/> - </a> - </td> - </tr><tr> - <td>location</td> - <td> - <span t-field="user.city"/> - <span t-if="user.city and user.country_id">, </span> - <span t-field="user.country_id"/> - <t t-if="user.country_id"> <span t-field="user.country_id.image" t-field-options='{"widget": "image", "class":"forum_user_flag"}'/></t> - - </td> - </tr> - <tr> - <td rowspan="2" valign="top"><span class="text-muted">stats</span></td> - <td>karma</td> - <td><span t-field="user.karma"/></td> - </tr><tr> - <td>votes</td> - <td> - <span class="fa fa-thumbs-up"/> - <span t-esc="up_votes"/> - <span class="fa fa-thumbs-down"/> - <span t-esc="down_votes"/> - </td> - </tr> - </table> - <div class="well well-sm"> - <span t-field="user.partner_id.website_description"/> - <t t-if="uid == user.id"> - <a class="fa fa-arrow-right" t-attf-href="/forum/#{ slug(forum) }/edit/profile/#{ user.id }"> Edit Your Bio</a> - </t> - </div> - </div> + <label class="col-md-4 control-label mb16" for="user.partner_id.city">City</label> + <div class="col-md-7 mb16"> + <input type="text" class="form-control" name="city" t-attf-value="#{user.partner_id.city or ''}"/> </div> - - <ul class="nav nav-tabs"> - <li class="active"> - <a href="#questions" data-toggle="tab"><t t-esc="len(questions)"/> Questions</a> - </li> - <li> - <a href="#answers" data-toggle="tab"><t t-esc="len(answers)"/> Answers</a> - </li> - <li t-if="uid == user.id"> - <a href="#favourite_question" data-toggle="tab"><t t-esc="len(favourite)"/> Favourite Questions</a> - </li> - <li t-if="uid == user.id"> - <a href="#followed_question" data-toggle="tab"><t t-esc="len(followed)"/> Followed Questions</a> - </li> - <li t-if="uid == user.id"> - <a href="#activity" data-toggle="tab">Activity</a> - </li> - <li> - <a href="#badges" data-toggle="tab">Badges</a> - </li> - <li t-if="uid == user.id"> - <a href="#votes" data-toggle="tab">Votes</a> - </li> - </ul> - <div class="tab-content mt16"> - <div class="tab-pane active" id="questions"> - <div class="mb16" t-foreach="questions" t-as="question"> - <t t-call="website_forum.post_list"/> - </div> - </div><div class="tab-pane" id="answers"> - <div t-foreach="answers" t-as="answer"> - <t t-call="website_forum.post_list_answer"/> - </div> - </div> - <div class="tab-pane" id="karma"> - <h1>Karma</h1> - </div> - <div class="tab-pane" id="badges"> - <t t-call="website_forum.user_badges"/> - </div> - <div class="tab-pane" id="favourite_question"> - <div t-foreach="favourite" t-as="question"> - <t t-call="website_forum.post_list"/> - </div> - </div> - <div class="tab-pane" id="followed_question"> - <div t-foreach="followed" t-as="question"> - <t t-call="website_forum.post_list"/> - </div> - </div> - <div class="tab-pane" id="votes"> - <t t-call="website_forum.user_votes"/> - </div> - <div class="tab-pane" id="activity"> - <ul class="list-unstyled"> - <li t-foreach="activities" t-as="activity"> - <span t-field="activity.date" t-field-options='{"format": "short"}'/> - <span t-esc="activity.subtype_id.name" class="label label-info"/> - <t t-set="post" t-value="posts[activity.res_id]"/> - <span t-if="post[1]"> - <a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post[0]) }#answer-#{ str(post[1].id) }"> - <span t-esc="post[0].name"/> - </a> - </span> - <span t-if="not post[1]"> - <a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post[0]) }"> - <span t-esc="post[0].name"/> - </a> - </span> - </li> - </ul> - </div> + <label class="col-md-4 control-label mb16" for="contact_name">Country</label> + <div class="col-md-7 mb16"> + <select class="form-control" name="country"> + <option value="">Country...</option> + <t t-foreach="countries or []" t-as="country"> + <option t-att-value="country.id" t-att-selected="country.id == user.partner_id.country.id"><t t-esc="country.name"/></option> + </t> + </select> </div> - </t> - </template> + <!--Note: using website_description fiels instead of using commnt firld of partner--> + <label class="col-md-4 control-label mb16" for="user.partner_id.website_description">Biography</label> + <div class="col-md-7 mb16"> + <textarea name="description" style="min-height: 120px" required="True" + class="form-control"><t t-esc="user.partner_id.website_description"/></textarea> + </div> + <div class="col-sm-offset-4 col-md-4 mb16"> + <button class="btn btn-primary btn-lg">Update</button> + </div> + </form> + </t> +</template> - <template id="user_badges"> - <table class="table mt32 mb64"> - <tr t-foreach="user.badge_ids" t-as="badge"> +<template id="user_detail_full"> + <t t-call="website_forum.header"> + <h1 class="mt0 page-header"> + <span t-field="user.name"/> + <small>profile</small> + </h1> + <div class="row"> + <div class="col-sm-2"> + <span t-field="user.image" + t-field-options='{"widget": "image", "class": "img img-responsive img-circle"}'/> + </div> + <div class="col-sm-10"> + <table class="table table-condensed"> + <tr> + <td rowspan="2" valign="top"><span class="text-muted">contributions</span></td> + <td>member since</td> + <td><span t-field="user.create_date" t-field-options='{"format": "short"}'/></td> + </tr><tr> + <td>last connection</td> + <td><span t-field="user.login_date" t-field-options='{"format": "short"}'/></td> + </tr> + <tr> + <td rowspan="2" valign="top"><span class="text-muted">bio</span></td> + <td>website</td> <td> - <a t-attf-href="/forum/#{ slug(forum) }/badge/#{ slug(badge.badge_id) }" class="badge pull-left"> - <span t-if="badge.badge_id.level == 'gold'" class="fa fa-circle badge-gold"/> - <span t-if="badge.badge_id.level == 'silver'" class="fa fa-circle badge-silver"/> - <span t-if="badge.badge_id.level == 'bronze'" class="fa fa-circle badge-bronze"/> - <span t-field="badge.badge_id.name"/> + <a t-att-href="user.website" t-if="user.website"> + <span t-field="user.website"/> </a> - </td><td> - <b t-esc="badge.badge_id.stat_count_distinct"/> - <i class="text-muted">awarded users</i> - </td><td> - <span t-field="badge.badge_id.description"/> + </td> + </tr><tr> + <td>location</td> + <td> + <span t-field="user.city"/> + <span t-if="user.city and user.country_id">, </span> + <span t-field="user.country_id"/> + <t t-if="user.country_id"> <span t-field="user.country_id.image" t-field-options='{"widget": "image", "class":"forum_user_flag"}'/></t> + + </td> + </tr> + <tr> + <td rowspan="2" valign="top"><span class="text-muted">stats</span></td> + <td>karma</td> + <td><span t-field="user.karma"/></td> + </tr><tr> + <td>votes</td> + <td> + <span class="fa fa-thumbs-up"/> + <span t-esc="up_votes"/> + <span class="fa fa-thumbs-down"/> + <span t-esc="down_votes"/> </td> </tr> - </table> - <div class="mb16" t-if="not user.badge_ids"> - <b>No badge yet!</b><br/> - <a t-attf-href="/forum/#{ slug(forum) }/badge" class="fa fa-arrow-right"> Check available badges</a> + </table> + <div class="well well-sm"> + <span t-field="user.partner_id.website_description"/> + <t t-if="uid == user.id"> + <a class="fa fa-arrow-right" t-attf-href="/forum/#{slug(forum)}/user/#{slug(user)}/edit"> Edit Your Bio</a> + </t> + </div> </div> - </template> + </div> - <template id="user_votes"> - <div t-foreach="vote_post" t-as="vote"> - <t t-esc="vote.post_id.create_date"/> - <span t-if="vote.vote == '1'" class="fa fa-thumbs-up text-success" style="margin-left:30px"/> - <span t-if="vote.vote == '-1'" class="fa fa-thumbs-down text-warning" style="margin-left:30px"/> - <t t-if="vote.post_id.parent_id"> - <a t-attf-href="/forum/#{ slug(forum) }/question/#{ vote.post_id.parent_id.id }/#answer-#{ vote.post_id.id }" t-esc="vote.post_id.parent_id.name" style="margin-left:10px"/> - </t> - <t t-if="not vote.post_id.parent_id"> - <a t-attf-href="/forum/#{ slug(forum) }/question/#{ vote.post_id.id }" style=" color:black;margin-left:10px" t-esc="vote.post_id.name"/> - </t> + <ul class="nav nav-tabs"> + <li class="active"> + <a href="#questions" data-toggle="tab"><t t-esc="len(questions)"/> Questions</a> + </li> + <li> + <a href="#answers" data-toggle="tab"><t t-esc="len(answers)"/> Answers</a> + </li> + <li t-if="uid == user.id"> + <a href="#favourite_question" data-toggle="tab"><t t-esc="len(favourite)"/> Favourite Questions</a> + </li> + <li t-if="uid == user.id"> + <a href="#followed_question" data-toggle="tab"><t t-esc="len(followed)"/> Followed Questions</a> + </li> + <li t-if="uid == user.id"> + <a href="#activity" data-toggle="tab">Activity</a> + </li> + <li> + <a href="#badges" data-toggle="tab">Badges</a> + </li> + <li t-if="uid == user.id"> + <a href="#votes" data-toggle="tab">Votes</a> + </li> + </ul> + <div class="tab-content mt16"> + <div class="tab-pane active" id="questions"> + <div class="mb16" t-foreach="questions" t-as="question"> + <t t-call="website_forum.display_post"/> + </div> + </div><div class="tab-pane" id="answers"> + <div t-foreach="answers" t-as="answer"> + <t t-call="website_forum.display_post_answer"/> + </div> </div> - <div class="mb16" t-if="not vote_post"> - <b>No vote given by you yet!</b> + <div class="tab-pane" id="karma"> + <h1>Karma</h1> </div> - </template> - - <template id="post_list_answer"> - <div class="clearfix"> - <div t-attf-class="pull-left text-center mb16 box #{len(answer.vote_ids) and 'oe_green' or 'oe_grey'}"> - <div t-esc="len(answer.vote_ids)"/> + <div class="tab-pane" id="badges"> + <t t-call="website_forum.user_badges"/> + </div> + <div class="tab-pane" id="favourite_question"> + <div t-foreach="favourite" t-as="question"> + <t t-call="website_forum.display_post"/> </div> - <div class="question-name" style="margin-left: 32px;"> - <a style="font-size: 15px;" t-attf-href="/forum/#{ slug(forum) }/question/#{ answer.parent_id.id }/#answer-#{ answer.id }" t-esc="answer.parent_id.name"/> - <t t-if="len(answer.website_message_ids)>0"> - (<t t-esc="len(answer.website_message_ids)"/> - <t t-if="len(answer.website_message_ids)>1">Comments</t> - <t t-if="len(answer.website_message_ids)<=1">Comment</t>) - </t> + </div> + <div class="tab-pane" id="followed_question"> + <div t-foreach="followed" t-as="question"> + <t t-call="website_forum.display_post"/> </div> </div> - </template> + <div class="tab-pane" id="votes"> + <t t-call="website_forum.user_votes"/> + </div> + <div class="tab-pane" id="activity"> + <ul class="list-unstyled"> + <li t-foreach="activities" t-as="activity"> + <span t-field="activity.date" t-field-options='{"format": "short"}'/> + <span t-esc="activity.subtype_id.name" class="label label-info"/> + <t t-set="post" t-value="posts[activity.res_id]"/> + <span t-if="post[1]"> + <a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post[0]) }#answer-#{ str(post[1].id) }"> + <span t-esc="post[0].name"/> + </a> + </span> + <span t-if="not post[1]"> + <a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post[0]) }"> + <span t-esc="post[0].name"/> + </a> + </span> + </li> + </ul> + </div> + </div> + </t> +</template> + +<template id="user_badges"> + <table class="table mt32 mb64"> + <tr t-foreach="user.badge_ids" t-as="badge"> + <td> + <a t-attf-href="/forum/#{ slug(forum) }/badge/#{ slug(badge.badge_id) }" class="badge pull-left"> + <span t-if="badge.badge_id.level == 'gold'" class="fa fa-circle badge-gold"/> + <span t-if="badge.badge_id.level == 'silver'" class="fa fa-circle badge-silver"/> + <span t-if="badge.badge_id.level == 'bronze'" class="fa fa-circle badge-bronze"/> + <span t-field="badge.badge_id.name"/> + </a> + </td><td> + <b t-esc="badge.badge_id.stat_count_distinct"/> + <i class="text-muted">awarded users</i> + </td><td> + <span t-field="badge.badge_id.description"/> + </td> + </tr> + </table> + <div class="mb16" t-if="not user.badge_ids"> + <b>No badge yet!</b><br/> + <a t-attf-href="/forum/#{ slug(forum) }/badge" class="fa fa-arrow-right"> Check available badges</a> + </div> +</template> + +<template id="user_votes"> + <div t-foreach="vote_post" t-as="vote"> + <t t-esc="vote.post_id.create_date"/> + <span t-if="vote.vote == '1'" class="fa fa-thumbs-up text-success" style="margin-left:30px"/> + <span t-if="vote.vote == '-1'" class="fa fa-thumbs-down text-warning" style="margin-left:30px"/> + <t t-if="vote.post_id.parent_id"> + <a t-attf-href="/forum/#{ slug(forum) }/question/#{ vote.post_id.parent_id.id }/#answer-#{ vote.post_id.id }" t-esc="vote.post_id.parent_id.name" style="margin-left:10px"/> + </t> + <t t-if="not vote.post_id.parent_id"> + <a t-attf-href="/forum/#{ slug(forum) }/question/#{ vote.post_id.id }" style=" color:black;margin-left:10px" t-esc="vote.post_id.name"/> + </t> + </div> + <div class="mb16" t-if="not vote_post"> + <b>No vote given by you yet!</b> + </div> +</template> </data> </openerp> |
