mirror of
https://github.com/NaN-tic/trydoc.git
synced 2023-12-14 02:03:42 +01:00
Make menu directive more generic to allow referring to any XML id and rename it to tryref.
This commit is contained in:
parent
a2b16cd56e
commit
ab59e790d8
|
@ -54,26 +54,6 @@ added. See the following example:
|
|||
.. fields:: ir.cron/user
|
||||
:help:
|
||||
|
||||
Menus
|
||||
~~~~~
|
||||
|
||||
You can refer to any menu entry with the following directive:
|
||||
|
||||
::
|
||||
|
||||
.. menu:: reference_to_menu_xml_id
|
||||
:nameonly:
|
||||
|
||||
The following code shows the full menu entry:
|
||||
|
||||
::
|
||||
|
||||
.. menu:: ir.menu_cron_form
|
||||
|
||||
which will output *Administration / Scheduler / Scheduled Actions*.
|
||||
Appending the ``:nameonly:`` flag will only show the menu entry name:
|
||||
*Scheduled Actions*.
|
||||
|
||||
Views
|
||||
~~~~~
|
||||
|
||||
|
@ -95,6 +75,32 @@ the generated screenshot.
|
|||
.. Note:: This directive is not fully working yet. It will add a screenshot of
|
||||
tryton's client but not of the appropriate view.
|
||||
|
||||
Menus and other data
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
You can refer to any menu entry with the following directive:
|
||||
|
||||
::
|
||||
|
||||
.. tryref:: reference_to_menu_xml_id/fieldname
|
||||
|
||||
The following code shows the full menu entry:
|
||||
|
||||
::
|
||||
|
||||
.. tryref:: ir.menu_cron_form/complete_name
|
||||
|
||||
which will output *Administration / Scheduler / Scheduled Actions*.
|
||||
You can also access any field of the record, for example:
|
||||
|
||||
::
|
||||
|
||||
.. tryref:: ir.menu_cron_form/name
|
||||
|
||||
will output *Scheduled Actions*. **tryref** can be used to access any field of
|
||||
any record with an *ir.model.data* if you know its XML id.
|
||||
|
||||
|
||||
Inline usage
|
||||
~~~~~~~~~~~~
|
||||
|
||||
|
|
|
@ -89,54 +89,43 @@ class FieldDirective(Directive):
|
|||
|
||||
return [nodes.Text(text)]
|
||||
|
||||
def get_menu_data(module_name, fs_id, show_name_only):
|
||||
def get_ref_data(module_name, fs_id, field):
|
||||
if not proteus.config._CONFIG.current:
|
||||
raise ValueError('Proteus has not been initialized.')
|
||||
ModelData = proteus.Model.get('ir.model.data')
|
||||
#db_id = ModelData.get_id(module_name, fs_id)
|
||||
|
||||
records = ModelData.find([
|
||||
('module', '=', module_name),
|
||||
('fs_id', '=', fs_id),
|
||||
('model', '=', 'ir.ui.menu'),
|
||||
])
|
||||
if not records:
|
||||
return None
|
||||
|
||||
db_id = records[0].db_id
|
||||
# model cannot be unicode
|
||||
model = str(records[0].model)
|
||||
|
||||
Menu = proteus.Model.get('ir.ui.menu')
|
||||
menu = Menu(db_id)
|
||||
if show_name_only:
|
||||
text = menu.name
|
||||
else:
|
||||
text = menu.complete_name
|
||||
Model = proteus.Model.get(model)
|
||||
record = Model(db_id)
|
||||
return getattr(record, field)
|
||||
|
||||
return text
|
||||
|
||||
class MenuDirective(Directive):
|
||||
class TryRefDirective(Directive):
|
||||
has_content = True
|
||||
required_arguments = 1
|
||||
optional_arguments = 1
|
||||
final_argument_whitespace = False
|
||||
option_spec = {
|
||||
# Prints only the name of the menu entry instead of its full path
|
||||
'nameonly': directives.flag,
|
||||
}
|
||||
option_spec = {}
|
||||
|
||||
def run(self):
|
||||
content = self.arguments[0]
|
||||
if 'nameonly' in self.options:
|
||||
show_name_only = True
|
||||
else:
|
||||
show_name_only = False
|
||||
|
||||
module_name, fs_id = content.split('.')
|
||||
ref, field = content.split('/')
|
||||
module_name, fs_id = ref.split('.')
|
||||
|
||||
text = get_menu_data(module_name, fs_id, show_name_only)
|
||||
text = get_ref_data(module_name, fs_id, field)
|
||||
if text is None:
|
||||
return [self.state_machine.reporter.warning(
|
||||
'Menu entry "%s" not found.' % content, line=self.lineno)]
|
||||
'Reference "%s" not found.' % content, line=self.lineno)]
|
||||
|
||||
return [nodes.Text(text)]
|
||||
|
||||
|
@ -211,7 +200,7 @@ class ViewDirective(Image):
|
|||
|
||||
class References(Transform):
|
||||
"""
|
||||
Parse and transform menu and field references in a document.
|
||||
Parse and transform tryref and field references in a document.
|
||||
"""
|
||||
|
||||
default_priority = 999
|
||||
|
@ -260,13 +249,10 @@ class References(Transform):
|
|||
else:
|
||||
show_help = False
|
||||
replacement = get_field_data(model_name, field_name, show_help)
|
||||
elif kind == 'menu':
|
||||
if options == 'nameonly':
|
||||
show_name_only = True
|
||||
else:
|
||||
show_name_only = False
|
||||
module_name, fs_id = content.split('.')
|
||||
replacement = get_menu_data(module_name, fs_id, show_name_only)
|
||||
elif kind == 'tryref':
|
||||
ref, field = content.split('/')
|
||||
module_name, fs_id = ref.split('.')
|
||||
replacement = get_ref_data(module_name, fs_id, field)
|
||||
else:
|
||||
replacement = refdata
|
||||
|
||||
|
@ -294,8 +280,9 @@ def setup(app):
|
|||
app.add_config_value('trydoc_pattern', re.compile(r'@(.|[^@]+)@'), 'env')
|
||||
|
||||
app.add_directive('field', FieldDirective)
|
||||
app.add_directive('menu', MenuDirective)
|
||||
app.add_directive('tryref', TryRefDirective)
|
||||
app.add_directive('view', ViewDirective)
|
||||
|
||||
app.connect(b'builder-inited', init_transformer)
|
||||
app.connect(b'build-finished', remove_temporary_files)
|
||||
|
||||
|
|
|
@ -8,15 +8,14 @@ This is an example of reference to field |cron_user| and its help |cron_user_hel
|
|||
.. |cron_user_help| field:: ir.cron/user
|
||||
:help:
|
||||
|
||||
.. |menu_name| menu:: ir.menu_cron_form
|
||||
:nameonly:
|
||||
.. |menu_name| tryref:: ir.menu_cron_form/name
|
||||
|
||||
.. |menu_complete_name| menu:: ir.menu_cron_form
|
||||
.. |menu_complete_name| tryref:: ir.menu_cron_form/complete_name
|
||||
|
||||
.. view:: party.party_party_form
|
||||
:field: name
|
||||
|
||||
This is an example of a field reference in the text: *@field:ir.cron/user@*, while this one is an example of a menu entry in the text: *@menu:ir.menu_cron_form@*.
|
||||
This is an example of a field reference in the text: *@field:ir.cron/user@*, while this one is an example of a menu entry in the text: *@tryref:ir.menu_cron_form/complete_name@*.
|
||||
|
||||
And now, the same example of field with help option: *@field:ir.cron/user:help@*, and the same example of menu entry with nameonly flag: **@menu:ir.menu_cron_form:nameonly@**.
|
||||
And now, the same example of field with help option: *@field:ir.cron/user:help@*.
|
||||
|
||||
|
|
Loading…
Reference in a new issue