# Post
# --------------------------------------------------
-
- @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/new', type='http', auth="public", methods=['POST'], website=True)
- def post_new(self, forum, post, **kwargs):
+ @http.route(['/forum/<model("forum.forum"):forum>/ask'], type='http', auth="public", website=True)
+ def forum_post(self, forum, post_type=None, **post):
if not request.session.uid:
return login_redirect()
- cr, uid, context = request.cr, request.uid, request.context
- user = request.registry['res.users'].browse(cr, SUPERUSER_ID, uid, context=context)
+ user = request.env.user
+ if not post_type in ['question', 'link', 'discussion']: # fixme: make dynamic
+ return werkzeug.utils.redirect('/forum/%s' % slug(forum))
if not user.email or not tools.single_email_re.match(user.email):
- return werkzeug.utils.redirect("/forum/%s/user/%s/edit?email_required=1" % (slug(forum), uid))
- request.registry['forum.post'].create(
- request.cr, request.uid, {
- 'forum_id': forum.id,
- 'parent_id': post.id,
- 'content': kwargs.get('content'),
- }, context=request.context)
- return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(post)))
+ return werkzeug.utils.redirect("/forum/%s/user/%s/edit?email_required=1" % (slug(forum), request.session.uid))
+ values = self._prepare_forum_values(forum=forum, searches={}, header={'ask_hide': True})
+ return request.website.render("website_forum.new_%s" % post_type, values)
+
+ @http.route(['/forum/<model("forum.forum"):forum>/new',
+ '/forum/<model("forum.forum"):forum>/<model("forum.post"):post_parent>/reply'],
+ type='http', auth="public", methods=['POST'], website=True)
+ def post_create(self, forum, post_parent=None, post_type=None, **post):
+ cr, uid, context = request.cr, request.uid, request.context
+ if not request.session.uid:
+ return login_redirect()
+
- post_tag_ids = forum.tag_to_write_vals(post.get('post_tags', False))
++ post_tag_ids = forum._tag_to_write_vals(post.get('post_tags', False))
+ new_question = request.env['forum.post'].create({
+ 'forum_id': forum.id,
+ 'name': post.get('post_name', ''),
+ 'content': post.get('content', False),
+ 'content_link': post.get('content_link', False),
+ 'parent_id': post_parent and post_parent.id or False,
+ 'tag_ids': post_tag_ids,
+ 'post_type': post_parent and post_parent.post_type or post_type, # tde check in selection field
+ })
+ return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), post_parent and slug(post_parent) or new_question.id))
@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):
})
return request.website.render("website_forum.edit_post", values)
- @http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/edition', type='http', auth="user", website=True)
- def post_edit_retro(self, forum, post, **kwargs):
- # This function is only there for retrocompatibility between old template using texttext and template using select2
- # It should be removed into master #TODO JKE: remove in master all condition with tag_type
- kwargs.update(tag_type="select2")
- return self.post_edit(forum, post, **kwargs)
-
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/save', type='http', auth="user", methods=['POST'], website=True)
def post_save(self, forum, post, **kwargs):
- post_tags = forum.tag_to_write_vals(kwargs.get('post_tag', ''))
- cr, uid, context = request.cr, request.uid, request.context
- question_tags = []
- Tag = request.registry['forum.tag']
- tag_version = kwargs.get('tag_type', 'texttext')
- if tag_version == "texttext": # old version - retro v8 - #TODO Remove in master
- if kwargs.get('question_tag') and kwargs.get('question_tag').strip('[]'):
- tags = kwargs.get('question_tag').strip('[]').replace('"', '').split(",")
- for tag in tags:
- tag_ids = Tag.search(cr, uid, [('name', '=', tag)], context=context)
- if tag_ids:
- question_tags += tag_ids
- else:
- new_tag = Tag.create(cr, uid, {'name': tag, 'forum_id': forum.id}, context=context)
- question_tags.append(new_tag)
- tags_val = [(6, 0, question_tags)]
- elif tag_version == "select2": # new version
- tags_val = forum._tag_to_write_vals(cr, uid, kwargs.get('question_tag', ''), context=context)
-
++ post_tags = forum._tag_to_write_vals(kwargs.get('post_tag', ''))
vals = {
- 'tag_ids': tags_val,
- 'name': kwargs.get('question_name'),
+ 'tag_ids': post_tags,
+ 'name': kwargs.get('post_name'),
'content': kwargs.get('content'),
}
- request.registry['forum.post'].write(cr, uid, [post.id], vals, context=context)
+ post.write(vals)
question = post.parent_id if post.parent_id else post
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), slug(question)))
return f.read()
return False
- _defaults = {
- 'description': 'This community is for professionals and enthusiasts of our products and services.',
- 'faq': _get_default_faq,
- 'karma_gen_question_new': 0, # set to null for anti spam protection
- 'karma_gen_question_upvote': 5,
- 'karma_gen_question_downvote': -2,
- 'karma_gen_answer_upvote': 10,
- 'karma_gen_answer_downvote': -2,
- 'karma_gen_answer_accept': 2,
- 'karma_gen_answer_accepted': 15,
- 'karma_gen_answer_flagged': -100,
- 'karma_ask': 3, # set to not null for anti spam protection
- 'karma_answer': 3, # set to not null for anti spam protection
- 'karma_edit_own': 1,
- 'karma_edit_all': 300,
- 'karma_close_own': 100,
- 'karma_close_all': 500,
- 'karma_unlink_own': 500,
- 'karma_unlink_all': 1000,
- 'karma_upvote': 5,
- 'karma_downvote': 50,
- 'karma_answer_accept_own': 20,
- 'karma_answer_accept_all': 500,
- 'karma_editor_link_files': 20,
- 'karma_editor_clickable_link': 20,
- 'karma_comment_own': 3,
- 'karma_comment_all': 5,
- 'karma_comment_convert_own': 50,
- 'karma_comment_convert_all': 500,
- 'karma_comment_unlink_own': 50,
- 'karma_comment_unlink_all': 500,
- 'karma_retag': 75,
- 'karma_flag': 500,
- }
-
- def create(self, cr, uid, values, context=None):
- if context is None:
- context = {}
- create_context = dict(context, mail_create_nolog=True)
- return super(Forum, self).create(cr, uid, values, context=create_context)
-
- def _tag_to_write_vals(self, cr, uid, tags='', context=None):
- User = self.pool['res.users']
- Tag = self.pool['forum.tag']
+ # description and use
+ name = fields.Char('Forum Name', required=True, translate=True)
+ faq = fields.Html('Guidelines', default=_get_default_faq, translate=True)
+ description = fields.Html(
+ 'Description',
+ default='<p> This community is for professionals and enthusiasts of our products and services.'
+ 'Share and discuss the best content and new marketing ideas,'
+ 'build your professional profile and become a better marketer together.</p>')
+ default_order = fields.Selection([
+ ('create_date desc', 'Newest'),
+ ('write_date desc', 'Last Updated'),
+ ('vote_count desc', 'Most Voted'),
+ ('relevancy desc', 'Relevancy'),
+ ('child_count desc', 'Answered')],
+ string='Default Order', required=True, default='write_date desc')
+ relevancy_post_vote = fields.Float('First Relevancy Parameter', default=0.8)
+ relevancy_time_decay = fields.Float('Second Relevancy Parameter', default=1.8)
+ default_post_type = fields.Selection([
+ ('question', 'Question'),
+ ('discussion', 'Discussion'),
+ ('link', 'Link')],
+ string='Default Post', required=True, default='question')
+ allow_question = fields.Boolean('Questions', help="Users can answer only once per question. Contributors can edit answers and mark the right ones.", default=True)
+ allow_discussion = fields.Boolean('Discussions', default=False)
+ allow_link = fields.Boolean('Links', help="When clicking on the post, it redirects to an external link", default=False)
+ # karma generation
+ karma_gen_question_new = fields.Integer(string='Asking a question', default=2)
+ karma_gen_question_upvote = fields.Integer(string='Question upvoted', default=5)
+ karma_gen_question_downvote = fields.Integer(string='Question downvoted', default=-2)
+ karma_gen_answer_upvote = fields.Integer(string='Answer upvoted', default=10)
+ karma_gen_answer_downvote = fields.Integer(string='Answer downvoted', default=-2)
+ karma_gen_answer_accept = fields.Integer(string='Accepting an answer', default=2)
+ karma_gen_answer_accepted = fields.Integer(string='Answer accepted', default=15)
+ karma_gen_answer_flagged = fields.Integer(string='Answer flagged', default=-100)
+ # karma-based actions
+ karma_ask = fields.Integer(string='Ask a new question', default=3)
+ karma_answer = fields.Integer(string='Answer a question', default=3)
+ karma_edit_own = fields.Integer(string='Edit its own posts', default=1)
+ karma_edit_all = fields.Integer(string='Edit all posts', default=300)
+ karma_close_own = fields.Integer(string='Close its own posts', default=100)
+ karma_close_all = fields.Integer(string='Close all posts', default=500)
+ karma_unlink_own = fields.Integer(string='Delete its own posts', default=500)
+ karma_unlink_all = fields.Integer(string='Delete all posts', default=1000)
+ karma_upvote = fields.Integer(string='Upvote', default=5)
+ karma_downvote = fields.Integer(string='Downvote', default=50)
+ karma_answer_accept_own = fields.Integer(string='Accept an answer on its own questions', default=20)
+ karma_answer_accept_all = fields.Integer(string='Accept an answers to all questions', default=500)
+ karma_editor_link_files = fields.Integer(string='Linking files (Editor)', default=20)
+ karma_editor_clickable_link = fields.Integer(string='Add clickable links (Editor)', default=20)
+ karma_comment_own = fields.Integer(string='Comment its own posts', default=1)
+ karma_comment_all = fields.Integer(string='Comment all posts', default=1)
+ karma_comment_convert_own = fields.Integer(string='Convert its own answers to comments and vice versa', default=50)
+ karma_comment_convert_all = fields.Integer(string='Convert all answers to answers and vice versa', default=500)
+ karma_comment_unlink_own = fields.Integer(string='Unlink its own comments', default=50)
+ karma_comment_unlink_all = fields.Integer(string='Unlinnk all comments', default=500)
+ karma_retag = fields.Integer(string='Change question tags', default=75)
+ karma_flag = fields.Integer(string='Flag a post as offensive', default=500)
+
+ @api.model
+ def create(self, values):
+ return super(Forum, self.with_context(mail_create_nolog=True)).create(values)
+
+ @api.model
- def tag_to_write_vals(self, tags=''):
++ def _tag_to_write_vals(self, tags=''):
+ User = self.env['res.users']
+ Tag = self.env['forum.tag']
post_tags = []
for tag in filter(None, tags.split(',')):
if tag.startswith('_'): # it's a new tag