Merge lp:~openerp-groupes/openobject-addons/base_module_doc_rst_improvements into lp:openobject-addons

Proposed by Olivier Ligot on 2010-10-05
Status: Superseded
Proposed branch: lp:~openerp-groupes/openobject-addons/base_module_doc_rst_improvements
Merge into: lp:openobject-addons
Diff against target: 162 lines (+46/-21)
4 files modified
base_module_doc_rst/base_module_doc_rst.py (+39/-18)
base_module_doc_rst/base_module_doc_rst_view.xml (+4/-0)
base_module_doc_rst/report/report_proximity_graph.py (+1/-1)
base_module_doc_rst/wizard/generate_relation_graph.py (+2/-2)
To merge this branch: bzr merge lp:~openerp-groupes/openobject-addons/base_module_doc_rst_improvements
Reviewer Review Type Date Requested Status
OpenERP Core Team 2010-10-05 Pending
Review via email: mp+37568@code.launchpad.net

This proposal has been superseded by a proposal from 2011-10-05.

Description of the change

This branch improves the module base_module_doc_rst by adding 3 news fields on ir.module.module:
- level: number of times a model is processed when it is in relation with another model
- filter_model_ids: filter the models taken into account to generate the relationship graph
- dot_graph: save the generated graph as a DOT file

To post a comment you must log in.
Fabien (Open ERP) (fp-tinyerp) wrote :

seems good

Julien Thewys (julien-thewys) wrote :

Looks like this has actually never been merged.
Could you make it so?

Unmerged revisions

4152. By Olivier Ligot on 2010-10-04

[ADD] dot_graph field on ir.module.module object

This new field allows to save the generated graph as a DOT file

4151. By Olivier Ligot on 2010-10-04

[FIX] same variable name (id)

4150. By Olivier Ligot on 2010-10-04

[ADD] filter_model_ids field on ir.module.module object

This new field allows to filter the models taken into account to generate the relationship graph

4149. By Olivier Ligot on 2010-10-04

[ADD] level field on ir.module.module object

This new field allows to specify the number of times a model is processed when it is in relation with another model.

4148. By Olivier Ligot on 2010-10-04

[REM] Useless code

4147. By Olivier Ligot on 2010-10-01

[FIX] DOT file label

4146. By Xavier (Open ERP) on 2010-09-30

[FIX] account_voucher: fix sales_reicept tests to assert on the status of 'reconciled' rather than print random stuff to stdout

4145. By Launchpad Translations on behalf of openerp on 2010-09-30

Launchpad automatic translations update.

4144. By Borja (Pexego) on 2010-09-29

[FIX] Merged Borja's branch for correction on Invoice correctd workflow action of sale order

4143. By Harry (OpenERP) on 2010-09-29

[FIX] stock_planning, hr_attendance: resolve regression after rev:4139

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'base_module_doc_rst/base_module_doc_rst.py'
2--- base_module_doc_rst/base_module_doc_rst.py 2010-08-19 11:51:57 +0000
3+++ base_module_doc_rst/base_module_doc_rst.py 2010-10-05 07:51:48 +0000
4@@ -32,21 +32,32 @@
5 _description = 'Module With Relationship Graph'
6 _columns = {
7 'file_graph': fields.binary('Relationship Graph'),
8+ 'level': fields.integer('Level', help="""Number of times a model is processed
9+when it is in relation with another model."""),
10+ 'filter_model_ids': fields.many2many('ir.model', 'module_filter_model_rel', 'module_id', 'model_id', 'Filter models'),
11+ 'dot_graph': fields.binary('Graph (DOT file)'),
12 }
13
14- def _get_graphical_representation(self, cr, uid, model_ids, level=1, context={}):
15+ _defaults = {
16+ 'level': 1
17+ }
18+
19+ def _get_graphical_representation(self, cr, uid, module_id, model_ids, level=1, context={}):
20 obj_model = self.pool.get('ir.model')
21 if level == 0:
22 return tuple()
23 relation = []
24+ module = self.browse(cr, uid, module_id, context=context)
25+ filter_models = [model.model for model in module.filter_model_ids]
26 for id in model_ids:
27 model_data = obj_model.browse(cr, uid, id, context=context)
28 for field in (f for f in model_data.field_id if f.ttype in ('many2many', 'many2one', 'one2many')):
29- relation.append((model_data.model, field.name, field.ttype, field.relation, field.field_description))
30- new_model_ids = obj_model.search(cr, uid, [('model', '=', field.relation)], context=context)
31- if new_model_ids:
32- model = obj_model.read(cr, uid, new_model_ids, ['id', 'name'], context=context)[0]
33- relation.extend(self._get_graphical_representation(cr, uid, model['id'], level - 1))
34+ if not filter_models or field.relation in filter_models:
35+ relation.append((model_data.model, field.name, field.ttype, field.relation, field.field_description))
36+ new_model_ids = obj_model.search(cr, uid, [('model', '=', field.relation)], context=context)
37+ if new_model_ids:
38+ model = obj_model.read(cr, uid, new_model_ids, ['id', 'name'], context=context)[0]
39+ relation.extend(self._get_graphical_representation(cr, uid, module_id, [model['id']], level - 1))
40 return tuple(relation)
41
42 def _get_structure(self, relations, main_element):
43@@ -70,7 +81,7 @@
44 'one2many': 'arrowtail="none" arrowhead="crow" color="blue" label="o2m"',
45 }[field_type]
46
47- def get_graphical_representation(self, cr, uid, model_ids, context=None):
48+ def get_graphical_representation(self, cr, uid, id, model_ids, context=None):
49 obj_model = self.pool.get('ir.model')
50 if context is None:
51 context = {}
52@@ -78,7 +89,7 @@
53 models = []
54 for obj in obj_model.browse(cr, uid, model_ids, context=context):
55 models.append(obj.model)
56- relations = set(self._get_graphical_representation(cr, uid, model_ids, context.get('level', 1)))
57+ relations = set(self._get_graphical_representation(cr, uid, id, model_ids, context.get('level', 1)))
58 res[obj.model] = "digraph G {\nnode [style=rounded, shape=record];\n%s\n%s }" % (
59 self._get_structure(relations, models),
60 ''.join('"%s":%s -> "%s":id:n [%s]; // %s\n' % (m, fn, fr, self._get_arrow(ft),ft) for m, fn, ft, fr, fl in relations),
61@@ -86,23 +97,28 @@
62 return res
63
64 def _get_module_objects(self, cr, uid, module, context={}):
65- obj_model = self.pool.get('ir.model')
66 obj_mod_data = self.pool.get('ir.model.data')
67- obj_ids = []
68 model_data_ids = obj_mod_data.search(cr, uid, [('module', '=', module), ('model', '=', 'ir.model')], context=context)
69 model_ids = []
70+ module_id = self.search(cr, uid, [('name', '=', module)])[0]
71+ module = self.browse(cr, uid, module_id, context=context)
72+ filter_model_ids = [model.id for model in module.filter_model_ids]
73 for mod in obj_mod_data.browse(cr, uid, model_data_ids, context=context):
74- model_ids.append(mod.res_id)
75- models = obj_model.browse(cr, uid, model_ids, context=context)
76- map(lambda x: obj_ids.append(x.id),models)
77- return obj_ids
78+ if not filter_model_ids or mod.res_id in filter_model_ids:
79+ model_ids.append(mod.res_id)
80+ return model_ids
81
82 def get_relation_graph(self, cr, uid, module_name, context=None):
83+ if context is None:
84+ context = {}
85+ result = {}
86 object_ids = self._get_module_objects(cr, uid, module_name, context=context)
87 if not object_ids:
88- return {'module_file': False}
89- context.update({'level': 1})
90- dots = self.get_graphical_representation(cr, uid, object_ids, context=context)
91+ return False
92+ module_id = self.search(cr, uid, [('name', '=', module_name)])[0]
93+ module = self.browse(cr, uid, module_id)
94+ context.update({'level': module.level})
95+ dots = self.get_graphical_representation(cr, uid, module_id, object_ids, context=context)
96 # todo: use os.realpath
97 file_path = tools.config['addons_path']+"/base_module_doc_rst/"
98 path_png = file_path + "/module.png"
99@@ -111,12 +127,17 @@
100 fp = file(path_dotfile, "w")
101 fp.write(val)
102 fp.close()
103+ fp = file(path_dotfile, "r")
104+ x = fp.read()
105+ fp.close()
106+ result['dot_graph'] = base64.encodestring(x)
107 os.popen('dot -Tpng' +' '+ path_dotfile + ' '+ '-o' +' ' + path_png)
108 fp = file(path_png, "r")
109 x = fp.read()
110 fp.close()
111 os.popen('rm ' + path_dotfile + ' ' + path_png)
112- return {'module_file': base64.encodestring(x)}
113+ result['file_graph'] = base64.encodestring(x)
114+ return result
115
116 module()
117
118
119=== modified file 'base_module_doc_rst/base_module_doc_rst_view.xml'
120--- base_module_doc_rst/base_module_doc_rst_view.xml 2010-05-19 15:57:31 +0000
121+++ base_module_doc_rst/base_module_doc_rst_view.xml 2010-10-05 07:51:48 +0000
122@@ -14,8 +14,12 @@
123 <field name="arch" type="xml">
124 <notebook position="inside">
125 <page string="Relationship Graph">
126+ <separator colspan="4" string="You can filter the models taken into account to generate the graph"/>
127+ <field name="filter_model_ids" colspan="4" nolabel="1"/>
128+ <field name="level"/>
129 <separator colspan="4" string="You can save this image as .png file"/>
130 <field name="file_graph" widget="image" nolabel="1" />
131+ <field name="dot_graph"/>
132 </page>
133 </notebook>
134 </field>
135
136=== modified file 'base_module_doc_rst/report/report_proximity_graph.py'
137--- base_module_doc_rst/report/report_proximity_graph.py 2010-08-19 11:51:57 +0000
138+++ base_module_doc_rst/report/report_proximity_graph.py 2010-10-05 07:51:48 +0000
139@@ -48,7 +48,7 @@
140 if id:
141 get_dpend_module(id[0].id)
142 get_dpend_module(module_id)
143- graph = pydot.Dot(graph_type='digraph',fontsize='10', label="\\nProximity Graph. \\n\\nGray Color:Official Modules, Red Color:Extra Addons Modules, Blue Color:Community Modules, Purple Color:Unknow Modules"
144+ graph = pydot.Dot(graph_type='digraph',fontsize='10', label='"\\nProximity Graph. \\n\\nGray Color:Official Modules, Red Color:Extra Addons Modules, Blue Color:Community Modules, Purple Color:Unknow Modules"'
145 , center='1')
146 for node in nodes:
147 if node[1] == "official":
148
149=== modified file 'base_module_doc_rst/wizard/generate_relation_graph.py'
150--- base_module_doc_rst/wizard/generate_relation_graph.py 2010-05-19 15:57:31 +0000
151+++ base_module_doc_rst/wizard/generate_relation_graph.py 2010-10-05 07:51:48 +0000
152@@ -33,8 +33,8 @@
153 modules = mod_obj.browse(cr, uid, datas['ids'], context=context)
154 for module in modules:
155 module_data = mod_obj.get_relation_graph(cr, uid, module.name, context=context)
156- if module_data['module_file']:
157- mod_obj.write(cr, uid, [module.id], {'file_graph': module_data['module_file']}, context=context)
158+ if module_data:
159+ mod_obj.write(cr, uid, [module.id], module_data, context=context)
160 return {}
161
162 class create_graph(wizard.interface):

Subscribers

People subscribed via source and target branches

to all changes: