mirror of
https://github.com/NaN-tic/trydoc.git
synced 2023-12-14 02:03:42 +01:00
Issue #4: Add model directive to print model name
This commit is contained in:
parent
025bf28356
commit
51bf12eb25
3 changed files with 127 additions and 54 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
* Fix screenshot bug: allow to generate more than 3 screenshots
|
||||||
|
* Fix screenshot bug: show icons correctly
|
||||||
|
* Get Tryton server connection params from configuration and also screenshots
|
||||||
|
size
|
||||||
|
* Add **model** directive to print model name
|
||||||
|
|
||||||
Version 0.5 2014-06-18
|
Version 0.5 2014-06-18
|
||||||
* Add option parser to get modules from XML-RPC server
|
* Add option parser to get modules from XML-RPC server
|
||||||
* Removed sphinxcontrib-inheritance from requirements
|
* Removed sphinxcontrib-inheritance from requirements
|
||||||
|
|
103
doc/index.rst
103
doc/index.rst
|
@ -86,14 +86,45 @@ Usage
|
||||||
|
|
||||||
TryDoc adds the following set of directives to be used in the docs:
|
TryDoc adds the following set of directives to be used in the docs:
|
||||||
|
|
||||||
Fields
|
Model
|
||||||
~~~~~~
|
~~~~~
|
||||||
|
|
||||||
|
You can refer to any model with the following directive:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
.. model:: model.name
|
||||||
|
|
||||||
|
which will print the given model name inside an _span_ with the class
|
||||||
|
*trydocfield*. You can change this default class with the configuration option
|
||||||
|
*trydoc_fieldclass*.
|
||||||
|
|
||||||
|
Optionally the ``:info:`` flag can be added to get the Info field of ir.model.
|
||||||
|
It isn't translated so provably it isn't very useful:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
.. model:: account.tax
|
||||||
|
:info:
|
||||||
|
|
||||||
|
It also have another optional option ``:class: CLASSLIST``. It adds the
|
||||||
|
specified classes to the _span_ (not replace the default class). An example:::
|
||||||
|
|
||||||
|
.. model:: ir.cron
|
||||||
|
:class: admin
|
||||||
|
|
||||||
|
It will generate the following code:::
|
||||||
|
|
||||||
|
<span class="trydocmodel admin">Cron</span>
|
||||||
|
|
||||||
|
Field
|
||||||
|
~~~~~
|
||||||
|
|
||||||
You can refer to any field with the following directive:
|
You can refer to any field with the following directive:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
.. fields:: model/field
|
.. field:: model/field
|
||||||
|
|
||||||
which will print the given field name inside an _span_ with the class
|
which will print the given field name inside an _span_ with the class
|
||||||
*trydocfield*. You can change this default class with the configuration option
|
*trydocfield*. You can change this default class with the configuration option
|
||||||
|
@ -103,49 +134,18 @@ Optionally the ``:help:`` flag can be added. See the following example:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
.. fields:: ir.cron/user
|
.. field:: ir.cron/user
|
||||||
:help:
|
:help:
|
||||||
|
|
||||||
It will print the help text of field despite of the field name (if the field
|
It will print the help text of field despite of the field name (if the field
|
||||||
doesn't have help text it will print a message advertising it.
|
doesn't have help text it will print a message advertising it.
|
||||||
|
|
||||||
It also have another optional option ``:class: CLASSLIST``. It adds the
|
It also have the optional option ``:class: CLASSLIST``.
|
||||||
specified classes to the _span_ (not replace the default class). An example:::
|
|
||||||
|
|
||||||
.. fields:: ir.cron/user
|
Tryref
|
||||||
:class: admin
|
~~~~~~
|
||||||
|
|
||||||
It will generate the following code:::
|
To show any data introduced in a XML file you can use the **tryref** directive.
|
||||||
|
|
||||||
<span class="trydocfield admin">Usuario</span>
|
|
||||||
|
|
||||||
Views
|
|
||||||
~~~~~
|
|
||||||
|
|
||||||
You can add a screenshot of any model view with the following directive:
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
.. view:: reference_to_view_xml_id
|
|
||||||
:field: fieldname
|
|
||||||
|
|
||||||
where ``:field:`` is optional and will ensure the given field name is shown in
|
|
||||||
the generated screenshot.
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
.. view:: party.party_party_form
|
|
||||||
:field: name
|
|
||||||
|
|
||||||
.. Note:: This directive is not fully working yet. It will add a screenshot of
|
|
||||||
tryton's client but not of the appropriate view.
|
|
||||||
|
|
||||||
It also has the optional option ``:class: CLASSLIST`` which adds the specified
|
|
||||||
class to the default class *trydocview* (which can be changed with the
|
|
||||||
configuration option *trydoc_viewclass*).
|
|
||||||
|
|
||||||
Menus and other data
|
|
||||||
~~~~~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
You can refer to any menu entry with the following directive:
|
You can refer to any menu entry with the following directive:
|
||||||
|
|
||||||
|
@ -174,6 +174,31 @@ class *trydocref*. This default class could be changed with the configuration
|
||||||
option *trydoc_refclass*. And if you want to add another classes to an specific
|
option *trydoc_refclass*. And if you want to add another classes to an specific
|
||||||
entry you could use the ``:class: CLASSLIST`` option.
|
entry you could use the ``:class: CLASSLIST`` option.
|
||||||
|
|
||||||
|
View
|
||||||
|
~~~~
|
||||||
|
|
||||||
|
You can add a screenshot of any model view with the following directive:
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
.. view:: reference_to_view_xml_id
|
||||||
|
:field: fieldname
|
||||||
|
|
||||||
|
where ``:field:`` is optional and will ensure the given field name is shown in
|
||||||
|
the generated screenshot.
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
.. view:: party.party_party_form
|
||||||
|
:field: name
|
||||||
|
|
||||||
|
.. Note:: This directive is not fully working yet. It will add a screenshot of
|
||||||
|
tryton's client but not of the appropriate view.
|
||||||
|
|
||||||
|
It also has the optional option ``:class: CLASSLIST`` which adds the specified
|
||||||
|
class to the default class *trydocview* (which can be changed with the
|
||||||
|
configuration option *trydoc_viewclass*).
|
||||||
|
|
||||||
Inline usage
|
Inline usage
|
||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,21 @@ except ImportError, e:
|
||||||
screenshot_files = []
|
screenshot_files = []
|
||||||
|
|
||||||
|
|
||||||
|
def get_model_data(model_name, show_info):
|
||||||
|
if not proteus.config._CONFIG.current:
|
||||||
|
raise ValueError('Proteus has not been initialized.')
|
||||||
|
|
||||||
|
Model = proteus.Model.get('ir.model')
|
||||||
|
models = Model.find([
|
||||||
|
('model', '=', model_name),
|
||||||
|
])
|
||||||
|
if not models:
|
||||||
|
return None
|
||||||
|
|
||||||
|
text = models[0].name if not show_info else models[0].info
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
def get_field_data(model_name, field_name, show_help):
|
def get_field_data(model_name, field_name, show_help):
|
||||||
if not proteus.config._CONFIG.current:
|
if not proteus.config._CONFIG.current:
|
||||||
raise ValueError('Proteus has not been initialized.')
|
raise ValueError('Proteus has not been initialized.')
|
||||||
|
@ -58,21 +73,17 @@ def get_field_data(model_name, field_name, show_help):
|
||||||
field, = fields
|
field, = fields
|
||||||
|
|
||||||
text = ''
|
text = ''
|
||||||
for field in models[0].fields:
|
if show_help:
|
||||||
if field.name == field_name:
|
if field.help:
|
||||||
if show_help:
|
text = field.help
|
||||||
if field.help:
|
else:
|
||||||
text = field.help
|
text = 'Field "%s" has no help available' % field.name
|
||||||
else:
|
else:
|
||||||
text = 'Field "%s" has no help available' % field.name
|
if field.field_description:
|
||||||
else:
|
text = field.field_description
|
||||||
if field.field_description:
|
else:
|
||||||
text = field.field_description
|
text = ('Field "%s" has no description available'
|
||||||
else:
|
% field.name)
|
||||||
text = ('Field "%s" has no description available'
|
|
||||||
% field.name)
|
|
||||||
break
|
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,6 +110,35 @@ def get_ref_data(module_name, fs_id, field=None):
|
||||||
return record
|
return record
|
||||||
|
|
||||||
|
|
||||||
|
class ModelDirective(Directive):
|
||||||
|
has_content = True
|
||||||
|
required_arguments = 1
|
||||||
|
optional_arguments = 1
|
||||||
|
final_argument_whitespace = False
|
||||||
|
option_spec = {
|
||||||
|
'info': directives.flag,
|
||||||
|
'class': directives.class_option,
|
||||||
|
}
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
config = self.state.document.settings.env.config
|
||||||
|
if 'info' in self.options:
|
||||||
|
show_info = True
|
||||||
|
else:
|
||||||
|
show_info = False
|
||||||
|
classes = [config.trydoc_modelclass]
|
||||||
|
if 'class' in self.options:
|
||||||
|
classes.extend(self.options['class'])
|
||||||
|
|
||||||
|
model_name = self.arguments[0]
|
||||||
|
text = get_model_data(model_name, show_info)
|
||||||
|
if text is None:
|
||||||
|
return [self.state_machine.reporter.warning(
|
||||||
|
'Model "%s" not found.' % model_name, line=self.lineno)]
|
||||||
|
|
||||||
|
return [nodes.inline(text, text, classes=classes)]
|
||||||
|
|
||||||
|
|
||||||
class FieldDirective(Directive):
|
class FieldDirective(Directive):
|
||||||
has_content = True
|
has_content = True
|
||||||
required_arguments = 1
|
required_arguments = 1
|
||||||
|
@ -440,6 +480,7 @@ def remove_temporary_files(app, exception):
|
||||||
def setup(app):
|
def setup(app):
|
||||||
app.add_config_value('trydoc_plaintext', True, 'env')
|
app.add_config_value('trydoc_plaintext', True, 'env')
|
||||||
app.add_config_value('trydoc_pattern', re.compile(r'@(.|[^@]+)@'), 'env')
|
app.add_config_value('trydoc_pattern', re.compile(r'@(.|[^@]+)@'), 'env')
|
||||||
|
app.add_config_value('trydoc_modelclass', 'trydocmodel', 'env')
|
||||||
app.add_config_value('trydoc_fieldclass', 'trydocfield', 'env')
|
app.add_config_value('trydoc_fieldclass', 'trydocfield', 'env')
|
||||||
app.add_config_value('trydoc_refclass', 'trydocref', 'env')
|
app.add_config_value('trydoc_refclass', 'trydocref', 'env')
|
||||||
app.add_config_value('trydoc_viewclass', 'trydocview', 'env')
|
app.add_config_value('trydoc_viewclass', 'trydocview', 'env')
|
||||||
|
@ -453,6 +494,7 @@ def setup(app):
|
||||||
app.add_config_value('tryton_default_height', 1024, 'env')
|
app.add_config_value('tryton_default_height', 1024, 'env')
|
||||||
# app.add_config_value('verbose', False, 'env'),
|
# app.add_config_value('verbose', False, 'env'),
|
||||||
|
|
||||||
|
app.add_directive('model', ModelDirective)
|
||||||
app.add_directive('field', FieldDirective)
|
app.add_directive('field', FieldDirective)
|
||||||
app.add_directive('tryref', TryRefDirective)
|
app.add_directive('tryref', TryRefDirective)
|
||||||
app.add_directive('view', ViewDirective)
|
app.add_directive('view', ViewDirective)
|
||||||
|
|
Loading…
Reference in a new issue