Skip to content

Commit 3d36d83

Browse files
paradoxxxzerosebastienbeau
authored andcommitted
[MIG] search_engine_serializer_pydantic
1 parent 5158f62 commit 3d36d83

9 files changed

Lines changed: 39 additions & 46 deletions

File tree

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ exclude: |
55
^connector_elasticsearch/|
66
^connector_search_engine_serializer_ir_export/|
77
^search_engine_image_thumbnail/|
8-
^search_engine_serializer_pydantic/|
98
# END NOT INSTALLABLE ADDONS
109
# Files and folders generated by bots, to avoid loops
1110
^setup/|/static/description/index\.html$|

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ requests
33
typesense>=1.1.0
44
typing-extensions
55
unidecode
6+
pydantic

search_engine_serializer_pydantic/README.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Search Engine Serilizer Pydantic
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsearch--engine-lightgray.png?logo=github
20-
:target: https://github.com/OCA/search-engine/tree/16.0/search_engine_serializer_pydantic
20+
:target: https://github.com/OCA/search-engine/tree/18.0/search_engine_serializer_pydantic
2121
:alt: OCA/search-engine
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/search-engine-16-0/search-engine-16-0-search_engine_serializer_pydantic
23+
:target: https://translation.odoo-community.org/projects/search-engine-18-0/search-engine-18-0-search_engine_serializer_pydantic
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/search-engine&target_branch=16.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/search-engine&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -99,16 +99,16 @@ Example:
9999
Known issues / Roadmap
100100
======================
101101

102-
- Add dedicated widget to display in a user friendly way the json
103-
schema generated by the serializer on the index form.
102+
- Add dedicated widget to display in a user friendly way the json schema
103+
generated by the serializer on the index form.
104104

105105
Bug Tracker
106106
===========
107107

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

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

@@ -123,14 +123,14 @@ Authors
123123
Contributors
124124
------------
125125

126-
- Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu/)
126+
- Laurent Mignon laurent.mignon@acsone.eu (https://www.acsone.eu/)
127127

128128
Other credits
129129
-------------
130130

131131
The development of this module has been financially supported by:
132132

133-
- (ALCYON Belux)[https://www.alcyonbelux.be/fr/]
133+
- (ALCYON Belux)[https://www.alcyonbelux.be/fr/]
134134

135135
Maintainers
136136
-----------
@@ -153,6 +153,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
153153

154154
|maintainer-lmignon|
155155

156-
This module is part of the `OCA/search-engine <https://github.com/OCA/search-engine/tree/16.0/search_engine_serializer_pydantic>`_ project on GitHub.
156+
This module is part of the `OCA/search-engine <https://github.com/OCA/search-engine/tree/18.0/search_engine_serializer_pydantic>`_ project on GitHub.
157157

158158
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

search_engine_serializer_pydantic/__manifest__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33

44
{
55
"name": "Search Engine Serilizer Pydantic",
6-
"summary": """
7-
Defines base class for pydantic baser serializer""",
8-
"version": "16.0.1.0.0",
6+
"summary": "Defines base class for pydantic baser serializer",
7+
"version": "18.0.1.0.0",
98
"license": "AGPL-3",
109
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
1110
"maintainers": ["lmignon"],
@@ -17,11 +16,10 @@
1716
"data": [
1817
"views/se_index.xml",
1918
],
20-
"demo": [],
2119
"external_dependencies": {
2220
"python": [
2321
"pydantic",
2422
],
2523
},
26-
"installable": False,
24+
"installable": True,
2725
}

search_engine_serializer_pydantic/models/se_index.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

44
import json
5-
from typing import Type
65

76
from pydantic import BaseModel
87

@@ -12,7 +11,6 @@
1211

1312

1413
class SeIndex(models.Model):
15-
1614
_inherit = "se.index"
1715

1816
is_pydantic_serializer = fields.Boolean(
@@ -47,7 +45,7 @@ def _compute_record_json_schema(self):
4745
rec.record_json_schema = None
4846
rec.record_json_schema_str = ""
4947
else:
50-
model: Type[BaseModel] = rec.model_serializer.get_model_class()
48+
model: type[BaseModel] = rec.model_serializer.get_model_class()
5149
rec.record_json_schema = model.model_json_schema()
5250
rec.record_json_schema_str = json.dumps(
5351
rec.record_json_schema, indent=2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"

search_engine_serializer_pydantic/static/description/index.html

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
@@ -9,10 +8,11 @@
98

109
/*
1110
:Author: David Goodger (goodger@python.org)
12-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1616
1717
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1818
customize this style sheet.
@@ -275,7 +275,7 @@
275275
margin-left: 2em ;
276276
margin-right: 2em }
277277

278-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
279279
pre.code, code { background-color: #eeeeee }
280280
pre.code .comment, code .comment { color: #5C6576 }
281281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +301,7 @@
301301
span.pre {
302302
white-space: pre }
303303

304-
span.problematic {
304+
span.problematic, pre.problematic {
305305
color: red }
306306

307307
span.section-subtitle {
@@ -369,7 +369,7 @@ <h1 class="title">Search Engine Serilizer Pydantic</h1>
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370370
!! source digest: sha256:c1ccbbd934bcc84a6ba68660b56e79a875d6da98da0bea29e68ce453e054aae0
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/search-engine/tree/16.0/search_engine_serializer_pydantic"><img alt="OCA/search-engine" src="https://img.shields.io/badge/github-OCA%2Fsearch--engine-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/search-engine-16-0/search-engine-16-0-search_engine_serializer_pydantic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/search-engine&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/search-engine/tree/18.0/search_engine_serializer_pydantic"><img alt="OCA/search-engine" src="https://img.shields.io/badge/github-OCA%2Fsearch--engine-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/search-engine-18-0/search-engine-18-0-search_engine_serializer_pydantic"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/search-engine&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This module is a technical module that define a new abstract class named
374374
<tt class="docutils literal">PydandicModelSerializer</tt> that inherit from
375375
<tt class="docutils literal">odoo.addons.connector_search_engine.tools.serializer.ModelSerializer</tt></p>
@@ -413,46 +413,46 @@ <h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
413413
provided by this module.</p>
414414
<p>Example:</p>
415415
<pre class="code python literal-block">
416-
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Type</span><span class="w">
417-
</span><span class="kn">from</span> <span class="nn">pydantic</span> <span class="kn">import</span> <span class="n">BaseModel</span><span class="w">
416+
<span class="kn">from</span><span class="w"> </span><span class="nn">typing</span><span class="w"> </span><span class="kn">import</span> <span class="n">Type</span><span class="w">
417+
</span><span class="kn">from</span><span class="w"> </span><span class="nn">pydantic</span><span class="w"> </span><span class="kn">import</span> <span class="n">BaseModel</span><span class="w">
418418

419-
</span><span class="kn">from</span> <span class="nn">odoo.addons.search_engine_serialize_pydantic.tools.serializer</span> <span class="kn">import</span> <span class="p">(</span><span class="w">
419+
</span><span class="kn">from</span><span class="w"> </span><span class="nn">odoo.addons.search_engine_serialize_pydantic.tools.serializer</span><span class="w"> </span><span class="kn">import</span> <span class="p">(</span><span class="w">
420420
</span> <span class="n">PydanticModelSerializer</span><span class="p">,</span><span class="w">
421421
</span><span class="p">)</span><span class="w">
422422

423423

424-
</span><span class="k">class</span> <span class="nc">MyModel</span><span class="p">(</span><span class="n">BaseModel</span><span class="p">):</span><span class="w">
424+
</span><span class="k">class</span><span class="w"> </span><span class="nc">MyModel</span><span class="p">(</span><span class="n">BaseModel</span><span class="p">):</span><span class="w">
425425
</span> <span class="n">name</span><span class="p">:</span> <span class="nb">str</span><span class="w">
426426
</span> <span class="n">description</span><span class="p">:</span> <span class="nb">str</span><span class="w">
427427

428-
</span> <span class="k">def</span> <span class="nf">record_to_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record</span><span class="p">:</span> <span class="n">Model</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span><span class="w">
428+
</span> <span class="k">def</span><span class="w"> </span><span class="nf">record_to_model</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record</span><span class="p">:</span> <span class="n">Model</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span><span class="w">
429429
</span> <span class="k">return</span> <span class="bp">cls</span><span class="p">(</span><span class="w">
430430
</span> <span class="n">name</span><span class="o">=</span><span class="n">record</span><span class="o">.</span><span class="n">name</span><span class="p">,</span><span class="w">
431431
</span> <span class="n">description</span><span class="o">=</span><span class="n">record</span><span class="o">.</span><span class="n">description</span><span class="p">,</span><span class="w">
432432
</span> <span class="p">)</span><span class="w">
433433

434-
</span><span class="k">class</span> <span class="nc">MyModelSerializer</span><span class="p">(</span><span class="n">PydanticModelSerializer</span><span class="p">):</span><span class="w">
435-
</span> <span class="k">def</span> <span class="nf">get_model_class</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Type</span><span class="p">[</span><span class="n">MyModel</span><span class="p">]:</span><span class="w">
434+
</span><span class="k">class</span><span class="w"> </span><span class="nc">MyModelSerializer</span><span class="p">(</span><span class="n">PydanticModelSerializer</span><span class="p">):</span><span class="w">
435+
</span> <span class="k">def</span><span class="w"> </span><span class="nf">get_model_class</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="n">Type</span><span class="p">[</span><span class="n">MyModel</span><span class="p">]:</span><span class="w">
436436
</span> <span class="k">return</span> <span class="n">MyModel</span><span class="w">
437437

438-
</span> <span class="k">def</span> <span class="nf">serialize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record</span><span class="p">:</span> <span class="n">Model</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span><span class="w">
438+
</span> <span class="k">def</span><span class="w"> </span><span class="nf">serialize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">record</span><span class="p">:</span> <span class="n">Model</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="nb">dict</span><span class="p">:</span><span class="w">
439439
</span> <span class="n">model</span><span class="p">:</span> <span class="n">MyModel</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_model_class</span><span class="p">()</span><span class="o">.</span><span class="n">record_to_model</span><span class="p">(</span><span class="n">record</span><span class="p">)</span><span class="w">
440440
</span> <span class="k">return</span> <span class="n">model</span><span class="o">.</span><span class="n">model_dump</span><span class="p">()</span>
441441
</pre>
442442
</div>
443443
<div class="section" id="known-issues-roadmap">
444444
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
445445
<ul class="simple">
446-
<li>Add dedicated widget to display in a user friendly way the json
447-
schema generated by the serializer on the index form.</li>
446+
<li>Add dedicated widget to display in a user friendly way the json schema
447+
generated by the serializer on the index form.</li>
448448
</ul>
449449
</div>
450450
<div class="section" id="bug-tracker">
451451
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
452452
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/search-engine/issues">GitHub Issues</a>.
453453
In case of trouble, please check there if your issue has already been reported.
454454
If you spotted it first, help us to smash it by providing a detailed and welcomed
455-
<a class="reference external" href="https://github.com/OCA/search-engine/issues/new?body=module:%20search_engine_serializer_pydantic%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
455+
<a class="reference external" href="https://github.com/OCA/search-engine/issues/new?body=module:%20search_engine_serializer_pydantic%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
456456
<p>Do not contact contributors directly about support or help with technical issues.</p>
457457
</div>
458458
<div class="section" id="credits">
@@ -479,13 +479,15 @@ <h2><a class="toc-backref" href="#toc-entry-8">Other credits</a></h2>
479479
<div class="section" id="maintainers">
480480
<h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
481481
<p>This module is maintained by the OCA.</p>
482-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
482+
<a class="reference external image-reference" href="https://odoo-community.org">
483+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
484+
</a>
483485
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
484486
mission is to support the collaborative development of Odoo features and
485487
promote its widespread use.</p>
486488
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
487489
<p><a class="reference external image-reference" href="https://github.com/lmignon"><img alt="lmignon" src="https://github.com/lmignon.png?size=40px" /></a></p>
488-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/search-engine/tree/16.0/search_engine_serializer_pydantic">OCA/search-engine</a> project on GitHub.</p>
490+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/search-engine/tree/18.0/search_engine_serializer_pydantic">OCA/search-engine</a> project on GitHub.</p>
489491
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
490492
</div>
491493
</div>

search_engine_serializer_pydantic/tools/serializer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

44
from abc import abstractmethod
5-
from typing import Type
65

76
from pydantic import BaseModel
87

@@ -11,6 +10,6 @@
1110

1211
class PydanticModelSerializer(ModelSerializer):
1312
@abstractmethod
14-
def get_model_class(self) -> Type[BaseModel]:
13+
def get_model_class(self) -> type[BaseModel]:
1514
"""Return the pydantic model class."""
1615
...

search_engine_serializer_pydantic/views/se_index.xml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,20 @@
22
<!-- Copyright 2023 ACSONE SA/NV
33
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
44
<odoo>
5-
65
<record model="ir.ui.view" id="se_index_form_view">
76
<field name="name">se.index.form</field>
87
<field name="model">se.index</field>
98
<field name="inherit_id" ref="connector_search_engine.se_index_form_view" />
109
<field name="arch" type="xml">
11-
<field name="name" position="after">
12-
<field name="is_pydantic_serializer" invisible="1" />
13-
</field>
1410
<group name="config" position="after">
1511
<group
1612
name="se_index_pydantic"
1713
string="Pydantic"
18-
attrs="{'invisible': [('is_pydantic_serializer', '=', False)]}"
14+
invisible="not is_pydantic_serializer"
1915
>
2016
<field name="record_json_schema_str" widget="ace" />
2117
</group>
2218
</group>
2319
</field>
2420
</record>
25-
26-
27-
2821
</odoo>

0 commit comments

Comments
 (0)