annotate libervia/backend/models/core.py @ 4165:81faa85c9cfa

template: add a `bare_jid` filter
author Goffi <goffi@goffi.org>
date Tue, 28 Nov 2023 17:41:49 +0100
parents 98687eaa6a09
children a1f7040b5a15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4162
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
35 class MessageEditData(MessageData):
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
36 """Data used when a new message edition has been received"""
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
37 pass
4149
c36295487082 core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff changeset
38
c36295487082 core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff changeset
39
c36295487082 core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff changeset
40 class MessageReactionData(MessageUpdateData):
c36295487082 core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff changeset
41 reactions: dict[str, list[str]] = Field(
c36295487082 core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff changeset
42 description="Reaction to reacting entities mapping"
c36295487082 core: introduce Pydantic based models in `libervia.backend.models.core`
Goffi <goffi@goffi.org>
parents:
diff changeset
43 )
4162
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
44
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
45
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
46 class MessageEdition(BaseModel):
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
47 """Data used to send a message edition"""
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
48 message: dict[str, str]
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
49 subject: dict[str, str] = Field(default_factory=dict)
98687eaa6a09 models (core): separate `MessageEditData` from `MessageEdition`:
Goffi <goffi@goffi.org>
parents: 4149
diff changeset
50 extra: dict[str, str] = Field(default_factory=dict)