Search 1.9 billion lines of Odoo code on GitHub

cms_form

Author: Camptocamp SA, Odoo Community Association (OCA)
License: LGPL-3
Branch: 9.0
Repository: akretion/website-cms
Dependencies: cms_status_message, and website
Languages: JavaScript (197, 8.6%), LESS (15, 0.7%), PO File (279, 12.1%), Python (1448, 62.9%), XML (264, 11.5%), and reStructuredText (98, 4.3%)
Other branches: 10.0, and 11.0
Other repositories: BTETON/website-cms, Change2improve/website-cms, CompassionCH/website-cms, ERPLibre/website-cms, ForgeFlow/website-cms, Gabinete-Digital/website-cms, Guobower/website-cms, Ingeos/website-cms, JazziMc/website-cms, MjAbuz/website-cms, NL66278/website-cms, NeatNerdPrime/website-cms, Nooka10/website-cms, OCA/website-cms, PCatinean/website-cms, SeuMarco/website-cms, TDu/website-cms, TelmoSenseFly/website-cms, VisiionSolucionesTecnologicas/website-cms, anhvu-sg/website-cms, apetbiz/website-cms, bishalgit/website-cms, bvkl/website-cms, caiuka/website-cms, camptocamp/website-cms, elvirekemajou/website-cms, gfcapalbo/website-cms, grindtildeath/website-cms, haroldtamo/website-cms, hbrunn/website-cms, hinfo506/website-cms, isoscl/website-cms, josueBulle/website-cms, kevin070982/website-cms, leemannd/website-cms, lideritjnma/website-cms, lukehuang/website-cms, one2pret/website-cms, pscloud/website-cms, py-web/website-cms, ravishekharco/website-cms, redcor/website-cms, rsullivan2704/website-cms, sanube/website-cms, simahawk/website-cms, steingabelgaard/website-cms, wahello/website-cms, and x0rzkov/odoo-website-cms

<a class="reference external image-reference" href="http://www.gnu.org/licenses/LGPL-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-lgpl--3-blue.svg"> </a> <a name="cms-form"></a> <h2>CMS Form</h2> <p>Basic website contents form framework. Allows to define front-end forms for every models in a simple way.</p> <p>If you are tired of re-defining every time an edit form or a search form for your odoo website, this is the module you are looking for.</p> <a name="features"></a> <h2>Features</h2> <ul class="simple"> <li>automatic form generation (create, write, search)</li> <li>automatic route generation (create, write, search)</li> <li><dl class="first docutils"> <dt>automatic machinery based on fields' type:</dt> <dd><ul class="first last"> <li>widget rendering</li> <li>field value load (from existing instance or from request)</li> <li>field value extraction (from request)</li> <li>field value write (to existing instance)</li> </ul> </dd> </dl> </li> <li>highly customizable</li> <li>works with every odoo model</li> <li>works also without any model</li> <li><dl class="first docutils"> <dt>add handy attributes to models inheriting from <code>website.published.mixin</code>:</dt> <dd><ul class="first last"> <li><code>cms_add_url</code>: lead to create form view. By default <code>/cms/form/create/my.model</code></li> <li><code>cms_edit_url</code>: lead to edit form view. By default <code>/cms/form/edit/my.model/model_id</code></li> <li><code>cms_search_url</code>: lead to search form view. By default <code>/cms/form/search/my.model</code></li> </ul> </dd> </dl> </li> </ul> <a name="usage"></a> <h2>Usage</h2> <a name="create-edit-form"></a> <h3>Create / Edit form</h3> <p>Just inherit from <code>cms.form</code> to add a form for your model. Quick example for partner:</p> <pre> <code lang="python">class PartnerForm(models.AbstractModel): _name = 'cms.form.res.partner' _inherit = 'cms.form' _form_model = 'res.partner' _form_model_fields = ('name', 'country_id') _form_required_fields = ('name', 'country_id')</code> </pre> <p>In this case you'll have form with the following characteristics:</p> <ul class="simple"> <li>works with <code>res.partner</code> model</li> <li>have only <code>name</code> and <code>country_id</code> fields</li> <li>both fields are required (is not possible to submit the form w/out one of those values)</li> </ul> <p>Here's the result:</p> <p><img alt="preview_create" src="./images/cms_form_example_create_partner.png" /> <img alt="preview_edit" src="./images/cms_form_example_edit_partner.png" /></p> <p>The form will be automatically available on these routes:</p> <ul class="simple"> <li><code>/cms/form/create/res.partner</code> to create new partners</li> <li><code>/cms/form/edit/res.partner/1</code> edit existing partners (partner id=1 in this case)</li> </ul> <p>NOTE: default generic routes work if the form's name is <code>cms.form.</code> + model name, like <code>cms.form.res.partner</code>. If you want you can easily define your own controller and give your form a different name, and have more elegant routes like <code>`/partner/edit/partner-slug-1</code>. Take a look at <a class="reference external" href="../cms_form_example">cms_form_example</a>.</p> <p>By default, the form is rendered as an horizontal twitter bootstrap form, but you can provide your own templates of course. By default, fields are ordered by their order in the model's schema. You can tweak it using <code>_form_fields_order</code>.</p> <a name="form-with-extra-control-fields"></a> <h3>Form with extra control fields</h3> <p>Imagine you want to notify the partner after its creation but only if you really need it.</p> <p>The form above can be extended with extra fields that are not part of the <code>_form_model</code> schema:</p> <pre> <code lang="python">class PartnerForm(models.AbstractModel): _name = 'cms.form.res.partner' _inherit = 'cms.form' _form_model = 'res.partner' _form_model_fields = ('name', 'country_id', 'email') _form_required_fields = ('name', 'country_id', 'email') notify_partner = fields.Boolean() def form_after_create_or_update(self, values, extra_values): if extra_values.get('notify_partner'): # do what you want here...</code> </pre> <p><code>notify_partner</code> will be included into the form but it will be discarded on create and write. Nevertheless you can use it as a control flag before and after the record has been created or updated using the hook <code>form_after_create_or_update</code>, as you see in this example.</p> <a name="search-form"></a> <h3>Search form</h3> <p>Just inherit from <code>cms.form.search</code> to add a form for your model. Quick example for partner:</p> <pre> <code lang="python">class PartnerSearchForm(models.AbstractModel): &quot;&quot;&quot;Partner model search form.&quot;&quot;&quot; _name = 'cms.form.search.res.partner' _inherit = 'cms.form.search' _form_model = 'res.partner' _form_model_fields = ('name', 'country_id', ) _form_fields_order = ('country_id', 'name', )</code> </pre> <p><img alt="preview_search" src="./images/cms_form_example_search.png" /></p> <p>The form will be automatically available at: <code>/cms/form/search/res.partner</code>.</p> <p>NOTE: default generic routes work if the form's name is <code>`cms.form.search</code> + model name, like <code>cms.form.search.res.partner</code>. If you want you can easily define your own controller and give your form a different name, and have more elegant routes like <code>/partners</code>. Take a look at <a class="reference external" href="../cms_form_example">cms_form_example</a>.</p> <a name="master-slave-fields"></a> <h3>Master / slave fields</h3> <p>A typical use case nowadays: you want to show/hide fields based on other fields' values. For the simplest cases you don't have to write a single line of JS. You can do it like this:</p> <pre> <code lang="python">class PartnerForm(models.AbstractModel): _name = 'cms.form.res.partner' _inherit = 'cms.form' _form_model = 'res.partner' _form_model_fields = ('name', 'type', 'foo') def _form_master_slave_info(self): info = self._super._form_master_slave_info() info.update({ # master field 'type':{ # actions 'hide': { # slave field: action values 'foo': ('contact', ), }, 'show': { 'foo': ('address', 'invoice', ), } }, }) return info</code> </pre> <p>Here we declared that:</p> <ul class="simple"> <li>when <cite>type</cite> field is equal to <cite>contact</cite> -&gt; hide <cite>foo</cite> field</li> <li>when <cite>type</cite> field is equal to <cite>address</cite> or <cite>invoice</cite> -&gt; show <cite>foo</cite> field</li> </ul> <a name="known-issues-roadmap"></a> <h2>Known issues / Roadmap</h2> <ul class="simple"> <li>add more tests, especially per each widget and type of field</li> <li>provide better widgets for image and file fields in general</li> <li>o2m fields: to be tested at all</li> <li>move widgets to abstract models too</li> <li>search form: generate default search domain in a clever way</li> <li>add easy way to switch from horizontal to vertical form</li> <li>provide more examples</li> <li>x2x fields: allow sub-items creation</li> <li>handle api onchanges</li> <li>support python expressions into master/slave rules</li> </ul> <a name="bug-tracker"></a> <h2>Bug Tracker</h2> <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/website-cms/issues">GitHub Issues</a>. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback.</p> <a name="credits"></a> <h2>Credits</h2> <a name="sponsor"></a> <h3>Sponsor</h3> <ul class="simple"> <li><a class="reference external" href="https://fluxdock.io">Fluxdock.io</a>.</li> </ul> <a name="contributors"></a> <h3>Contributors</h3> <ul class="simple"> <li>Simone Orsi &lt;<a class="reference external" href="mailto:simone.orsi&#64;camptocamp.com">simone.orsi&#64;camptocamp.com</a>&gt;</li> </ul> <a name="maintainer"></a> <h3>Maintainer</h3> <a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> <p>This module is maintained by the OCA.</p> <p>OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.</p> <p>To contribute to this module, please visit <a class="reference external" href="https://odoo-community.org">https://odoo-community.org</a>.</p>