schema.py 2.2 KB
Newer Older
François Ferry's avatar
François Ferry committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# -*- coding: utf-8 -*-
# copyright 2020 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr -- mailto:contact@logilab.fr
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

"""cubicweb-tuto schema"""
François Ferry's avatar
François Ferry committed
19
from yams.buildobjs import EntityType, String, Float, SubjectRelation, Int
20
from yams.constraints import BoundaryConstraint
21
22
23
from yams import MARKER


24
25
26
27
28
29
30
class EditorJsString(String):
    etype = "EditorJsString"

    def __init__(
        required: bool = False,
        formula=MARKER,
        override: bool = False,
31
        **kwargs,
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    ):
        super().__init__(required=required,
                         formula=formula,
                         override=override,
                         **kwargs)

# def EditorJsString(
#     required: bool = False,
#     formula=MARKER,
#     override: bool = False,
#     **kwargs,
# ):
#     return String(
#         required=required,
#         formula=formula,
#         override=override,
#         **kwargs,
#     )
François Ferry's avatar
François Ferry committed
50
51
52


class Museum(EntityType):
53
54
55
56
57
58
59
    name = String(required=True)
    latitude = Float(
        constraints=[BoundaryConstraint(">=", -90), BoundaryConstraint("<=", 90)]
    )
    longitude = Float(
        constraints=[BoundaryConstraint(">=", -180), BoundaryConstraint("<=", 180)]
    )
François Ferry's avatar
François Ferry committed
60
61
62
    is_in = SubjectRelation("City", cardinality="1*")
    director = SubjectRelation("Person", cardinality="**")
    postal_address = String()
63
    description = EditorJsString()
François Ferry's avatar
François Ferry committed
64
65
66


class City(EntityType):
67
    name = String(required=True)
François Ferry's avatar
François Ferry committed
68
    zip_code = Int()
69
    country = String(default="France")
François Ferry's avatar
François Ferry committed
70
71
72
73
74


class Person(EntityType):
    name = String()
    email = String()