Skip to content

Commit d6b2add

Browse files
[IMP] base_rest: pre-commit auto fixes
1 parent 7d9cb8e commit d6b2add

12 files changed

Lines changed: 69 additions & 80 deletions

File tree

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
exclude: |
22
(?x)
33
# NOT INSTALLABLE ADDONS
4-
^base_rest/|
54
^base_rest_auth_api_key/|
65
^base_rest_pydantic/|
76
^extendable/|

base_rest/README.rst

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Base Rest
2121
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2222
:alt: License: LGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
24-
:target: https://github.com/OCA/rest-framework/tree/18.0/base_rest
24+
:target: https://github.com/OCA/rest-framework/tree/19.0/base_rest
2525
:alt: OCA/rest-framework
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest
27+
:target: https://translation.odoo-community.org/projects/rest-framework-19-0/rest-framework-19-0-base_rest
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -89,8 +89,8 @@ Usage
8989

9090
To add your own REST service you must provides at least 2 classes.
9191

92-
- A Component providing the business logic of your service,
93-
- A Controller to register your service.
92+
- A Component providing the business logic of your service,
93+
- A Controller to register your service.
9494

9595
The business logic of your service must be implemented into a component
9696
(``odoo.addons.component.core.Component``) that inherit from
@@ -99,22 +99,22 @@ The business logic of your service must be implemented into a component
9999
Initially, base_rest expose by default all public methods defined in a
100100
service. The conventions for accessing methods via HTTP were as follows:
101101

102-
- The method ``def get(self, _id)`` if defined, is accessible via HTTP
103-
GET routes ``<string:_service_name>/<int:_id>`` and
104-
``<string:_service_name>/<int:_id>/get``.
105-
- The method ``def search(self, **params)`` if defined, is accessible
106-
via the HTTP GET routes ``<string:_service_name>/`` and
107-
``<string:_service_name>/search``.
108-
- The method ``def delete(self, _id)`` if defined, is accessible via the
109-
HTTP DELETE route ``<string:_service_name>/<int:_id>``.
110-
- The ``def update(self, _id, **params)`` method, if defined, is
111-
accessible via the HTTP PUT route
112-
``<string:_service_name>/<int:_id>``.
113-
- Other methods are only accessible via HTTP POST routes
114-
``<string:_service_name>`` or
115-
``<string:_service_name>/<string:method_name>`` or
116-
``<string:_service_name>/<int:_id>`` or
117-
``<string:_service_name>/<int:_id>/<string:method_name>``
102+
- The method ``def get(self, _id)`` if defined, is accessible via HTTP
103+
GET routes ``<string:_service_name>/<int:_id>`` and
104+
``<string:_service_name>/<int:_id>/get``.
105+
- The method ``def search(self, **params)`` if defined, is accessible
106+
via the HTTP GET routes ``<string:_service_name>/`` and
107+
``<string:_service_name>/search``.
108+
- The method ``def delete(self, _id)`` if defined, is accessible via
109+
the HTTP DELETE route ``<string:_service_name>/<int:_id>``.
110+
- The ``def update(self, _id, **params)`` method, if defined, is
111+
accessible via the HTTP PUT route
112+
``<string:_service_name>/<int:_id>``.
113+
- Other methods are only accessible via HTTP POST routes
114+
``<string:_service_name>`` or
115+
``<string:_service_name>/<string:method_name>`` or
116+
``<string:_service_name>/<int:_id>`` or
117+
``<string:_service_name>/<int:_id>/<string:method_name>``
118118

119119
.. code:: python
120120
@@ -231,10 +231,10 @@ schemas <https://docs.python-cerberus.org/en/stable/>`__ and associated
231231
to the methods using the following naming convention. For a method
232232
\`my_method\`:
233233

234-
- ``def _validator_my_method(self):`` will be called to get the schema
235-
required to validate the input parameters.
236-
- ``def _validator_return_my_method(self):`` if defined, will be called
237-
to get the schema used to validate the response.
234+
- ``def _validator_my_method(self):`` will be called to get the schema
235+
required to validate the input parameters.
236+
- ``def _validator_return_my_method(self):`` if defined, will be called
237+
to get the schema used to validate the response.
238238

239239
In order to offer even more flexibility, a new API has been developed.
240240

@@ -363,32 +363,33 @@ Changelog
363363

364364
**Features**
365365

366-
- Add support for oauth2 security scheme in the Swagger UI. If your
367-
openapi specification contains a security scheme of type oauth2, the
368-
Swagger UI will display a login button in the top right corner. In
369-
order to finalize the login process, a redirect URL must be provided
370-
when initializing the Swagger UI. The Swagger UI is now initialized
371-
with a oauth2RedirectUrl option that references a oauth2-redirect.html
372-
file provided by the swagger-ui lib and served by the current addon.
373-
(`#379 <https://github.com/OCA/rest-framework/issues/379>`__)
366+
- Add support for oauth2 security scheme in the Swagger UI. If your
367+
openapi specification contains a security scheme of type oauth2, the
368+
Swagger UI will display a login button in the top right corner. In
369+
order to finalize the login process, a redirect URL must be provided
370+
when initializing the Swagger UI. The Swagger UI is now initialized
371+
with a oauth2RedirectUrl option that references a
372+
oauth2-redirect.html file provided by the swagger-ui lib and served
373+
by the current addon.
374+
(`#379 <https://github.com/OCA/rest-framework/issues/379>`__)
374375

375376
12.0.2.0.1
376377
----------
377378

378-
- validator\_...() methods can now return a cerberus ``Validator``
379-
object instead of a schema dictionnary, for additional flexibility
380-
(e.g. allowing validator options such as ``allow_unknown``).
379+
- validator\_...() methods can now return a cerberus ``Validator``
380+
object instead of a schema dictionnary, for additional flexibility
381+
(e.g. allowing validator options such as ``allow_unknown``).
381382

382383
12.0.2.0.0
383384
----------
384385

385-
- Licence changed from AGPL-3 to LGPL-3
386+
- Licence changed from AGPL-3 to LGPL-3
386387

387388
12.0.1.0.1
388389
----------
389390

390-
- Fix issue when rendering the jsonapi documentation if no documentation
391-
is provided on a method part of the REST api.
391+
- Fix issue when rendering the jsonapi documentation if no
392+
documentation is provided on a method part of the REST api.
392393

393394
12.0.1.0.0
394395
----------
@@ -404,7 +405,7 @@ Bug Tracker
404405
Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
405406
In case of trouble, please check there if your issue has already been reported.
406407
If you spotted it first, help us to smash it by providing a detailed and welcomed
407-
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
408+
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
408409

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

@@ -419,8 +420,8 @@ Authors
419420
Contributors
420421
------------
421422

422-
- Laurent Mignon <laurent.mignon@acsone.eu>
423-
- Sébastien Beau <sebastien.beau@akretion.com>
423+
- Laurent Mignon <laurent.mignon@acsone.eu>
424+
- Sébastien Beau <sebastien.beau@akretion.com>
424425

425426
Maintainers
426427
-----------
@@ -435,6 +436,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
435436
mission is to support the collaborative development of Odoo features and
436437
promote its widespread use.
437438

438-
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/base_rest>`_ project on GitHub.
439+
This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/19.0/base_rest>`_ project on GitHub.
439440

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

base_rest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from . import models
21
from . import components
2+
from . import models
33
from . import http

base_rest/__manifest__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"summary": """
77
Develop your own high level REST APIs for Odoo thanks to this addon.
88
""",
9-
"version": "18.0.1.1.1",
9+
"version": "19.0.1.0.0",
1010
"development_status": "Beta",
1111
"license": "LGPL-3",
12-
"author": "ACSONE SA/NV, " "Odoo Community Association (OCA)",
12+
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
1313
"maintainers": [],
1414
"website": "https://github.com/OCA/rest-framework",
1515
"depends": ["component", "web"],
@@ -33,5 +33,5 @@
3333
"apispec",
3434
]
3535
},
36-
"installable": False,
36+
"installable": True,
3737
}

base_rest/components/service.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ def _get_openapi_default_responses(self):
197197
return {
198198
"400": {"description": "One of the given parameter is not valid"},
199199
"401": {
200-
"description": "The user is not authorized. Authentication "
201-
"is required"
200+
"description": "The user is not authorized. Authentication is required"
202201
},
203202
"404": {"description": "Requested resource not found"},
204203
"403": {

base_rest/models/rest_service_registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def build_registry(self, services_registry, states=None, exclude_addons=None):
192192
graph = odoo.modules.graph.Graph()
193193
graph.add_module(self.env.cr, "base")
194194

195-
query = "SELECT name " "FROM ir_module_module " "WHERE state IN %s "
195+
query = "SELECT name FROM ir_module_module WHERE state IN %s "
196196
params = [tuple(states)]
197197
if exclude_addons:
198198
query += " AND name NOT IN %s "

base_rest/restapi.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,13 @@ def from_params(self, service, params):
218218
validator = self.get_cerberus_validator(service, "input")
219219
if validator.validate(params):
220220
return validator.document
221-
raise UserError(service.env._("BadRequest %s") % validator.errors)
221+
raise UserError(service.env._("BadRequest %s", validator.errors))
222222

223223
def to_response(self, service, result):
224224
validator = self.get_cerberus_validator(service, "output")
225225
if validator.validate(result):
226226
return validator.document
227-
raise SystemError(service.env._("Invalid Response %s") % validator.errors)
227+
raise SystemError(service.env._("Invalid Response %s", validator.errors))
228228

229229
def to_openapi_query_parameters(self, service, spec):
230230
json_schema = self.to_json_schema(service, spec, "input")
@@ -276,7 +276,7 @@ def get_cerberus_validator(self, service, direction):
276276
if isinstance(schema, dict):
277277
return Validator(schema, purge_unknown=True)
278278
raise Exception(
279-
service.env._("Unable to get cerberus schema from %s") % self._schema
279+
service.env._("Unable to get cerberus schema from %s", self._schema)
280280
)
281281

282282
def to_json_schema(self, service, spec, direction):
@@ -412,7 +412,11 @@ def from_params(self, service, params):
412412
) # multipart ony sends its parts as string
413413
except json.JSONDecodeError as error:
414414
raise ValidationError(
415-
service.env._(f"{key}'s JSON content is malformed: {error}")
415+
service.env._(
416+
"%(key)s's JSON content is malformed: %(error)s",
417+
key=key,
418+
error=error,
419+
)
416420
) from error
417421
param = part.from_params(service, json_param)
418422
params[key] = param

base_rest/static/description/index.html

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ <h1>Base Rest</h1>
374374
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375375
!! source digest: sha256:198b97806a0a8c480e6c8f26f3ce3199cba9978f8d152ecf93c80091323d1805
376376
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<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/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/18.0/base_rest"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest"><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/rest-framework&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
377+
<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/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/19.0/base_rest"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-19-0/rest-framework-19-0-base_rest"><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/rest-framework&amp;target_branch=19.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378378
<p>This addon is deprecated and not fully supported anymore from Odoo 16.
379379
Please migrate to the FastAPI migration module. See
380380
<a class="reference external" href="https://github.com/OCA/rest-framework/pull/291">https://github.com/OCA/rest-framework/pull/291</a>.</p>
@@ -454,8 +454,8 @@ <h2><a class="toc-backref" href="#toc-entry-2">Usage</a></h2>
454454
<li>The method <tt class="docutils literal">def search(self, **params)</tt> if defined, is accessible
455455
via the HTTP GET routes <tt class="docutils literal">&lt;string:_service_name&gt;/</tt> and
456456
<tt class="docutils literal"><span class="pre">&lt;string:_service_name&gt;/search</span></tt>.</li>
457-
<li>The method <tt class="docutils literal">def delete(self, _id)</tt> if defined, is accessible via the
458-
HTTP DELETE route <tt class="docutils literal"><span class="pre">&lt;string:_service_name&gt;/&lt;int:_id&gt;</span></tt>.</li>
457+
<li>The method <tt class="docutils literal">def delete(self, _id)</tt> if defined, is accessible via
458+
the HTTP DELETE route <tt class="docutils literal"><span class="pre">&lt;string:_service_name&gt;/&lt;int:_id&gt;</span></tt>.</li>
459459
<li>The <tt class="docutils literal">def update(self, _id, **params)</tt> method, if defined, is
460460
accessible via the HTTP PUT route
461461
<tt class="docutils literal"><span class="pre">&lt;string:_service_name&gt;/&lt;int:_id&gt;</span></tt>.</li>
@@ -701,8 +701,9 @@ <h3><a class="toc-backref" href="#toc-entry-5">16.0.1.0.2 (2023-10-07)</a></h3>
701701
Swagger UI will display a login button in the top right corner. In
702702
order to finalize the login process, a redirect URL must be provided
703703
when initializing the Swagger UI. The Swagger UI is now initialized
704-
with a oauth2RedirectUrl option that references a oauth2-redirect.html
705-
file provided by the swagger-ui lib and served by the current addon.
704+
with a oauth2RedirectUrl option that references a
705+
oauth2-redirect.html file provided by the swagger-ui lib and served
706+
by the current addon.
706707
(<a class="reference external" href="https://github.com/OCA/rest-framework/issues/379">#379</a>)</li>
707708
</ul>
708709
</div>
@@ -723,8 +724,8 @@ <h3><a class="toc-backref" href="#toc-entry-7">12.0.2.0.0</a></h3>
723724
<div class="section" id="section-4">
724725
<h3><a class="toc-backref" href="#toc-entry-8">12.0.1.0.1</a></h3>
725726
<ul class="simple">
726-
<li>Fix issue when rendering the jsonapi documentation if no documentation
727-
is provided on a method part of the REST api.</li>
727+
<li>Fix issue when rendering the jsonapi documentation if no
728+
documentation is provided on a method part of the REST api.</li>
728729
</ul>
729730
</div>
730731
<div class="section" id="section-5">
@@ -740,7 +741,7 @@ <h2><a class="toc-backref" href="#toc-entry-10">Bug Tracker</a></h2>
740741
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/rest-framework/issues">GitHub Issues</a>.
741742
In case of trouble, please check there if your issue has already been reported.
742743
If you spotted it first, help us to smash it by providing a detailed and welcomed
743-
<a class="reference external" href="https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
744+
<a class="reference external" href="https://github.com/OCA/rest-framework/issues/new?body=module:%20base_rest%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
744745
<p>Do not contact contributors directly about support or help with technical issues.</p>
745746
</div>
746747
<div class="section" id="credits">
@@ -767,7 +768,7 @@ <h3><a class="toc-backref" href="#toc-entry-14">Maintainers</a></h3>
767768
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
768769
mission is to support the collaborative development of Odoo features and
769770
promote its widespread use.</p>
770-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/rest-framework/tree/18.0/base_rest">OCA/rest-framework</a> project on GitHub.</p>
771+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/rest-framework/tree/19.0/base_rest">OCA/rest-framework</a> project on GitHub.</p>
771772
<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>
772773
</div>
773774
</div>

0 commit comments

Comments
 (0)