Templating the XML files

The data XML can be sometimes very repetitive and so we duplicate large parts. But then it becomes harder to maintain such data.
Here are some examples of repetitive data:

  • same access rights for different groups
  • same access rights for different models
  • the pattern form, list views and ir.action.act_window

I think we could use a template engine (Genshi) for them. Maybe we would use a different extension to differentiate with raw template or we could apply the template engine on all of them.
With such feature we could also provide function for common usage.

Another idea would be to also add templating to the view XML. But except for very rare case (like listing all the perm_ in ir.model.access), I see no real advantage and it can slow down the server.

I think it will be better to use a different extension and apply the rendering only to those file because the current parser is SAX based to consume low memory. If we pre-process all the XML files, we will slow down large data files. That’s why I think the rendering should only be done to the files that use it.

This sounds interesting, I rember that when I was on nantic we had some script to generate this records using a xml template and providing just the model name. Currently I’m not using any script but just copying and replacing the fields. For me a common template will ease the development but also the learning curve for newcomers.

I have some fear on how to avoid to much parameters on this functions, but probably this is something that should be discussed latter when implementend

I agree that using a diferent extension will be a good way to enable the feature. Maybe we can use the .txml extension (Templated XML) to indicate that the XML file contains a template.

Another option will be too look at the xml headers to see if the Genshi namespace is included on the tryton tag

Do we want to support users to define and customize custom functions (like we do for reports by overriding the get_context function) or the common usage functions will be standard?

The problem is that editor does not recognize this extension as XML.

But this means parsing the XML to know with which parser to parse.

This would be based on Genshi include feature.
And I think trytond could have some generic common functions.

Doubling up the extension could work, so perhaps something like .tmpl.xml (for template XML) or .gen.xml (for genshi/generate XML)? This still has the .xml extension at the end for the editior, but it is also easy to distinguish from regular XML files based on the filename when loading.

1 Like

+1 to any effort that tries to simplify management of XML files.

About the proposal I wonder how hard it will be to guess the IDs that will be created by such methods. It seems that it could be somewhat harder to find the IDs that ones need to refer to in “inheriting” modules.

Although the proposal is about templating, I’ve also thought in the past about simplifying XMLs. Maybe I’m the only one but I find XMLs somewhat hard to read and write and I’ve lately been used to YAML syntax.

If that was considered there are many ways to establish the structure of such file. One of them could be as follows (a fragment of sale/sale.xml translated into sale/sale.yml):

---
- model: res.group
  group_sale:
    name: Sales
  group_sale_admin:
    name: Sales Administration

- model: res.user-res.group
  user_admin_group_sale:
    user: res.user_admin
    group: group_sale

  user_admin_group_sale_admin:
    user: res.user_admin
    group: group_sale_admin

- model: ir.ui.icon
  sale_icon:
    name: tryton-sale
    path: icons/tryton-sale.svg

- model: ir.ui.view
  sale_view_form:
    model: sale.sale
    type: form
    name: sale_form

  sale_view_tree:
    model: sale.sale
    type: tree
    name: sale_tree

- model: ir.action.act_window
  act_sale_form:
    name: Sales
    res_model: sale.sale
    search_value: ""

- model: ir.action.act_window.view
  act_sale_form_view1:
    sequence: 10
    view: sale_view_tree
    act_window: act_sale_form

  act_sale_form_view2:
    sequence: 20
    view: sale_view_form
    act_window: act_sale_form

- model: ir.action.act_window.domain
  act_sale_form_domain_draft:
    name: Draft
    sequence: 10
    domain:
      eval: [('state', '=', 'draft')]
      pyson: 1
    count:
      eval: True
    act_window: act_sale_form

  act_sale_form_domain_quotation:
    name: Quotation
    sequence: 20
    domain:
      eval: [('state', '=', 'quotation')]
      pyson: 1
    count:
      eval: True
    act_window: act_sale_form

  act_sale_form_domain_processing:
    name: Processing
    sequence: 40
    domain:
      eval: [('state', '=', 'processing')]
      pyson: 1
    count:
      eval: True
    act_window: act_sale_form

  act_sale_form_domain_all:
    name: All
    sequence: 9999
    domain: ""
    act_window: act_sale_form

This makes several assumptions such as:

  • It takes advantage of the fact that many consecutive records are from the same model
  • Assumes that most of the time m2o fields use a “ref=xxx” where xxx is the ID of the related record

Of course there could be other ways of structuring it, such as:

group_sale:
  model: res.group
  fields:
    name: Sales

group_sale_admin:
  model: res.group

I understand that because of the use of SAX, XML may consume less memory, and maybe others already feel comfortable with XML, but just wanted to put another option on the table.