Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] web_widget_pattern: Migration to 18.0 #3059

Open
wants to merge 5 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
119 changes: 119 additions & 0 deletions web_widget_pattern/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
==============
Input patterns
==============

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:049fefbca58070d1187e57e952f2eac13aa3aa4f636ca6c84e2ec8e67f4cd125
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/16.0/web_widget_pattern
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-16-0/web-16-0-web_widget_pattern
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows to use
`patterns <https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern>`__
in text fields in the backend.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Usage
=====

You can either define a pattern in your Python source code on a field as
in

.. code:: python

my_field = fields.Char(pattern='[0-9]')

or on view level as in

.. code:: xml

<field name="my_field" pattern="[0-9]" />

Demo data adds a pattern on the street2 field on partner forms to only
allow numbers.

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

- allow to optionally validate fields against its pattern server side
- support text, url, email, phone, ... fields
- support using a pattern from a computed field

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_widget_pattern%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Hunki Enterprises BV

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

- Holger Brunn <[email protected]>
(https://hunki-enteprises.com)
- Sensible Consulting Services <[email protected]>
(https://sensiblecs.com)
Maintainers
-----------

This module is maintained by the OCA.

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

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.

.. |maintainer-hbrunn| image:: https://github.com/hbrunn.png?size=40px
:target: https://github.com/hbrunn
:alt: hbrunn

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-hbrunn|

This module is part of the `OCA/web <https://github.com/OCA/web/tree/16.0/web_widget_pattern>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions web_widget_pattern/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
27 changes: 27 additions & 0 deletions web_widget_pattern/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2024 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)

{
"name": "Input patterns",
"summary": "Allows to define a regex for validating input on the backend",
"version": "18.0.1.0.0",
"development_status": "Alpha",
"category": "Technical",
"website": "https://github.com/OCA/web",
"author": "Hunki Enterprises BV, Odoo Community Association (OCA)",
"maintainers": ["hbrunn"],
"license": "AGPL-3",
"depends": [
"web",
],
"data": [],
"demo": [
"demo/res_partner_views.xml",
],
"assets": {
"web.assets_backend": [
"web_widget_pattern/static/src/*.xml",
"web_widget_pattern/static/src/*.esm.js",
],
},
}
14 changes: 14 additions & 0 deletions web_widget_pattern/demo/res_partner_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 Hunki Enterprises BV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0) -->
<data>
<record id="view_partner_form" model="ir.ui.view">
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='street2']" position="attributes">
<attribute name="pattern">[0-9]+</attribute>
</xpath>
</field>
</record>
</data>
22 changes: 22 additions & 0 deletions web_widget_pattern/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_widget_pattern
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-05-20 13:38+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: web_widget_pattern
#: model:ir.model,name:web_widget_pattern.model_base
msgid "Base"
msgstr "Base"
19 changes: 19 additions & 0 deletions web_widget_pattern/i18n/web_widget_pattern.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * web_widget_pattern
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: web_widget_pattern
#: model:ir.model,name:web_widget_pattern.model_base
msgid "Base"
msgstr ""
1 change: 1 addition & 0 deletions web_widget_pattern/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base
28 changes: 28 additions & 0 deletions web_widget_pattern/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 Hunki Enterprises BV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl-3.0)

from odoo import api, fields, models


class Base(models.AbstractModel):
_inherit = "base"

def _valid_field_parameter(self, field, name):
return super()._valid_field_parameter(field, name) or (
name == "pattern" and isinstance(field, fields.Char)
)

@api.model
def _get_view_field_attributes(self):
return super()._get_view_field_attributes() + ["pattern"]

@api.model
def fields_get(self, allfields=None, attributes=None):
result = super().fields_get(allfields=allfields, attributes=attributes)
if attributes is None or "pattern" in attributes:
for field_name, description in result.items():
field = self._fields.get(field_name)
pattern = getattr(field, "pattern", None)
if pattern is not None:
description["pattern"] = pattern
return result
2 changes: 2 additions & 0 deletions web_widget_pattern/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Holger Brunn \<[email protected]> (https://hunki-enteprises.com)
- Sensible Consulting Services \<[email protected]> (https://sensiblecs.com)
1 change: 1 addition & 0 deletions web_widget_pattern/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows to use [patterns](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern) in text fields in the backend.
3 changes: 3 additions & 0 deletions web_widget_pattern/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- allow to optionally validate fields against its pattern server side
- support text, url, email, phone, ... fields
- support using a pattern from a computed field
13 changes: 13 additions & 0 deletions web_widget_pattern/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
You can either define a pattern in your Python source code on a field as in

```python
my_field = fields.Char(pattern='[0-9]')
```

or on view level as in

```xml
<field name="my_field" pattern="[0-9]" />
```

Demo data adds a pattern on the street2 field on partner forms to only allow numbers.
Binary file added web_widget_pattern/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading