summaryrefslogtreecommitdiff
path: root/addons/website_forum_doc/controllers
diff options
context:
space:
mode:
authorSrushti Patel <shp@odoo.com>2015-09-09 17:38:50 +0530
committerDavid Monjoie <dmo@odoo.com>2016-04-08 13:54:07 +0200
commit1e9b6b4cb4914159d9b18ec00a861da3542bd3e5 (patch)
tree9c480f530174efd2db090ca40123cf4659a11ac1 /addons/website_forum_doc/controllers
parentb88060e5bae0d239a2b7879b9661d015ec9df3b9 (diff)
[MIG] website_forum_doc: migrated to new api
Diffstat (limited to 'addons/website_forum_doc/controllers')
-rw-r--r--addons/website_forum_doc/controllers/main.py41
1 files changed, 13 insertions, 28 deletions
diff --git a/addons/website_forum_doc/controllers/main.py b/addons/website_forum_doc/controllers/main.py
index a34e8eef2a1..6817a7e5ef0 100644
--- a/addons/website_forum_doc/controllers/main.py
+++ b/addons/website_forum_doc/controllers/main.py
@@ -1,23 +1,19 @@
# -*- coding: utf-8 -*-
-from openerp import http
-from openerp.http import request
-from openerp.addons.website.models.website import slug
+from odoo import http
+from odoo.http import request
class WebsiteDoc(http.Controller):
@http.route(['/forum/how-to', '/forum/how-to/<model("forum.documentation.toc"):toc>'], type='http', auth="public", website=True)
def toc(self, toc=None, **kwargs):
- cr, uid, context, toc_id = request.cr, request.uid, request.context, False
if toc:
sections = toc.child_ids
forum = toc.forum_id
else:
- toc_obj = request.registry['forum.documentation.toc']
- obj_ids = toc_obj.search(cr, uid, [('parent_id', '=', False)], context=context)
- sections = toc_obj.browse(cr, uid, obj_ids, context=context)
- forum = sections and sections[0].forum_id or False
+ sections = request.env['forum.documentation.toc'].search([('parent_id', '=', False)], limit=1)
+ forum = sections and sections.forum_id
value = {
'toc': toc,
'main_object': toc or forum,
@@ -29,7 +25,7 @@ class WebsiteDoc(http.Controller):
@http.route(['''/forum/how-to/<model("forum.documentation.toc"):toc>/<model("forum.post", "[('documentation_toc_id','=',toc[0])]"):post>'''], type='http', auth="public", website=True)
def post(self, toc, post, **kwargs):
# TODO: implement a redirect instead of crash
- assert post.documentation_toc_id.id == toc.id, "Wrong post!"
+ assert post.documentation_toc_id == toc, "Wrong post!"
value = {
'toc': toc,
'post': post,
@@ -40,31 +36,20 @@ class WebsiteDoc(http.Controller):
@http.route('/forum/<model("forum.forum"):forum>/question/<model("forum.post"):post>/promote', type='http', auth="user", website=True)
def post_toc(self, forum, post, **kwargs):
- cr, uid, context, toc_id = request.cr, request.uid, request.context, False
- user = request.registry['res.users'].browse(cr, uid, uid, context=context)
- assert user.karma >= 200, 'You need 200 karma to promote a post to the documentation'
- toc_obj = request.registry['forum.documentation.toc']
- obj_ids = toc_obj.search(cr, uid, [], context=context)
- tocs = toc_obj.browse(cr, uid, obj_ids, context=context)
+ assert request.env.user.karma >= 200, 'You need 200 karma to promote a post to the documentation'
value = {
'post': post,
'forum': post.forum_id,
- 'chapters': filter(lambda x: not x.child_ids, tocs)
+ 'chapters': request.env['forum.documentation.toc'].search([('child_ids', '=', False)])
}
return request.website.render("website_forum_doc.promote_question", value)
@http.route('/forum/<model("forum.forum"):forum>/promote_ok', type='http', auth="user", website=True)
def post_toc_ok(self, forum, post_id, toc_id, **kwargs):
- cr, uid, context = request.cr, request.uid, request.context
- user = request.registry['res.users'].browse(cr, uid, uid, context=context)
- assert user.karma >= 200, 'Not enough karma, you need 200 to promote a documentation.'
-
- toc_obj = request.registry['forum.documentation.toc']
- stage_ids = toc_obj.search(cr, uid, [], limit=1, context=context)
-
- post_obj = request.registry['forum.post']
- post_obj.write(cr, uid, [int(post_id)], {
+ assert request.env.user.karma >= 200, 'Not enough karma, you need 200 to promote a documentation.'
+ stage = request.env['forum.documentation.toc'].search([], limit=1)
+ request.env['forum.post'].browse(int(post_id)).write({
'documentation_toc_id': toc_id and int(toc_id) or False,
- 'documentation_stage_id': stage_ids and stage_ids[0] or False
- }, context=context)
- return request.redirect('/forum/'+str(forum.id)+'/question/'+str(post_id))
+ 'documentation_stage_id': stage and stage.id
+ })
+ return request.redirect('/forum/' + str(forum.id) + '/question/' + str(post_id))