[MIG] website_forum_doc: migrated to new api

This commit is contained in:
Srushti Patel
2016-04-08 13:54:07 +02:00
committed by David Monjoie
parent b88060e5ba
commit 1e9b6b4cb4
7 changed files with 59 additions and 106 deletions
+13 -28
View File
@@ -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))
+2 -2
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data>
<!-- JUMP TO DOCUMENTATION AT INSTALL -->
<record id="action_open_documentation" model="ir.actions.act_url">
@@ -45,4 +45,4 @@
</record>
</data>
</openerp>
</odoo>
+2 -4
View File
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<!-- Table Of Content -->
<record id="toc_functional_doc" model="forum.documentation.toc">
@@ -88,5 +87,4 @@
<field name="documentation_toc_id" ref="toc_cms_ecommerce"/>
</record>
</data>
</openerp>
</odoo>
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
from openerp.osv import osv, fields
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
class Documentation(osv.Model):
class Documentation(models.Model):
_name = 'forum.documentation.toc'
_description = 'Documentation ToC'
_inherit = ['website.seo.metadata']
@@ -11,48 +12,36 @@ class Documentation(osv.Model):
_parent_order = "sequence, name"
_parent_store = True
def name_get(self, cr, uid, ids, context=None):
if isinstance(ids, (list, tuple)) and not len(ids):
return []
if isinstance(ids, (long, int)):
ids = [ids]
reads = self.read(cr, uid, ids, ['name', 'parent_id'], context=context)
sequence = fields.Integer('Sequence')
name = fields.Char('Name', required=True, translate=True)
introduction = fields.Html('Introduction', translate=True)
parent_id = fields.Many2one('forum.documentation.toc', string='Parent Table Of Content', ondelete='cascade')
child_ids = fields.One2many('forum.documentation.toc', 'parent_id', string='Children Table Of Content')
parent_left = fields.Integer(string='Left Parent', index=True)
parent_right = fields.Integer(string='Right Parent', index=True)
post_ids = fields.One2many('forum.post', 'documentation_toc_id', string='Posts')
forum_id = fields.Many2one('forum.forum', string='Forum', required=True)
@api.multi
def name_get(self):
res = []
for record in reads:
name = record['name']
if record['parent_id']:
name = record['parent_id'][1]+' / '+name
res.append((record['id'], name))
for record in self:
name = record.name
if record.parent_id:
name = record.parent_id.name + ' / ' + name
res.append((record.id, name))
return res
# TODO master remove me
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
res = self.name_get(cr, uid, ids, context=context)
return dict(res)
_columns = {
'sequence': fields.integer('Sequence'),
'name': fields.char('Name', required=True, translate=True),
'introduction': fields.html('Introduction', translate=True),
'parent_id': fields.many2one('forum.documentation.toc', 'Parent Table Of Content', ondelete='cascade'),
'child_ids': fields.one2many('forum.documentation.toc', 'parent_id', 'Children Table Of Content'),
'parent_left': fields.integer('Left Parent', select=True),
'parent_right': fields.integer('Right Parent', select=True),
'post_ids': fields.one2many('forum.post', 'documentation_toc_id', 'Posts'),
'forum_id': fields.many2one('forum.forum', 'Forum', required=True),
}
_constraints = [
(osv.osv._check_recursion, 'Error ! You cannot create recursive categories.', ['parent_id'])
]
@api.constrains('parent_id')
def _check_parent_id(self):
if not self._check_recursion():
raise ValidationError(_('Error ! You cannot create recursive categories.'))
class DocumentationStage(osv.Model):
class DocumentationStage(models.Model):
_name = 'forum.documentation.stage'
_description = 'Post Stage'
_order = 'sequence'
_columns = {
'sequence': fields.integer('Sequence'),
'name': fields.char('Stage Name', required=True, translate=True),
}
sequence = fields.Integer('Sequence')
name = fields.Char(string='Stage Name', required=True, translate=True)
+9 -20
View File
@@ -1,30 +1,19 @@
# -*- coding: utf-8 -*-
from openerp.osv import osv, fields
from odoo import api, fields, models
class Post(osv.Model):
class Post(models.Model):
_inherit = 'forum.post'
_columns = {
'documentation_toc_id': fields.many2one('forum.documentation.toc', 'Documentation ToC', ondelete='set null'),
'documentation_stage_id': fields.many2one('forum.documentation.stage', 'Documentation Stage'),
'color': fields.integer('Color Index')
}
documentation_toc_id = fields.Many2one('forum.documentation.toc', string='Documentation ToC', ondelete='set null')
documentation_stage_id = fields.Many2one('forum.documentation.stage', string='Documentation Stage',
default=lambda self: self.env['forum.documentation.stage'].search([], limit=1))
color = fields.Integer(string='Color Index')
def _get_default_stage_id(self, cr, uid, context=None):
stage_ids = self.pool["forum.documentation.stage"].search(cr, uid, [], limit=1, context=context)
return stage_ids and stage_ids[0] or False
_defaults = {
'documentation_stage_id': _get_default_stage_id,
}
def _read_group_stage_ids(self, cr, uid, ids, domain, read_group_order=None, access_rights_uid=None, context=None):
stage_obj = self.pool.get('forum.documentation.stage')
stage_ids = stage_obj.search(cr, uid, [], context=context)
result = stage_obj.name_get(cr, uid, stage_ids, context=context)
return result, {}
@api.multi
def _read_group_stage_ids(self, domain, read_group_order=None, access_rights_uid=None):
return self.env['forum.documentation.stage'].search([]).name_get(), {}
_group_by_full = {
'documentation_stage_id': _read_group_stage_ids,
+4 -8
View File
@@ -1,7 +1,5 @@
<?xml version="1.0"?>
<openerp>
<data>
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- DOCUMENTATION TOC VIEWS -->
<record id="view_documentation_toc_list" model="ir.ui.view">
<field name="name">forum.documentation.toc.list</field>
@@ -27,7 +25,7 @@
<!-- Project Task Kanban View -->
<record model="ir.ui.view" id="view_forum_post_kanban">
<record id="view_forum_post_kanban" model="ir.ui.view">
<field name="name">forum.post.kanban</field>
<field name="model">forum.post</field>
<field name="arch" type="xml">
@@ -100,6 +98,4 @@
</xpath>
</field>
</record>
</data>
</openerp>
</odoo>
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<!-- Front-end assets: custom css -->
<template id="assets_frontend" inherit_id="website.assets_frontend" name="website_forum_doc assets">
@@ -268,7 +267,4 @@
</section>
</t>
</template>
</data>
</openerp>
</odoo>