Mercurial > libervia-backend
annotate libervia/backend/models/core.py @ 4239:a38559e6d6e2
core: remove legacy VERSION file.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 11 May 2024 13:25:45 +0200 |
parents | a1f7040b5a15 |
children | 0d7bb4df2343 |
rev | line source |
---|---|
4149
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia common models |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2023 Jérôme Poisson (goffi@goffi.org) |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
4162
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
19 from pydantic import BaseModel, Field |
4149
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 class MessageData(dict): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 pass |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 class MessageUpdateData(BaseModel): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 type: str |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 def __init__(self, **kwargs): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 if "type" not in kwargs: |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 kwargs["type"] = "reactions" |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 super().__init__(**kwargs) |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 class MessageReactionData(MessageUpdateData): |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 reactions: dict[str, list[str]] = Field( |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 description="Reaction to reacting entities mapping" |
c36295487082
core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 ) |
4162
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
39 |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
40 |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
41 class MessageEdition(BaseModel): |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
42 """Data used to send a message edition""" |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
43 message: dict[str, str] |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
44 subject: dict[str, str] = Field(default_factory=dict) |
98687eaa6a09
models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents:
4149
diff
changeset
|
45 extra: dict[str, str] = Field(default_factory=dict) |