Skip to content

Commit

Permalink
[IMP] fastapi: pre-commit auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cormaza committed Nov 8, 2024
1 parent dbd339a commit 7f2b580
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 54 deletions.
42 changes: 21 additions & 21 deletions fastapi/demo/fastapi_endpoint_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
<!-- Copyright 2022 ACSONE SA/NV
License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). -->
<odoo>
<!-- This is the user that will be used to run the demo app -->
<record
<!-- This is the user that will be used to run the demo app -->
<record
id="my_demo_app_user"
model="res.users"
context="{'no_reset_password': True, 'no_reset_password': True}"
>
<field name="name">My Demo Endpoint User</field>
<field name="login">my_demo_app_user</field>
<field name="groups_id" eval="[(6, 0, [])]" />
</record>
<field name="name">My Demo Endpoint User</field>
<field name="login">my_demo_app_user</field>
<field name="groups_id" eval="[(6, 0, [])]" />
</record>

<!-- This is the group that will be used to run the demo app
<!-- This is the group that will be used to run the demo app
This group will only depend on the "group_fastapi_endpoint_runner" group
that provides the minimal access rights to retrieve the user running the
endpoint handlers and performs authentication.
-->
<record id="my_demo_app_group" model="res.groups">
<field name="name">My Demo Endpoint Group</field>
<field name="users" eval="[(4, ref('my_demo_app_user'))]" />
<field name="implied_ids" eval="[(4, ref('group_fastapi_endpoint_runner'))]" />
</record>
<record id="my_demo_app_group" model="res.groups">
<field name="name">My Demo Endpoint Group</field>
<field name="users" eval="[(4, ref('my_demo_app_user'))]" />
<field name="implied_ids" eval="[(4, ref('group_fastapi_endpoint_runner'))]" />
</record>

<!-- This is the endpoint that will be used to run the demo app
<!-- This is the endpoint that will be used to run the demo app
This endpoint will be registered on the "/fastapi_demo" path
-->

<record model="fastapi.endpoint" id="fastapi_endpoint_demo">
<field name="name">Fastapi Demo Endpoint</field>
<field
<record model="fastapi.endpoint" id="fastapi_endpoint_demo">
<field name="name">Fastapi Demo Endpoint</field>
<field
name="description"
><![CDATA[
# A Dummy FastApi Demo
Expand All @@ -39,9 +39,9 @@ This demo endpoint has been created by inhering from "fastapi.endpoint", registe
a new app into the app selection field and implementing the `_get_fastapi_routers`
methods. See documentation to learn more about how to create a new app.
]]></field>
<field name="app">demo</field>
<field name="root_path">/fastapi_demo</field>
<field name="demo_auth_method">http_basic</field>
<field name="user_id" ref="my_demo_app_user" />
</record>
<field name="app">demo</field>
<field name="root_path">/fastapi_demo</field>
<field name="demo_auth_method">http_basic</field>
<field name="user_id" ref="my_demo_app_user" />
</record>
</odoo>
2 changes: 1 addition & 1 deletion fastapi/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def optionally_authenticated_partner_impl() -> Partner | None:


def authenticated_partner_env(
partner: Annotated[Partner, Depends(authenticated_partner_impl)]
partner: Annotated[Partner, Depends(authenticated_partner_impl)],
) -> Environment:
"""Return an environment with the authenticated partner id in the context"""
return partner.with_context(authenticated_partner_id=partner.id).env
Expand Down
6 changes: 3 additions & 3 deletions fastapi/models/fastapi_endpoint_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def _get_app(self):
authenticated_partner_impl_override = (
api_key_based_authenticated_partner_impl
)
app.dependency_overrides[
authenticated_partner_impl
] = authenticated_partner_impl_override
app.dependency_overrides[authenticated_partner_impl] = (
authenticated_partner_impl_override
)
return app

def _prepare_fastapi_app_params(self) -> dict[str, Any]:
Expand Down
3 changes: 2 additions & 1 deletion fastapi/routers/demo_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
The demo router is a router that demonstrates how to use the fastapi
integration with odoo.
"""

from typing import Annotated

from psycopg2 import errorcodes
Expand Down Expand Up @@ -66,7 +67,7 @@ async def get_lang(env: Annotated[Environment, Depends(odoo_env)]):

@router.get("/demo/who_ami")
async def who_ami(
partner: Annotated[Partner, Depends(authenticated_partner)]
partner: Annotated[Partner, Depends(authenticated_partner)],
) -> DemoUserInfo:
"""Who am I?
Expand Down
1 change: 0 additions & 1 deletion fastapi/security/fastapi_endpoint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<!-- Copyright 2022 ACSONE SA/NV
License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). -->
<odoo>

<record model="ir.model.access" id="fastapi_endpoint_access_view">
<field name="name">fastapi.endpoint view</field>
<field name="model_id" ref="model_fastapi_endpoint" />
Expand Down
1 change: 0 additions & 1 deletion fastapi/security/ir_rule+acl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,4 @@
<field name="domain_force"> [('user_id', '=', user.id)]</field>
<field name="groups" eval="[(4, ref('group_fastapi_endpoint_runner'))]" />
</record>

</odoo>
37 changes: 18 additions & 19 deletions fastapi/views/fastapi_endpoint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
<!-- Copyright 2022 ACSONE SA/NV
License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). -->
<odoo>

<record model="ir.ui.view" id="fastapi_endpoint_form_view">
<field name="name">fastapi.endpoint.form (in fastapi)</field>
<field name="model">fastapi.endpoint</field>
<field name="arch" type="xml">
<form>
<header>
</header>
<header />
<sheet>
<field name="active" invisible="1" />
<field name="registry_sync" invisible="1" />
Expand Down Expand Up @@ -37,22 +35,24 @@
/>
<div class="oe_title">
<label for="name" />
<h1><field name="name" /></h1>
<h1>
<field name="name" />
</h1>
</div>
<group>
<group>
<field name="app" />
<field name="root_path" />
<field name="user_id" />
<field name="company_id" />
<field name="description" />
<field name="save_http_session" />
</group>
<group name="resoures">
<field name="docs_url" widget="url" />
<field name="redoc_url" widget="url" />
<field name="openapi_url" widget="url" />
</group>
<group>
<field name="app" />
<field name="root_path" />
<field name="user_id" />
<field name="company_id" />
<field name="description" />
<field name="save_http_session" />
</group>
<group name="resoures">
<field name="docs_url" widget="url" />
<field name="redoc_url" widget="url" />
<field name="openapi_url" widget="url" />
</group>
</group>
<span name="configuration" />
</sheet>
Expand All @@ -73,7 +73,7 @@
domain="[('active','=',False)]"
/>
<group expand='0' string='Group by...'>
<filter
<filter
string='App'
name="groupby_app"
context="{'group_by': 'app'}"
Expand Down Expand Up @@ -133,5 +133,4 @@
<field name="action" ref="fastapi_endpoint_act_window" />
<field name="sequence" eval="16" />
</record>

</odoo>
12 changes: 5 additions & 7 deletions fastapi/views/fastapi_endpoint_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@
<!-- Copyright 2022 ACSONE SA/NV
License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). -->
<odoo>

<record model="ir.ui.view" id="fastapi_endpoint_demo_form_view">
<field name="name">fastapi.endpoint.demo.form (in fastapi)</field>
<field name="model">fastapi.endpoint</field>
<field name="inherit_id" ref="fastapi_endpoint_form_view" />
<field name="arch" type="xml">
<span name="configuration" position="after">
<group
<span name="configuration" position="after">
<group
name="demo_app_configuration"
title="Configuration"
invisible="app != 'demo'"
>
<field name="demo_auth_method" />
</group>
</span>
<field name="demo_auth_method" />
</group>
</span>
</field>
</record>

</odoo>
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# generated from manifests external_dependencies
a2wsgi>=1.10.6
fastapi>=0.110.0
parse-accept-language
python-multipart
ujson

0 comments on commit 7f2b580

Please sign in to comment.