Skip to content

Commit 38cebf7

Browse files
committed
Merge PR #582 into 18.0
Signed-off-by lmignon
2 parents 3c7dfb2 + 36d9cda commit 38cebf7

23 files changed

Lines changed: 1211 additions & 0 deletions

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ exclude: |
22
(?x)
33
# NOT INSTALLABLE ADDONS
44
^fastapi_auth_jwt/|
5+
^extendable_fastapi/|
56
# END NOT INSTALLABLE ADDONS
67
# Files and folders generated by bots, to avoid loops
78
^setup/|/static/description/index\.html$|

extendable_fastapi/README.rst

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
==================
2+
Extendable Fastapi
3+
==================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:4e4f5d96294f860ce7f0c4e023431f8ed9ca011c318b5ba4a3cfcd15c31eac1a
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
18+
:alt: License: LGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
20+
:target: https://github.com/OCA/rest-framework/tree/18.0/extendable_fastapi
21+
:alt: OCA/rest-framework
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-extendable_fastapi
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This addon is a technical addon used to allows the use of
32+
`extendable <https://pypi.org/project/extendable/>`__ classes in the
33+
implementation of your fastapi endpoint handlers. It also allows you to
34+
use
35+
`extendable_pydantic <https://pypi.org/project/extendable_pydantic/>`__
36+
models when defining your endpoint handlers request and response models.
37+
38+
**Table of contents**
39+
40+
.. contents::
41+
:local:
42+
43+
Changelog
44+
=========
45+
46+
16.0.2.1.1 (2023-11-07)
47+
-----------------------
48+
49+
**Bugfixes**
50+
51+
- Fix registry corruption when running tests difined in a class
52+
inheriting of the *FastAPITransactionCase* class if an error occurs in
53+
the *setUpClass* after the call to super().
54+
(`#392 <https://github.com/OCA/rest-framework/issues/392>`__)
55+
56+
16.0.2.1.0 (2023-10-13)
57+
-----------------------
58+
59+
**Features**
60+
61+
-
62+
63+
- New base schemas: *PagedCollection*. This schema is used to define
64+
the the structure of a paged collection of resources. This schema is
65+
similar to the ones defined in the Odoo's **fastapi** addon but
66+
works as/with extendable models.
67+
- The *StrictExtendableBaseModel* has been moved to the
68+
*extendable_pydantic* python lib. You should consider to import it
69+
from there.
70+
(`#380 <https://github.com/OCA/rest-framework/issues/380>`__)
71+
72+
Bug Tracker
73+
===========
74+
75+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
76+
In case of trouble, please check there if your issue has already been reported.
77+
If you spotted it first, help us to smash it by providing a detailed and welcomed
78+
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20extendable_fastapi%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
79+
80+
Do not contact contributors directly about support or help with technical issues.
81+
82+
Credits
83+
=======
84+
85+
Authors
86+
-------
87+
88+
* ACSONE SA/NV
89+
90+
Contributors
91+
------------
92+
93+
- Laurent Mignon <laurent.mignon@acsone.eu> (https://acsone.eu)
94+
- Marie Lejeune <marie.lejeune@acsone.eu> (https://acsone.eu)
95+
96+
Maintainers
97+
-----------
98+
99+
This module is maintained by the OCA.
100+
101+
.. image:: https://odoo-community.org/logo.png
102+
:alt: Odoo Community Association
103+
:target: https://odoo-community.org
104+
105+
OCA, or the Odoo Community Association, is a nonprofit organization whose
106+
mission is to support the collaborative development of Odoo features and
107+
promote its widespread use.
108+
109+
.. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px
110+
:target: https://github.com/lmignon
111+
:alt: lmignon
112+
113+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
114+
115+
|maintainer-lmignon|
116+
117+
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/extendable_fastapi>`_ project on GitHub.
118+
119+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

extendable_fastapi/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import fastapi_dispatcher
2+
from .schemas import StrictExtendableBaseModel

extendable_fastapi/__manifest__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright 2023 ACSONE SA/NV
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
3+
4+
{
5+
"name": "Extendable Fastapi",
6+
"summary": """
7+
Allows the use of extendable into fastapi apps""",
8+
"version": "18.0.1.0.0",
9+
"license": "LGPL-3",
10+
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
11+
"maintainers": ["lmignon"],
12+
"website": "https://github.com/OCA/rest-framework",
13+
"depends": ["fastapi", "extendable"],
14+
"data": [],
15+
"demo": [],
16+
"external_dependencies": {
17+
"python": [
18+
"pydantic>=2.0.0",
19+
"extendable-pydantic>=1.2.0",
20+
],
21+
},
22+
"installable": True,
23+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2023 ACSONE SA/NV
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL).
3+
4+
from contextlib import contextmanager
5+
6+
from odoo.addons.extendable.registry import _extendable_registries_database
7+
from odoo.addons.fastapi.fastapi_dispatcher import (
8+
FastApiDispatcher as BaseFastApiDispatcher,
9+
)
10+
11+
from extendable import context
12+
13+
14+
class FastApiDispatcher(BaseFastApiDispatcher):
15+
routing_type = "fastapi"
16+
17+
def dispatch(self, endpoint, args):
18+
with self._manage_extendable_context():
19+
return super().dispatch(endpoint, args)
20+
21+
@contextmanager
22+
def _manage_extendable_context(self):
23+
env = self.request.env
24+
registry = _extendable_registries_database.get(env.cr.dbname, {})
25+
token = context.extendable_registry.set(registry)
26+
try:
27+
response = yield
28+
finally:
29+
context.extendable_registry.reset(token)
30+
return response
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
#
4+
msgid ""
5+
msgstr ""
6+
"Project-Id-Version: Odoo Server 16.0\n"
7+
"Report-Msgid-Bugs-To: \n"
8+
"Last-Translator: \n"
9+
"Language-Team: \n"
10+
"MIME-Version: 1.0\n"
11+
"Content-Type: text/plain; charset=UTF-8\n"
12+
"Content-Transfer-Encoding: \n"
13+
"Plural-Forms: \n"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import fastapi_endpoint_demo
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2023 ACSONE SA/NV
2+
# License LGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import models
5+
6+
from fastapi import APIRouter
7+
8+
from ..tests.routers import demo_pydantic_router
9+
10+
11+
class FastapiEndpoint(models.Model):
12+
_inherit = "fastapi.endpoint"
13+
14+
def _get_fastapi_routers(self) -> list[APIRouter]:
15+
# Add router defined for tests to the demo app
16+
routers = super()._get_fastapi_routers()
17+
if self.app == "demo":
18+
routers.append(demo_pydantic_router)
19+
return routers

extendable_fastapi/pyproject.toml

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"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Laurent Mignon \<<laurent.mignon@acsone.eu>\> (<https://acsone.eu>)
2+
- Marie Lejeune \<<marie.lejeune@acsone.eu>\> (<https://acsone.eu>)

0 commit comments

Comments
 (0)