~openerp-commiter/openobject-addons/trunk-training

« back to all changes in this revision

Viewing changes to base_module_doc_rst/base_module_doc_rst.py

  • Committer: HDA(OpenERP)
  • Date: 2010-05-17 11:25:04 UTC
  • mfrom: (4287.4.283 trunk-extra-addons)
  • Revision ID: hda@tinyerp.com-20100517112504-5ygd4t4w26sdz9f5
Merged with main traun extra addons

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
class module(osv.osv):
31
31
    _inherit = 'ir.module.module'
32
32
    _description = 'Module With Relationship Graph'
33
 
 
34
 
    _columns={
 
33
    _columns = {
35
34
        'file_graph': fields.binary('Relationship Graph'),
36
35
            }
37
36
 
38
 
    def _get_graphical_representation(self, cr, uid, model_ids, level=1, context=None):
 
37
    def _get_graphical_representation(self, cr, uid, model_ids, level=1, context={}):
 
38
        obj_model = self.pool.get('ir.model')
39
39
        if level == 0:
40
40
            return tuple()
41
41
        relation = []
42
42
        for id in model_ids:
43
 
            model_data = self.pool.get('ir.model').browse(cr, uid, id)
 
43
            model_data = obj_model.browse(cr, uid, id, context=context)
44
44
            for field in (f for f in model_data.field_id if f.ttype in ('many2many', 'many2one', 'one2many')):
45
45
                relation.append((model_data.model, field.name, field.ttype, field.relation, field.field_description))
46
 
                new_model_ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', field.relation)])
47
 
                model = self.pool.get('ir.model').read(cr, uid, new_model_ids, ['id', 'name'])[0]
48
 
                relation.extend(self._get_graphical_representation(cr, uid, model['id'], level - 1))
 
46
                new_model_ids = obj_model.search(cr, uid, [('model', '=', field.relation)], context=context)
 
47
                if new_model_ids:
 
48
                    model = obj_model.read(cr, uid, new_model_ids, ['id', 'name'], context=context)[0]
 
49
                    relation.extend(self._get_graphical_representation(cr, uid, model['id'], level - 1))
49
50
        return tuple(relation)
50
51
 
51
52
    def _get_structure(self, relations, main_element):
71
72
        }[field_type]
72
73
 
73
74
    def get_graphical_representation(self, cr, uid, model_ids, context=None):
 
75
        obj_model = self.pool.get('ir.model')
74
76
        if context is None:
75
77
            context = {}
76
78
        res = {}
77
79
        models = []
78
 
        for obj in self.pool.get('ir.model').browse(cr, uid, model_ids, context=context):
 
80
        for obj in obj_model.browse(cr, uid, model_ids, context=context):
79
81
            models.append(obj.model)
80
82
        relations = set(self._get_graphical_representation(cr, uid, model_ids, context.get('level', 1)))
81
83
        res[obj.model] = "digraph G {\nnode [style=rounded, shape=record];\n%s\n%s }" % (
98
100
 
99
101
    def get_relation_graph(self, cr, uid, module_name, context=None):
100
102
        object_ids = self._get_module_objects(cr, uid, module_name, context=context)
101
 
#        if not object_ids:
 
103
        if not object_ids:
 
104
            return {'module_file': False}
102
105
#            raise orm.except_orm(_('Warning'),
103
106
#                 _('No object available on this module or Module is not installed'))
104
 
        if not object_ids:
105
 
            return {'module_file': False}
106
107
        context.update({'level': 1})
107
108
        dots = self.get_graphical_representation(cr, uid, object_ids, context=context)
108
109
        # todo: use os.realpath