[IMP] improved form view for posts
[odoo/odoo.git] / addons / website_forum_doc / models / documentation.py
1 # -*- coding: utf-8 -*-
2
3 import openerp
4 from openerp.osv import osv, fields
5
6 class Documentation(osv.Model):
7     _name = 'forum.documentation.toc'
8     _description = 'Documentation ToC'
9     _inherit = ['website.seo.metadata']
10     _order = "parent_left"
11     _parent_order = "sequence, name"
12     _parent_store = True
13     def name_get(self, cr, uid, ids, context=None):
14         if isinstance(ids, (list, tuple)) and not len(ids):
15             return []
16         if isinstance(ids, (long, int)):
17             ids = [ids]
18         reads = self.read(cr, uid, ids, ['name','parent_id'], context=context)
19         res = []
20         for record in reads:
21             name = record['name']
22             if record['parent_id']:
23                 name = record['parent_id'][1]+' / '+name
24             res.append((record['id'], name))
25         return res
26
27     def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
28         res = self.name_get(cr, uid, ids, context=context)
29         return dict(res)
30
31     _columns = {
32         'sequence': fields.integer('Sequence'),
33         'display_name': fields.function(_name_get_fnc, type="char", string='Full Name'),
34         'name': fields.char('Name', required=True, translate=True),
35         'introduction': fields.html('Introduction', translate=True),
36         'parent_id': fields.many2one('forum.documentation.toc', 'Parent Table Of Content', ondelete='cascade'),
37         'child_ids': fields.one2many('forum.documentation.toc', 'parent_id', 'Children Table Of Content'),
38         'parent_left': fields.integer('Left Parent', select=True),
39         'parent_right': fields.integer('Right Parent', select=True),
40         'post_ids': fields.one2many('forum.post', 'documentation_toc_id', 'Posts'),
41         'forum_id': fields.many2one('forum.forum', 'Forum', required=True),
42     }
43
44     _constraints = [
45         (osv.osv._check_recursion, 'Error ! You cannot create recursive categories.', ['parent_id'])
46     ]
47
48
49 class DocumentationStage(osv.Model):
50     _name = 'forum.documentation.stage'
51     _description = 'Post Stage'
52     _order = 'sequence'
53     _columns = {
54         'sequence': fields.integer('Sequence'),
55         'name': fields.char('Stage Name', required=True, translate=True),
56     }
57
58
59 class Post(osv.Model):
60     _inherit = 'forum.post'
61     _columns = {
62         'documentation_toc_id': fields.many2one('forum.documentation.toc', 'Documentation ToC', ondelete='set null'),
63         'documentation_stage_id': fields.many2one('forum.documentation.stage', 'Documentation Stage'),
64         'color': fields.integer('Color Index')
65     }
66     def _read_group_stage_ids(self, cr, uid, ids, domain, read_group_order=None, access_rights_uid=None, context=None):
67         stage_obj = self.pool.get('forum.documentation.stage')
68         stage_ids = stage_obj.search(cr, uid, [], context=context)
69         result = stage_obj.name_get(cr, uid, stage_ids, context=context)
70         return result, {}
71
72     _group_by_full = {
73         'documentation_stage_id': _read_group_stage_ids,
74     }
75