Total Complexity | 0 |
Total Lines | 44 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding:utf-8 -*- |
||
2 | """ |
||
3 | KeySchema module |
||
4 | """ |
||
5 | |||
6 | from loglan_core import Key as BaseKey, Definition |
||
7 | from marshmallow_sqlalchemy.fields import Nested |
||
8 | |||
9 | from app.api.schemas import ma |
||
10 | |||
11 | |||
12 | # TODO from loglan_core.addons.addon_key_getter import AddonKeyGetter |
||
13 | |||
14 | |||
15 | class Key( |
||
16 | BaseKey, |
||
17 | ): # AddonKeyGetter |
||
18 | __tablename__ = BaseKey.__tablename__ |
||
19 | |||
20 | |||
21 | class KeySchema(ma.SQLAlchemyAutoSchema): |
||
22 | class Meta: |
||
23 | model = Key |
||
24 | include_fk = True |
||
25 | exclude = ("created", "updated", "_definitions") |
||
26 | |||
27 | _definitions = Nested( |
||
28 | "DefinitionSchema", |
||
29 | exclude=["word_id", "keys"], |
||
30 | many=True, |
||
31 | only={ |
||
32 | *Definition.attributes_basic(), |
||
33 | *Definition.relationships(), |
||
34 | "source_word", |
||
35 | }, |
||
36 | ) |
||
37 | definitions = _definitions |
||
38 | |||
39 | |||
40 | key_schema_nested = KeySchema(only=Key.attributes_basic()) |
||
41 | key_schema_full = KeySchema(only=(*Key.attributes_extended(), "definitions")) |
||
42 | |||
43 | blue_print_export = (Key, key_schema_nested, key_schema_full) |
||
44 |