Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
242 commits
Select commit Hold shift + click to select a range
e269d36
[ADD] cms_form
simahawk May 29, 2017
484a82d
Make cms_form* uninstallable
simahawk Oct 2, 2017
b34bdec
[MIG][10.0] cms_form
simahawk Oct 2, 2017
95cb8b9
[fix] TMP FIX for v10 ir_qweb issue (addresses #odoo/issues/16641)
simahawk Oct 2, 2017
49f865e
Make cms_form installable!
simahawk Oct 4, 2017
c7fd809
[MIG][11.0] cms_form
simahawk Jan 19, 2018
6ee2743
[DEL] cms_form: drop ir_ui_view patch for v10
simahawk Jan 19, 2018
545a34e
[REF] cms_form: refactor test models setup
simahawk Jan 19, 2018
57f9f8f
[fix] cms_form: fields get dynamic non stored fields
simahawk Jan 20, 2018
fb33d2e
[MIG][11] cms_form: include fix for navbar odoo/odoo/pull/22384
simahawk Feb 3, 2018
c8ecf63
[IMP] cms_form: ease m2o select option override
simahawk Feb 3, 2018
d45225f
[IMP] cms_form: base test case `get_form`
simahawk Feb 4, 2018
2c8ff8b
cms_form: fix some permission issues
simahawk Feb 8, 2018
a6300a5
cms_form: fix master_slave.js change trigger on load
simahawk Feb 8, 2018
500aa72
Fix global JS lint
simahawk Feb 9, 2018
2a9ee5d
cms_form: fix x2m widget load default value empty
simahawk Mar 2, 2018
8849ed3
cms_form: fix x2m widget value comparison
simahawk Mar 2, 2018
62ef870
cms_form: bump 11.0.1.0.2
simahawk Mar 20, 2018
488cdf1
Form controller: main_object defaults to empty recordset
simahawk Mar 21, 2018
4e516a3
cms_form: bump 11.0.1.0.3
simahawk Mar 21, 2018
4a475eb
cms_form: add fieldsets support
simahawk Feb 28, 2018
5f0d92c
cms_form: ease override of JSON info
simahawk Mar 1, 2018
6cd8d36
cms_form: bump 11.0.1.0.4 (and add changelog)
simahawk Mar 23, 2018
3efad64
cms_form widget: fix json params rendering
simahawk Mar 22, 2018
54f7edc
cms_form date widget: allow custom default today
simahawk Mar 22, 2018
609ff59
cms_form search: fix date search w/ empty value
simahawk Mar 22, 2018
b41da92
cms_form: add multi value widget for search forms
simahawk Mar 22, 2018
3031bb4
cms_form: add vertical fields option
simahawk Mar 22, 2018
21ccb1f
Fix fieldset support for search forms
simahawk Mar 23, 2018
83cb2bf
Delegate field wrapper class computation to form
simahawk Mar 23, 2018
286ebc2
Bump cms_form 11.0.1.1.0
simahawk Mar 26, 2018
646e6d5
cms_form: fix date widget default today only if empty
simahawk Mar 26, 2018
ec1822f
Bump `cms_form` 11.0.1.1.1
simahawk Mar 26, 2018
648fd92
cms_form: move `check_permission` to form
simahawk Mar 29, 2018
50320d9
cms_form: fix handling of forms w/ no form_model
simahawk Mar 29, 2018
f85d5af
cms_form: improve custom attributes override
simahawk Mar 29, 2018
96108b3
Form controller: better HTTP status for redirect and no cache
simahawk Mar 30, 2018
6f8cbf7
cms_form: create/write use a copy of values
simahawk Apr 3, 2018
51a5e0a
cms_form: form_get_widget pass keyword args to ease customization
simahawk Apr 3, 2018
63515da
cms_form: add `lock copy paste` option
simahawk Apr 3, 2018
574b9fb
cms_form: support multiple values for same field
simahawk Apr 3, 2018
9d4b760
cms_form: add error msg block for validation errors
simahawk Apr 3, 2018
61d6e45
cms_form: fix required attr on boolean widget
simahawk Apr 3, 2018
05f396f
Bump `cms_form` 11.0.1.2.0
simahawk Apr 9, 2018
eec75de
cms_form: add fake_session helper for tests
simahawk Apr 9, 2018
577c6cc
cms_form: make test on validation error defensive
simahawk Apr 10, 2018
83e298c
cms_form: fix search form regression on permission check
simahawk Apr 13, 2018
8251c64
Bump `cms_form` 11.0.1.2.1
simahawk Apr 13, 2018
39583ff
cms_form: add wizard support
simahawk Feb 24, 2018
8ff28a1
Bump `cms_form` 11.0.1.3.0
simahawk Apr 17, 2018
bd4d050
Wizard: ease customization of stored values
simahawk Apr 19, 2018
d7a55fa
Bump cms_form 11.0.1.3.1
simahawk Apr 22, 2018
e9ff266
Fix `fake_session` helper in form tests common
simahawk Apr 22, 2018
1b81bdb
Add `cms_info`
simahawk Mar 4, 2018
705ba40
Form mixin: use permission checks from `cms_info`
simahawk Apr 22, 2018
27a05ca
Search form: pass `pager` as render value
simahawk Apr 23, 2018
35065bb
cms_form: add request marshallers and tests
simahawk Apr 27, 2018
5f1951d
cms_form: include wizard name in form wrapper klass
simahawk Apr 27, 2018
8882091
Fix wizard rendering tests
simahawk Apr 27, 2018
4009125
Bump cms_form 11.0.1.4.0
simahawk Apr 27, 2018
b8e7dbd
cms_form: add sphinx doc
simahawk Apr 29, 2018
349f9db
Bump cms_form 11.0.1.4.1
simahawk Apr 29, 2018
7605ad9
cms_form: update docs [ci skip]
simahawk Apr 29, 2018
1600635
cms_form: search form support quick domain rules
simahawk May 11, 2018
52a71fe
cms_form: use safe default for pager url
simahawk May 11, 2018
ab3181f
Bump cms_form 11.0.1.4.2
simahawk May 31, 2018
4d7490c
cms_form widgets: fix missing `required` attribute
simahawk Jun 12, 2018
308c731
cms_form: cleanup controller render values
simahawk Jun 12, 2018
ffbd33e
cms_form: be defensive on error block render
simahawk Jun 12, 2018
1d4777f
Fix RST linting
simahawk Jun 28, 2018
5452f33
[UPD] Update cms_form.pot
oca-travis Jun 28, 2018
f9e7974
[11.0] cms_form: do not use empty strings in search domain
grindtildeath Jun 29, 2018
089dab8
Bump cms_form 11.0.1.4.3
simahawk Jul 4, 2018
cb9940b
Search form: fix default URL py3 compat
simahawk Jul 4, 2018
c6117cd
Bump cms_form 11.0.1.4.4
simahawk Jul 4, 2018
5fe1624
[UPD] Update cms_form.pot
oca-travis Jul 4, 2018
53ebf82
cms_form: handle hidden input automatically
simahawk Jul 6, 2018
de3a273
Bump cms_form 11.0.1.5.0
simahawk Jul 6, 2018
baa86fb
[UPD] Update cms_form.pot
oca-travis Jul 6, 2018
a89557f
cms_form: fix regression fields ordering + hidden
simahawk Jul 9, 2018
f25bd19
Bump cms_form 11.0.1.5.1
simahawk Jul 9, 2018
a6efccd
cms_form: selection widget to handle integer values
simahawk Jul 11, 2018
4c162c7
cms_form: fix ordering w/ `groups` protected fields
simahawk Jul 11, 2018
cb74d48
Bump cms_form 11.0.1.5.2
simahawk Jul 12, 2018
c21ec75
cms_form: fix `safe_to_date` to make form extractor happy
simahawk Jul 17, 2018
2cc31a9
cms_form: hidden input respect field type value
simahawk Jul 18, 2018
78a8dc4
cms_form: test `get_widget`
simahawk Jul 21, 2018
f8c5fac
cms_form: test css klass methods
simahawk Jul 21, 2018
8fac682
cms_form: test field wrapper rendering
simahawk Jul 22, 2018
e9fa2a0
cms_form: test `get_form` reusable
simahawk Jul 22, 2018
eb8ca33
cms_form: sort out base test case classes
simahawk Jul 22, 2018
e5068de
cms_form: add basic tests for widget
simahawk Jul 22, 2018
66f558a
cms_form: add test for char widget
simahawk Jul 23, 2018
6319def
cms_form: add test for hidden widget
simahawk Jul 24, 2018
d47c3e9
cms_form: add :float marshaller
simahawk Jul 24, 2018
c755c68
cms_form: input hidden support cast to float
simahawk Jul 24, 2018
731797e
cms_form: test conversion of no value
simahawk Jul 24, 2018
3d65e43
PEP8
simahawk Jul 24, 2018
a981d51
cms_form: allow to skip HttpCase on demand
simahawk Jul 24, 2018
418a624
cms_form: test fieldsets rendering
simahawk Jul 24, 2018
fdbc2d5
cms_form: fixup tests imports
simahawk Jul 25, 2018
6aa8cfb
Bump cms_form 11.0.1.6.0
simahawk Jul 25, 2018
d36c196
cms_form: fix JS indentation date_widget.js
simahawk Aug 7, 2018
43a3e92
cms_form: date widget JS datepicker options custom
simahawk Aug 7, 2018
030d48c
Bump cms_form 11.0.1.6.1
simahawk Aug 7, 2018
2f1b4a3
Fix cms_form RST
simahawk Aug 8, 2018
4de7611
cms_account_form: test coverage 100%
simahawk Aug 5, 2018
71e4480
cms_form: fix default today on date widget
simahawk Aug 21, 2018
7e93d90
Bump cms_form 11.0.1.6.2
simahawk Aug 21, 2018
c4c6700
Added translation using Weblate (French)
grindtildeath Oct 12, 2018
326406c
Translated using Weblate (French)
grindtildeath Oct 12, 2018
617f87e
Update translation files
oca-transbot Dec 9, 2018
53e6b09
cms_form: split widget models to sep files
simahawk Jan 12, 2019
f7d846e
cms_form: fix binary widget ignore none values
simahawk Jan 12, 2019
584f6e9
cms_form: widgets test cov 100%
simahawk Jan 12, 2019
a88aa50
cms_form: x2many widget test cov + fix value handling
simahawk Jan 13, 2019
caf7c7e
cms_form: binary widget test cov + fix value handling
simahawk Jan 13, 2019
5c10968
cms_form: utils test cov 100%
simahawk Jan 13, 2019
b3aa884
cms_form: cms.form.mixin test cov 100%
simahawk Jan 13, 2019
d23f1c7
cms_form: fix selection widget w/ non-Selection field
simahawk Jan 16, 2019
6fff9f4
[REF] cms_form: date widget use snippet animation
simahawk Jan 16, 2019
1203fed
Bump cms_form 11.0.1.6.3
simahawk Jan 18, 2019
f0dde27
cms_form: go ahead w/ test cov 100%
simahawk Jan 21, 2019
35c6a7c
[REF] cms.form.widget.date: use BS datepicker, handle lang
simahawk Jan 16, 2019
a2eb590
[UPD] Update cms_form.pot
oca-travis May 3, 2019
bed44af
Update translation files
oca-transbot May 3, 2019
76eb8b7
[ADD] PoC for ajaxifying forms
hbrunn Jun 28, 2019
f5f64ef
[UPD] Update cms_form.pot
oca-travis Aug 15, 2019
f84eb51
cms_form 11.0.1.7.0
OCA-git-bot Aug 15, 2019
a3ba785
[FIX] cms_form. Ajax requests should also allow public user.
NL66278 Aug 22, 2019
ca43c59
cms_form 11.0.1.7.1
OCA-git-bot Aug 23, 2019
f5cc3d9
Update translation files
oca-transbot Nov 19, 2019
c7e2028
Fix possible XSS attack on user input
Nooka10 Dec 17, 2019
ce08afc
cms_form 11.0.1.7.2
OCA-git-bot Mar 9, 2020
872d96c
cms_form: jump to v13, make uninstallable
simahawk May 16, 2021
b75e906
[REF] cms_form: Black python code
simahawk Apr 18, 2020
70e766e
[MIG] cms_form: Migration to 13.0
simahawk Apr 18, 2020
4f49ed6
cms_form: apply pre-commit
simahawk Apr 25, 2020
dffb91f
cms_form: msic fixes for v13
simahawk Apr 25, 2020
4cda9ac
cms_form: marshaller escape optional
simahawk Apr 26, 2020
13d1e01
cms_form: marshaller escape test + use html.escape
simahawk Apr 26, 2020
b583f3d
cms_form: refactor tests w/ odoo-test-helper
simahawk May 14, 2021
a795a1c
cms_form: fix copyright year
simahawk May 14, 2021
b53326a
cms_form: fix tabs for BS4
simahawk May 17, 2021
762f30a
Set maintainer on cms*
simahawk Aug 23, 2021
3c2a9a4
[UPD] Update cms_form.pot
oca-travis Aug 23, 2021
0f608b9
cms_form 13.0.1.0.1
OCA-git-bot Aug 23, 2021
e493788
Added translation using Weblate (Catalan)
Noel000 Feb 15, 2022
b8128b0
Translated using Weblate (Catalan)
Noel000 Feb 15, 2022
9caedb4
Translated using Weblate (Catalan)
Noel000 Apr 13, 2022
84798d6
cms_form*: make not installable
simahawk Jul 12, 2023
c601f47
cms_form*: add website to manifest
simahawk Jul 12, 2023
fcb0146
cms_form: apply pre-commit
simahawk Jul 11, 2023
309ec1a
cms_form: prepare for v16 (and remove 'website')
simahawk Jul 11, 2023
d9dccc5
cms_form: refactor class init and attributes
simahawk Jul 11, 2023
0a33400
cms_form: fix status msg add after rollback
simahawk Jul 11, 2023
bb6950d
cms_form: mig widgets
simahawk Jul 12, 2023
c9db618
cms_form: make Serialized field fail gracefully
simahawk Jul 12, 2023
eea7cb9
cms_form: add TODO for templates
simahawk Jul 12, 2023
42b41d7
cms_form: ease custom widget declaration
simahawk Jul 13, 2023
3d7bab1
cms_form: add _form_fields_attributes_get
simahawk Jul 13, 2023
a668f5e
cms_form: fix url tests
simahawk Jul 13, 2023
50f2adb
cms_form: x2m widget defaults to []
simahawk Jul 13, 2023
d3cffa1
cms_form: add form_fname_pattern
simahawk Jul 14, 2023
07de9d2
cms_form: improve tests.utils.fake_form
simahawk Jul 14, 2023
8eed892
cms_form: add some todos
simahawk Jul 14, 2023
5057f4b
cms_form: refactor marshaller as class
simahawk Jul 14, 2023
873ad63
cms_form: add :dict:list marshaller
simahawk Jul 14, 2023
2b00644
cms_form: fix/imp request test utils
simahawk Jul 14, 2023
67e7ea1
cms_form: fix controllers rendering and tests
simahawk Jul 14, 2023
d411328
cms_form: fix usage of t-raw in tmpl
simahawk Jul 14, 2023
cd473f0
cms_form: do not break if model has no url field
simahawk Jul 14, 2023
d017e76
cms_form: add field for wrapper template
simahawk Jul 14, 2023
44eefd8
cms_form: fix wizard storage
simahawk Jul 14, 2023
dd7618a
cms_form: wizard load defaults from storage
simahawk Jul 14, 2023
3c4f4a0
cms_form: introduce form_data field
simahawk Jul 18, 2023
4745760
cms_form: add form_get_current_widget
simahawk Jul 18, 2023
e95bc02
cms_form: fix wizard session store
simahawk Jul 18, 2023
04b1a3c
cms_form: widget mixin default to no value
simahawk Jul 18, 2023
7fe8be6
cms_form: add readonly form mode
simahawk Jul 20, 2023
424b055
cms_form: merge fields rather than replace
simahawk Jul 20, 2023
fb23ebe
cms_form: support form_hidden attribute
simahawk Jul 20, 2023
cfdb7a8
cms_form: add ctrl to render portion of forms
simahawk Jul 20, 2023
906331f
cms_form: support wizard form reset on demand
simahawk Jul 20, 2023
f3c3528
cms_form: add wizard.is_final_step_process helper
simahawk Jul 20, 2023
3ad7bec
cms_form: widget mixin ease json data conversion
simahawk Jul 20, 2023
a033376
cms_form: fix wiz last step next url
simahawk Jul 24, 2023
4f12dbc
cms_form: cms.form add mesage after all hooks
simahawk Jul 24, 2023
37138bc
cms_form: add TODO to fix widget ids
simahawk Jul 24, 2023
5d32f96
cms_form: fix warning for exc attribute
simahawk Jul 24, 2023
ca8f08e
cms_form: wipe wiz storage after last step complete
simahawk Jul 24, 2023
a4d00f0
cms_form: fix wrapper tmpl id
simahawk Jul 24, 2023
d7dedda
cms_form: fix wiz btn position
simahawk Jul 25, 2023
5d90859
cms_form: fix session de-serialization
simahawk Jul 25, 2023
c06d11c
cms_form: add search no result tmpl
simahawk Aug 3, 2023
950e5d5
cms_form: fix widget.mixin extract corner case
simahawk Aug 4, 2023
12e7ba1
cms_form: widget init allow direct fields init
simahawk Sep 11, 2023
ce044df
cms_form: support mix/max for numeric widgets
simahawk Sep 11, 2023
f205cf7
cms_form: allow txt input pattern validation
simahawk Sep 11, 2023
49e6fc4
cms_form: allow custom field wrapper tmpl and class by widget
simahawk Sep 13, 2023
bb6ce35
cms_form: add widget.html_value
simahawk Sep 13, 2023
e02573e
cms_form: fix boolean widget class
simahawk Sep 13, 2023
3be9c97
cms_form: fix disabled checkbox
simahawk Sep 13, 2023
d2325e5
cms_form: fix textarea random white spaces
simahawk Sep 13, 2023
74e5efe
cms_form: fix wiz form_load_defaults
simahawk Sep 18, 2023
18a05c7
cms_form: add basic file widget
simahawk Sep 18, 2023
b792a81
cms_form: fix master/slave JS
simahawk Sep 18, 2023
b06a250
cms_form: add wizard.wiz_load_steps
simahawk Sep 19, 2023
c81cc35
cms_form: fix binary file value handling
simahawk Sep 19, 2023
0a96bcd
cms_form: fix widget.w_load none value
simahawk Sep 19, 2023
d089d6f
cms_form: fix marshallers tests
simahawk Sep 19, 2023
9c10ef7
cms_form: fix marshaller cleanup
simahawk Sep 19, 2023
7a28a0e
cms_form: add :file marshaller
simahawk Sep 19, 2023
30fa1a8
cms_form: prevent deprecate warning on perm tests
simahawk Sep 20, 2023
2006353
cms_form: improve utils.safe_to_float
simahawk Sep 20, 2023
adbbe04
cms_form: form_load_defaults use form_data if available
simahawk Sep 20, 2023
deb828e
cms_form: fix number tests
simahawk Sep 20, 2023
eafadcb
cms_form: fix x2m tests
simahawk Sep 20, 2023
f244b9b
cms_form: fix form base test default
simahawk Sep 20, 2023
7667161
cms_form: fix master/slave js handle required
simahawk Sep 22, 2023
2dd66ce
cms_form: fix linting
simahawk Oct 31, 2023
3ec4a1a
Merge PR #130 into 16.0
OCA-git-bot Oct 31, 2023
99034f8
[UPD] Update cms_form.pot
Oct 31, 2023
a317785
[BOT] post-merge updates
OCA-git-bot Oct 31, 2023
f036b7f
Update translation files
weblate Oct 31, 2023
33253ab
cms_form: wizrd optional confirm submit modal
simahawk Oct 31, 2023
c15ba21
Added translation using Weblate (Italian)
mymage Nov 12, 2023
e033adc
Translated using Weblate (Italian)
mymage Nov 13, 2023
bd48d93
Added translation using Weblate (Spanish)
Ivorra78 Dec 13, 2023
a745579
Translated using Weblate (Spanish)
Ivorra78 Dec 13, 2023
efd303b
cms_form: add FormRedirect exception
simahawk Jan 25, 2024
708b632
Translated using Weblate (Italian)
mymage Jul 1, 2024
9612c9e
Translated using Weblate (Catalan)
QuiJoQuim Dec 7, 2024
f742768
Merge PR #138 into 16.0
OCA-git-bot Jan 28, 2025
166192d
[BOT] post-merge updates
OCA-git-bot Jan 28, 2025
267136c
Merge PR #135 into 16.0
OCA-git-bot Feb 6, 2025
f0b27ad
[UPD] Update cms_form.pot
Feb 6, 2025
0346249
[BOT] post-merge updates
OCA-git-bot Feb 6, 2025
eca3f00
Update translation files
weblate Feb 6, 2025
41c362e
Translated using Weblate (Italian)
mymage Feb 6, 2025
6f1de01
Merge remote-tracking branch 'cmsform/16.0' into 15.0-backport-cms_form
jonbulz Sep 19, 2025
43f18d5
cms_form: backport from 16.0 to 15.0
jonbulz Sep 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions cms_form/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
.. image:: https://img.shields.io/badge/licence-lgpl--3-blue.svg
:target: http://www.gnu.org/licenses/LGPL-3.0-standalone.html
:alt: License: LGPL-3

CMS Form
========

Advanced contents form framework. Allows to define front-end forms for every models in a simple way.

If you are tired of re-defining every time an edit form or a search form for your odoo portal or website,
this is the module you are looking for.

Features
========

* automatic form generation (create, write, search, wizards)
* automatic route generation (create, write, search, wizards)
* automatic machinery based on fields' type:
* widget rendering
* field value load (from existing instance or from request)
* field value extraction (from request)
* field value write (to existing instance)
* automatic field grouping in fieldsets

* highly customizable
* works with every odoo model
* works also without any model

Usage
=====

Check full documentation inside `doc` folder.


Known issues / Roadmap
======================

* add more tests, especially per each widget and type of field
* provide better widgets for image and file fields in general
* o2m fields: to be tested at all
* move widgets to abstract models too
* search form: generate default search domain in a clever way
* add easy way to switch from horizontal to vertical form
* provide more examples
* x2x fields: allow sub-items creation
* handle api onchanges
* support python expressions into master/slave rules
* the ajax UI blocking/spinner could be more beautiful


Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/website-cms/issues>`_. 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.

Credits
=======

Sponsor
-------

* `Fluxdock.io <https://fluxdock.io>`_.

Contributors
------------

* Simone Orsi <[email protected]>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
4 changes: 4 additions & 0 deletions cms_form/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# not sure why these lines are counted as not test covered
# since nothing would work in tests w/out them being loaded
from . import models # pragma: no cover
from . import controllers # pragma: no cover
41 changes: 41 additions & 0 deletions cms_form/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2017 Simone Orsi
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

{
"name": "CMS Form",
"summary": """
Basic content type form""",
"version": "15.0.1.0.0",
"license": "LGPL-3",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["simahawk"],
"website": "https://github.com/OCA/website-cms",
"depends": [
"cms_info",
"cms_status_message",
# TODO: get rid of portal too
"portal",
"base_sparse_field",
"website",
"web",
],
"data": [
"security/cms_form.xml",
"templates/form.xml",
"templates/widgets.xml",
"templates/portal.xml",
],
"installable": True,
"assets": {
"web.assets_frontend": [
"cms_form/static/src/scss/cms_form.scss",
"cms_form/static/src/scss/progressbar.scss",
# TODO: review them all w/ modern JS
"cms_form/static/src/js/select2widgets.js",
"cms_form/static/src/js/textarea_widget.js",
"cms_form/static/src/js/master_slave.js",
"cms_form/static/src/js/lock_copy_paste.js",
"cms_form/static/src/js/ajax.js",
],
},
}
1 change: 1 addition & 0 deletions cms_form/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
259 changes: 259 additions & 0 deletions cms_form/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
# Copyright 2017 Simone Orsi
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

import json

import werkzeug

from odoo import _, http
from odoo.http import request

from ..exceptions import FormRedirect


class FormControllerMixin(object):

# default template
template = "cms_form.portal_form_wrapper"

def get_template(self, form, **kw):
"""Retrieve rendering template.

Defaults to `template` attribute.
Can be overridden straight in the form
using the attribute `form_wrapper_template`.
"""
template = form.form_wrapper_template or self.template

if not template:
raise NotImplementedError("You must provide a template!")
return template

def get_render_values(self, form, **kw):
"""Retrieve rendering values.

You can override this to inject more values.
"""
main_object = form.main_object
# Cleanup render values and remove form fields' values.
# When you submit a form and there's an error odoo will give you back
# all submitted values into `kw` but:
# 1. we don't need them since all values are encapsulated
# into form.form_render_values
# and are already accessible on each widget
# 2. this can break website rendering because you might have fields
# w/ a name that overrides a rendering value not related to a form.
# Most common example: field named `website` will override
# odoo record for current website.
vals = {k: v for k, v in kw.items() if k not in form.form_fields_get()}
vals.update({"form": form, "main_object": main_object, "controller": self})
return vals

def form_model_key(self, model, **kw):
"""Return a valid form model."""
return "cms.form." + model

def get_form(self, model, model_id=None, **kw):
"""Retrieve form for given model and initialize it."""
form_model_key = kw.pop("form_model_key", None)
if not form_model_key:
form_model_key = self.form_model_key(model, **kw)
if form_model_key in request.env:
if model:
main_object = request.env[model]
if model_id:
main_object = request.env[model].browse(model_id)
else:
# HACK: odoo requires a stupid `main_object` to stay there
# See https://github.com/odoo/odoo/pull/22384
# So here we mock main_object to the form model recordset
main_object = request.env[form_model_key]
form = request.env[form_model_key].form_init(
request, main_object=main_object, **kw
)
else:
# TODO: enable form by default?
# How? with a flag on ir.model.model?
# And which fields to include automatically?
raise NotImplementedError(_("%s model has no CMS form registered.") % model)
return form

def make_response(self, model, model_id=None, **kw):
"""Prepare and return form response.

:param model: an odoo model's name
:param model_id: an odoo record's id
:param page: current page if any (mostly for search forms)
:param kw: extra parameters

How it works:
* retrieve current main object if any
* check permission on model and/or main object
* retrieve the form
* make the form process current request
* if the form is successful and has `form_redirect` attribute
it redirects to it.
* otherwise it just renders the form
"""
form = self.get_form(model, model_id=model_id, **kw)
form.form_check_permission()
# pass only specific extra args, to not pollute form render values
try:
form.form_process(extra_args={"page": kw.get("page")})
except FormRedirect as exc:
return werkzeug.utils.redirect(exc.next_url, code=303)
# search forms do not need these attrs
if getattr(form, "form_success", None) and getattr(form, "form_redirect", None):
# anything went fine, redirect to next url
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/303
return werkzeug.utils.redirect(form.form_next_url(), code=303)

if form.form_render_values.get("errors"):
# transient model fields on cms.form are reset after savepoint rollback
# so in case of errors, the form needs to be re-initialized
# otherwise, the template won't be able to render
form = self.get_form(model, model_id=model_id, form_data=None)

# render form wrapper
values = self.get_render_values(form, **kw)
return request.render(
self.get_template(form, **kw),
values,
headers={"Cache-Control": "no-cache"},
)

def make_response_ajax(self, model, model_id=None, **kw):
"""Return only results to replace the current result with"""
response = self.make_response(model, model_id=model_id, **kw)
data = {
"content": self._make_response_ajax_content(response),
}
return json.dumps(data)

def _make_response_ajax_content(self, response):
"""Return a HTML string to be passed to the client"""
raise NotImplementedError()


class CMSFormController(http.Controller, FormControllerMixin):
"""CMS form controller."""

@http.route(
["/cms/create/<string:model>", "/cms/edit/<string:model>/<int:model_id>"],
type="http",
auth="user",
website=True,
)
def cms_form(self, model, model_id=None, **kw):
"""Handle a `form` route."""
return self.make_response(model, model_id=model_id, **kw)

@http.route(
[
"/cms/render/form/<string:form_model>",
"/cms/render/form/<string:form_model>/<int:model_id>",
],
type="json",
auth="user",
website=True,
# FIXME
csfr=False,
)
def cms_form_render(self, form_model, model_id=None, **kw):
kw["form_model_key"] = form_model
data = request.get_json_data()
process_form = data.get("process", kw.pop("process", False))
widget_params = data.get("widget_params", kw.pop("widget_params", {}))
if widget_params:
kw["form_model_fields"] = list(widget_params)
form = self.get_form(None, model_id=model_id, **kw)
form.form_check_permission()
if process_form:
form.form_process()
by_widget = {}
for fname, params in widget_params.items():
widget = form.form_get_current_widget(fname)
widget.update(params)
by_widget[fname] = widget.render()
if by_widget:
return {"by_widget": by_widget}
return {"form": form.form_render()}


class WizardFormControllerMixin(FormControllerMixin):

template = "cms_form.portal_wizard_form_wrapper"

def make_response(self, wiz_model, model_id=None, page=1, **kw):
"""Custom response.

The main difference w/ the base form controller is that
we retrieve the form model via wizard step.
"""
# init wizard 1st
wiz = request.env[wiz_model].form_init(request, page=page, **kw)
step_info = wiz.wiz_get_step_info(page)
# retrieve form model for current step
form_model = step_info["form_model"]
model = request.env[form_model].form_model_name
kw["form_model_key"] = form_model
return super().make_response(model, model_id=model_id, page=page, **kw)


class CMSWizardFormController(http.Controller, WizardFormControllerMixin):
"""CMS wizard controller."""

@http.route(
["/cms/wiz/<string:wiz_model>/page/<int:page>"],
type="http",
auth="user",
website=True,
)
def cms_wiz(self, wiz_model, model_id=None, **kw):
"""Handle a wizard route."""
return self.make_response(wiz_model, model_id=model_id, **kw)


class SearchFormControllerMixin(FormControllerMixin):

template = "cms_form.portal_search_form_wrapper"

def form_model_key(self, model, **kw):
return "cms.form.search." + model

def get_render_values(self, form, **kw):
values = super().get_render_values(form, **kw)
values.update({"pager": form.form_search_results["pager"]})
return values


class CMSSearchFormController(http.Controller, SearchFormControllerMixin):
"""CMS form controller."""

@http.route(
["/cms/search/<string:model>", "/cms/search/<string:model>/page/<int:page>"],
type="http",
auth="public",
website=True,
)
def cms_form(self, model, **kw):
"""Handle a search `form` route."""
response = self.make_response(model, **kw)
return response

@http.route(
[
"/cms/ajax/search/<string:model>",
"/cms/ajax/search/<string:model>/<int:model_id>",
],
type="http",
auth="public",
website=True,
)
def ajax(self, model, model_id=None, **kw):
"""handle an ajax request"""
return self.make_response_ajax(model, **kw)

def _make_response_ajax_content(self, response):
template = response.qcontext["form"].form_search_results_template
return request.env["ir.qweb"]._render(template, response.qcontext)
Loading
Loading