Browse Source
fix template description being indented
fix template description being indented
[FIX] Use human name and english category name for manifest [IMP] multi line notes, unprefix names, pep8 py files [IMP] whitespace cleanup in templates [FIX] base models get _name, custom get _inherit flake fix add missing spaces prevent crash on menus with no action switch GPL-2 to LGPL-3 generate license headers with license name fix pep/flake errors in generated files add m2m and relation field options in fieldspull/107/head
Vincent Vinet
10 years ago
committed by
Maxime Chambreuil
14 changed files with 402 additions and 150 deletions
-
17module_prototyper/models/default_description.py
-
19module_prototyper/models/ir_model_fields.py
-
73module_prototyper/models/licenses.py
-
96module_prototyper/models/module_prototyper.py
-
3module_prototyper/templates/8.0/__init__.py.template
-
28module_prototyper/templates/8.0/__openerp__.py.template
-
32module_prototyper/templates/8.0/header.template
-
5module_prototyper/templates/8.0/models/__init__.py.template
-
61module_prototyper/templates/8.0/models/model_name.py.template
-
21module_prototyper/templates/8.0/views/model_menus.xml.template
-
16module_prototyper/templates/8.0/views/model_views.xml.template
-
5module_prototyper/tests/__init__.py
-
30module_prototyper/tests/test_prototype.py
-
16module_prototyper/views/ir_model_fields_view.xml
@ -0,0 +1,73 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
# ############################################################################# |
||||
|
# |
||||
|
# OpenERP, Open Source Management Solution |
||||
|
# This module copyright (C) 2010 - 2014 Savoir-faire Linux |
||||
|
# (<http://www.savoirfairelinux.com>). |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
|
||||
|
BASE_GPL = """ |
||||
|
This program is free software: you can redistribute it and/or modify |
||||
|
it under the terms of the {name} as |
||||
|
published by the Free Software Foundation{version}. |
||||
|
|
||||
|
This program is distributed in the hope that it will be useful, |
||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
GNU General Public License for more details. |
||||
|
|
||||
|
You should have received a copy of the {name} |
||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
""" |
||||
|
|
||||
|
|
||||
|
GPL3 = "GPL-3" |
||||
|
GPL3_L = "GPL-3 or any later version" |
||||
|
LGPL3 = "LGPL-3" |
||||
|
LGPL3_L = "LGPL-3 or any later version" |
||||
|
AGPL3 = "AGPL-3" |
||||
|
AGPL3_L = "AGPL-3 or any later version" |
||||
|
OSI = "Other OSI approved license" |
||||
|
|
||||
|
V3 = " version 3" |
||||
|
V3L = """, either version 3 of the |
||||
|
License, or (at your option) any later version""" |
||||
|
|
||||
|
GPL_LICENSES = { |
||||
|
GPL3: ("GNU General Public License", V3), |
||||
|
GPL3_L: ("GNU General Public License", V3L), |
||||
|
LGPL3: ("GNU Lesser General Public License", V3), |
||||
|
LGPL3_L: ("GNU Lesser General Public License", V3L), |
||||
|
AGPL3: ("GNU Affero General Public License", V3), |
||||
|
AGPL3_L: ("GNU Affero General Public License", V3L), |
||||
|
} |
||||
|
|
||||
|
BASE_OSI = """ |
||||
|
This program is free software: you should have received a copy of the |
||||
|
license under which it is distributed along with the program. |
||||
|
""" |
||||
|
|
||||
|
|
||||
|
def get_license_text(license): |
||||
|
""" Get the python license header for a license """ |
||||
|
if license in GPL_LICENSES: |
||||
|
name, version = GPL_LICENSES[license] |
||||
|
return BASE_GPL.format(name=name, version=version).splitlines() |
||||
|
elif license == OSI: |
||||
|
return BASE_OSI |
||||
|
else: |
||||
|
return "" |
@ -1,6 +1,7 @@ |
|||||
{% extends "header.template" %} |
{% extends "header.template" %} |
||||
{% block body %} |
{% block body %} |
||||
{% if models -%} |
|
||||
|
{% if models %} |
||||
|
|
||||
from . import models |
from . import models |
||||
{% endif %} |
{% endif %} |
||||
{% endblock %} |
{% endblock %} |
@ -1,6 +1,9 @@ |
|||||
{% extends "header.template" %} |
{% extends "header.template" %} |
||||
{% block body %} |
{% block body %} |
||||
{% for model in models -%} |
|
||||
|
{% for model in models %} |
||||
|
{% if loop.first %} |
||||
|
|
||||
|
{% endif %} |
||||
from . import {{ model }} |
from . import {{ model }} |
||||
{% endfor %} |
{% endfor %} |
||||
{% endblock %} |
{% endblock %} |
@ -1,22 +1,63 @@ |
|||||
{% extends "header.template" %} |
{% extends "header.template" %} |
||||
{% block body %} |
{% block body %} |
||||
|
|
||||
from openerp import models, fields |
from openerp import models, fields |
||||
from openerp.tools.translate import _ |
from openerp.tools.translate import _ |
||||
|
|
||||
|
|
||||
class {{ name }}(models.Model): |
|
||||
_inherit = "{{ inherit }}" |
|
||||
{% if description -%}_description = "{{ description }}"{% endif %} |
|
||||
|
class {{ unprefix(name) }}(models.Model): |
||||
|
{% if model.state == 'base' %} |
||||
|
_name = "{{ model.model }}" |
||||
|
{% else %} |
||||
|
_inherit = "{{ model.model }}" |
||||
|
{% endif %} |
||||
|
{% if description %} |
||||
|
_description = "{{ description }}" |
||||
|
{% endif %} |
||||
|
|
||||
{% for field in fields -%} |
|
||||
{% if field.notes -%}# {{ field.notes }}{% endif %} |
|
||||
{{ field.name }} = fields.{{ field.ttype|capitalize }}( |
|
||||
|
{% for field in fields %} |
||||
|
{% for line in wrap(field.notes, replace_whitespace=False) %} |
||||
|
{% if line %} |
||||
|
# {{line}} |
||||
|
{% else %} |
||||
|
# |
||||
|
{% endif %} |
||||
|
{% endfor %} |
||||
|
{{ unprefix(field.name) }} = fields.{{ field.ttype|capitalize }}( |
||||
string=_("{{ field.field_description }}"), |
string=_("{{ field.field_description }}"), |
||||
|
{% if field.selection %} |
||||
|
selection={{ selection }}, |
||||
|
{% endif %} |
||||
|
{% if field.relation %} |
||||
|
comodel_name="{{ field.relation }}", |
||||
|
{% endif %} |
||||
|
{% if field.column1 %} |
||||
|
column1="{{ field.column1 }}", |
||||
|
{% endif %} |
||||
|
{% if field.column2 %} |
||||
|
column1="{{ field.column2 }}", |
||||
|
{% endif %} |
||||
required={{ field.required }}, |
required={{ field.required }}, |
||||
translate={{ field.translate }}, |
translate={{ field.translate }}, |
||||
readonly={{ field.readonly }}, |
readonly={{ field.readonly }}, |
||||
{% if field.size -%}size={{ field.size }},{% endif %} |
|
||||
{% if field.helper -%}help=_("{{ field.helper }}"),{% endif %} |
|
||||
){% endfor %} |
|
||||
|
|
||||
|
{% if field.size %} |
||||
|
size={{ field.size }}, |
||||
|
{% endif %} |
||||
|
{% if field.domain %} |
||||
|
domain={{ field.domain }}, |
||||
|
{% endif %} |
||||
|
{% if field.context %} |
||||
|
context={{ field.context }}, |
||||
|
{% endif %} |
||||
|
{% if field.limit %} |
||||
|
limit={{ field.limit }}, |
||||
|
{% endif %} |
||||
|
{% if field.ttype == 'many2one' and field.on_delete %} |
||||
|
on_delete="{{ field.on_delete }}", |
||||
|
{% endif %} |
||||
|
{% if field.helper %} |
||||
|
help=_("{{ field.helper }}"), |
||||
|
{% endif %} |
||||
|
) |
||||
|
{% endfor %} |
||||
{% endblock %} |
{% endblock %} |
@ -1,24 +1,29 @@ |
|||||
<?xml version="1.0"?> |
<?xml version="1.0"?> |
||||
<openerp> |
<openerp> |
||||
<data> |
<data> |
||||
{% for menu in menus -%} |
|
||||
|
{% for menu in menus %} |
||||
<record id="action_{{ menu.action.name }}_{{ menu.action.view_type }}_view" model="{{ menu.action.type }}"> |
<record id="action_{{ menu.action.name }}_{{ menu.action.view_type }}_view" model="{{ menu.action.type }}"> |
||||
<field name="name">{{ menu.action.name }}</field> |
|
||||
|
<field name="name">{{ unprefix(menu.action.name) }}</field> |
||||
<field name="type">{{ menu.action.type }}</field> |
<field name="type">{{ menu.action.type }}</field> |
||||
<field name="res_model">{{ menu.action.res_model }}</field> |
|
||||
|
<field name="res_model">{{ unprefix(menu.action.res_model) }}</field> |
||||
<field name="view_type">{{ menu.action.view_type }}</field> |
<field name="view_type">{{ menu.action.view_type }}</field> |
||||
<field name="view_mode">{{ menu.action.view_mode }}</field> |
<field name="view_mode">{{ menu.action.view_mode }}</field> |
||||
{% if menu.action.help %}<field name="help" type="html">{{ menu.action.help }} |
|
||||
</field>{% endif %} |
|
||||
|
{% if menu.action.help %} |
||||
|
<field name="help" type="html">{{ menu.action.help }} |
||||
|
</field> |
||||
|
{% endif %} |
||||
</record> |
</record> |
||||
|
|
||||
<menuitem action="action_{{ menu.action.name }}_{{ menu.action.view_type }}_view" |
|
||||
|
<menuitem action="action_{{ unprefix(menu.action.name) }}_{{ menu.action.view_type }}_view" |
||||
name="{{ menu.name }}" |
name="{{ menu.name }}" |
||||
id="menu_action_{{ menu.name|replace('.', '_') }}_{{ menu.action.view_type }}" |
|
||||
|
id="menu_action_{{ unprefix(menu.name)|replace('.', '_') }}_{{ menu.action.view_type }}" |
||||
{% if menu.parent_id %}parent="{{ menu.parent_id.get_xml_id(cr,1,1).values()[0] }}"{% endif %} |
{% if menu.parent_id %}parent="{{ menu.parent_id.get_xml_id(cr,1,1).values()[0] }}"{% endif %} |
||||
sequence="{{ menu.sequence }}" |
sequence="{{ menu.sequence }}" |
||||
groups="{% for group in menu.groups_id %}{{ group.get_xml_id(cr,1,1).values()[0] }},{% endfor %}" |
groups="{% for group in menu.groups_id %}{{ group.get_xml_id(cr,1,1).values()[0] }},{% endfor %}" |
||||
/> |
/> |
||||
{% endfor -%} |
|
||||
|
{% if not loop.last %} |
||||
|
|
||||
|
{% endif %} |
||||
|
{% endfor %} |
||||
</data> |
</data> |
||||
</openerp> |
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue