nsarchive 3.0.0a7__py3-none-any.whl → 3.0.0b1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nsarchive/__init__.py +17 -10
- nsarchive/{instances → interfaces}/_economy.py +15 -30
- nsarchive/interfaces/_entities.py +206 -0
- nsarchive/interfaces/_justice.py +122 -0
- nsarchive/interfaces/_state.py +196 -0
- nsarchive/mandate.py +50 -0
- nsarchive/{cls → models}/base.py +28 -7
- nsarchive/{cls → models}/economy.py +34 -14
- nsarchive/{cls → models}/entities.py +143 -77
- nsarchive/models/justice.py +108 -0
- nsarchive/models/republic.py +128 -0
- nsarchive/models/scale.py +23 -0
- nsarchive/models/state.py +75 -0
- {nsarchive-3.0.0a7.dist-info → nsarchive-3.0.0b1.dist-info}/METADATA +3 -2
- nsarchive-3.0.0b1.dist-info/RECORD +19 -0
- {nsarchive-3.0.0a7.dist-info → nsarchive-3.0.0b1.dist-info}/WHEEL +1 -1
- nsarchive/cls/archives.py +0 -93
- nsarchive/cls/republic.py +0 -149
- nsarchive/instances/_entities.py +0 -281
- nsarchive/instances/_republic.py +0 -339
- nsarchive-3.0.0a7.dist-info/RECORD +0 -15
- {nsarchive-3.0.0a7.dist-info → nsarchive-3.0.0b1.dist-info}/LICENSE +0 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import requests
|
4
|
+
|
5
|
+
from .base import NSID
|
6
|
+
from .republic import Vote
|
7
|
+
|
8
|
+
class Party:
|
9
|
+
def __init__(self, org_id: NSID):
|
10
|
+
self._url: str = ''
|
11
|
+
self._headers: dict = {}
|
12
|
+
|
13
|
+
self.org_id = org_id
|
14
|
+
|
15
|
+
self.color: int = 0x000000
|
16
|
+
self.motto: str = None
|
17
|
+
self.scale: dict = {}
|
18
|
+
self.last_election: int = None
|
19
|
+
|
20
|
+
def _load(self, _data: dict, url: str = None, headers: dict = None):
|
21
|
+
self._url = url
|
22
|
+
self._headers = headers
|
23
|
+
|
24
|
+
self.org_id = _data['org_id']
|
25
|
+
|
26
|
+
self.color = _data['color']
|
27
|
+
self.motto = _data['motto']
|
28
|
+
self.scale = _data['politiscales']
|
29
|
+
self.last_election = _data['last_election']
|
30
|
+
|
31
|
+
def cancel_candidacy(self, election: Election):
|
32
|
+
election.cancel_candidacy()
|
33
|
+
|
34
|
+
class Election:
|
35
|
+
def __init__(self, id: NSID):
|
36
|
+
self._url: str = ''
|
37
|
+
self._headers: dict = {}
|
38
|
+
|
39
|
+
self.id = id
|
40
|
+
self.type: str = 'full' # Partial = législatives, full = totales
|
41
|
+
self.vote: Vote = None
|
42
|
+
|
43
|
+
def _load(self, _data: dict, url: str = None, headers: str = None):
|
44
|
+
self._url = url
|
45
|
+
self._headers = headers
|
46
|
+
|
47
|
+
self.id = _data['id']
|
48
|
+
self.type = _data['type']
|
49
|
+
|
50
|
+
self.vote = Vote(_data['vote']['id'])
|
51
|
+
self.vote._load(_data['vote'], url, headers)
|
52
|
+
|
53
|
+
def close(self):
|
54
|
+
if self.vote:
|
55
|
+
self.vote.close()
|
56
|
+
else:
|
57
|
+
return
|
58
|
+
|
59
|
+
def add_vote(self, id: str):
|
60
|
+
if self.vote:
|
61
|
+
self.vote.add_vote(id)
|
62
|
+
else:
|
63
|
+
return
|
64
|
+
|
65
|
+
def submit_candidacy(self):
|
66
|
+
res = requests.put(f"{self._url}/submit")
|
67
|
+
|
68
|
+
if res.status_code != 200:
|
69
|
+
res.raise_for_status()
|
70
|
+
|
71
|
+
def cancel_candidacy(self):
|
72
|
+
res = requests.put(f"{self._url}/cancel_candidacy")
|
73
|
+
|
74
|
+
if res.status_code != 200:
|
75
|
+
res.raise_for_status()
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: nsarchive
|
3
|
-
Version: 3.0.
|
3
|
+
Version: 3.0.0b1
|
4
4
|
Summary: API-wrapper pour récupérer des données liées à Nation
|
5
5
|
License: GPL-3.0
|
6
6
|
Author: happex
|
@@ -11,6 +11,7 @@ Classifier: Programming Language :: Python :: 3
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.10
|
12
12
|
Classifier: Programming Language :: Python :: 3.11
|
13
13
|
Classifier: Programming Language :: Python :: 3.12
|
14
|
+
Classifier: Programming Language :: Python :: 3.13
|
14
15
|
Requires-Dist: pillow (>=10.4,<11.0)
|
15
16
|
Requires-Dist: requests (>=2.31,<3.0)
|
16
17
|
Description-Content-Type: text/markdown
|
@@ -0,0 +1,19 @@
|
|
1
|
+
nsarchive/__init__.py,sha256=Sh9eQ1alsA-fnFr3AHeMEQ5PZ1r4h_XtCBii3FlkUDs,853
|
2
|
+
nsarchive/assets/default_avatar.png,sha256=n-4vG_WPke8LvbY3ZU6oA-H-OtRoIu7woKnRq9DCIlI,51764
|
3
|
+
nsarchive/interfaces/_economy.py,sha256=54TpYKRw07HIryd3EDifA9Hs3s6O7aHcrtV4P8qY0QY,9348
|
4
|
+
nsarchive/interfaces/_entities.py,sha256=9iSw_AAMmdh7VY8BgQkRoZ0RIMsi7ZYYLB3_PJXMbOU,6399
|
5
|
+
nsarchive/interfaces/_justice.py,sha256=AOuPLgja1D1_MU6oll5JOdb0yjLknd7QIdxyStDNhBM,3708
|
6
|
+
nsarchive/interfaces/_state.py,sha256=7cGYnkjUXLnkGnZiYNfhq4QraZ_lqMXdlBriV-SUQng,5515
|
7
|
+
nsarchive/mandate.py,sha256=U0RE9Gpr3XawSWyr99X__GUoiwJAwKbOP4v_I2Z97Oc,1609
|
8
|
+
nsarchive/models/base.py,sha256=UBpM4B1nOPJCPJmPAkbumGYxGxBtQUY7omh8uEczsCc,8763
|
9
|
+
nsarchive/models/economy.py,sha256=GD1G2fOyIZxquC7F6Rawy0V1gmXN0keTh-r4xvcGl6Y,7681
|
10
|
+
nsarchive/models/entities.py,sha256=UP3jFS-KDIER8-K1EVdjgCge7qeCtJ3106XBNrhDKLE,17429
|
11
|
+
nsarchive/models/justice.py,sha256=RuFmPi6mK-8APc-_WSPz4bYfnC46WYwdEnzGsZcdXDw,3420
|
12
|
+
nsarchive/models/republic.py,sha256=hZA9XB-jHQjscBzuk7vfB_CjtU2Yb8AFM3TxFM6RF5k,3260
|
13
|
+
nsarchive/models/scale.py,sha256=ukh6wiE4mBcqbqtAC9GvCyTVUnwYUp3jla03Nohnsck,751
|
14
|
+
nsarchive/models/state.py,sha256=gxxUu-E6t2tEx70vXT5XQ17JppP2JKpk4MWclWoqUSM,1963
|
15
|
+
nsarchive/utils.py,sha256=L37Dm8aO0Sm3FDLPf2tP6fo-1lodDq7JIz-WXttNuJg,684
|
16
|
+
nsarchive-3.0.0b1.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
|
17
|
+
nsarchive-3.0.0b1.dist-info/METADATA,sha256=gQ9hFbAZ6cf_xXRJnx1h36io5qfafhGJ1s6lH4zng6c,746
|
18
|
+
nsarchive-3.0.0b1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
19
|
+
nsarchive-3.0.0b1.dist-info/RECORD,,
|
nsarchive/cls/archives.py
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
import time
|
2
|
-
|
3
|
-
from .base import *
|
4
|
-
|
5
|
-
class Archive:
|
6
|
-
def __init__(self, author: NSID = '0', target: NSID = '0'):
|
7
|
-
"""
|
8
|
-
Classe de référence pour toutes les archives.
|
9
|
-
|
10
|
-
## Attributs de base
|
11
|
-
- date: `int`\n
|
12
|
-
Date (timestamp) de l'exécution de l'archive
|
13
|
-
- id: `NSID`\n
|
14
|
-
Clé d'identification des archives (basée sur la date)
|
15
|
-
- author: `NSID`\n
|
16
|
-
ID de l'auteur de l'action
|
17
|
-
- target: `NSID`:
|
18
|
-
ID de la cible de l'action
|
19
|
-
- action: `str`:\n
|
20
|
-
Action effectuée
|
21
|
-
- details: `dict`\n
|
22
|
-
Ensemble de détails que les différents bots peuvent utiliser
|
23
|
-
"""
|
24
|
-
self.date: int = round(time.time())
|
25
|
-
|
26
|
-
self.id: NSID = NSID(self.date)
|
27
|
-
self.author: NSID = NSID(author)
|
28
|
-
self.target: NSID = NSID(target)
|
29
|
-
|
30
|
-
self.action: str = ""
|
31
|
-
self.details: dict = {
|
32
|
-
"reason": None
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
# Entities
|
37
|
-
|
38
|
-
class Sanction(Archive):
|
39
|
-
def __init__(self, author: NSID, target: NSID) -> None:
|
40
|
-
super().__init__(author, target)
|
41
|
-
|
42
|
-
self.details: dict = {
|
43
|
-
"reason": None,
|
44
|
-
"major": False, # Sanction majeure ou non
|
45
|
-
"duration": 0 # Durée en secondes , 0 = définitif
|
46
|
-
}
|
47
|
-
|
48
|
-
class Report(Archive):
|
49
|
-
def __init__(self, author: NSID, target: NSID) -> None:
|
50
|
-
super().__init__(author, target)
|
51
|
-
|
52
|
-
self.details: dict = {
|
53
|
-
"reason": None,
|
54
|
-
"elements": [] # Liste des pièces jointes
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
# Community
|
59
|
-
|
60
|
-
class Election(Archive):
|
61
|
-
def __init__(self, author: NSID, target: NSID, position: str) -> None:
|
62
|
-
super().__init__(author, target)
|
63
|
-
|
64
|
-
self.details = {
|
65
|
-
"position": position,
|
66
|
-
"positive_votes": 0,
|
67
|
-
"total_votes": 0
|
68
|
-
}
|
69
|
-
|
70
|
-
class Promotion(Archive):
|
71
|
-
def __init__(self, author: NSID, target: NSID, position: str) -> None:
|
72
|
-
super().__init__(author, target)
|
73
|
-
|
74
|
-
self.details = {
|
75
|
-
"position": position
|
76
|
-
}
|
77
|
-
|
78
|
-
class Demotion(Archive):
|
79
|
-
def __init__(self, author: NSID, target: NSID) -> None:
|
80
|
-
super().__init__(author, target)
|
81
|
-
|
82
|
-
|
83
|
-
# Bank
|
84
|
-
|
85
|
-
class Transaction(Archive):
|
86
|
-
def __init__(self, author: NSID, target: NSID) -> None:
|
87
|
-
super().__init__(author, target)
|
88
|
-
|
89
|
-
self.details = {
|
90
|
-
"amount": 0,
|
91
|
-
"currency": "HC",
|
92
|
-
"reason": None
|
93
|
-
}
|
nsarchive/cls/republic.py
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
from nsarchive.cls.base import NSID
|
2
|
-
|
3
|
-
# Votes
|
4
|
-
|
5
|
-
class VoteOption:
|
6
|
-
"""
|
7
|
-
Option disponible lors d'un vote
|
8
|
-
|
9
|
-
## Attributs
|
10
|
-
- id: `str`\n
|
11
|
-
Identifiant de l'option
|
12
|
-
- title: `str`\n
|
13
|
-
Label de l'option
|
14
|
-
- count: `int`\n
|
15
|
-
Nombre de sympathisants pour cette option
|
16
|
-
"""
|
17
|
-
|
18
|
-
def __init__(self, id: str, title: str = None, count: int = 0):
|
19
|
-
self.id = id
|
20
|
-
self.title = title if title else id
|
21
|
-
self.count = count
|
22
|
-
|
23
|
-
class Vote:
|
24
|
-
"""
|
25
|
-
Classe de référence pour les différents votes du serveur
|
26
|
-
|
27
|
-
## Attributs
|
28
|
-
- id: `NSID`\n
|
29
|
-
Identifiant du vote
|
30
|
-
- title: `str`\n
|
31
|
-
Titre du vote
|
32
|
-
- choices: list[.VoteOption]\n
|
33
|
-
Liste des choix disponibles
|
34
|
-
- author: `NSID`\n
|
35
|
-
Identifiant de l'auteur du vote
|
36
|
-
- startDate: `int`\n
|
37
|
-
Date de début du vote
|
38
|
-
- endDate: `int`\n
|
39
|
-
Date limite pour voter
|
40
|
-
"""
|
41
|
-
|
42
|
-
def __init__(self, id: NSID, title: str) -> None:
|
43
|
-
self.id: NSID = NSID(id)
|
44
|
-
self.title: str = title
|
45
|
-
self.choices: list[VoteOption] = []
|
46
|
-
self.author: NSID = NSID("0")
|
47
|
-
self.startDate: int = 0
|
48
|
-
self.endDate: int = 0
|
49
|
-
|
50
|
-
def by_id(self, id: str) -> VoteOption:
|
51
|
-
for opt in self.choices:
|
52
|
-
if opt.id == id:
|
53
|
-
return opt
|
54
|
-
|
55
|
-
def sorted(self, titles_only: bool = False) -> list[VoteOption] | list[str]:
|
56
|
-
sorted_list: list[VoteOption] = sorted(self.choices, lambda opt : opt.count)
|
57
|
-
|
58
|
-
if titles_only:
|
59
|
-
return [ opt.id for opt in sorted_list ]
|
60
|
-
else:
|
61
|
-
return sorted_list
|
62
|
-
|
63
|
-
class Referendum(Vote):
|
64
|
-
"""
|
65
|
-
Vote à trois positions
|
66
|
-
"""
|
67
|
-
|
68
|
-
def __init__(self, id: NSID, title: str) -> None:
|
69
|
-
super().__init__(id, title)
|
70
|
-
|
71
|
-
self.choices = [
|
72
|
-
VoteOption('yes', 'Oui'),
|
73
|
-
VoteOption('no', 'Non'),
|
74
|
-
VoteOption('blank', 'Pas d\'avis'),
|
75
|
-
]
|
76
|
-
|
77
|
-
class Lawsuit(Vote):
|
78
|
-
"""
|
79
|
-
Vote à trois positions pour un procès
|
80
|
-
"""
|
81
|
-
|
82
|
-
def __init__(self, id: NSID, title: str) -> None:
|
83
|
-
super().__init__(id, title)
|
84
|
-
|
85
|
-
self.choices = [
|
86
|
-
VoteOption('guilty', 'Coupable'),
|
87
|
-
VoteOption('innocent', 'Innocent'),
|
88
|
-
VoteOption('blank', 'Pas d\'avis'),
|
89
|
-
]
|
90
|
-
|
91
|
-
|
92
|
-
# Institutions (defs)
|
93
|
-
|
94
|
-
class Official:
|
95
|
-
def __init__(self, id: NSID) -> None:
|
96
|
-
self.id: NSID = NSID(id)
|
97
|
-
|
98
|
-
self.mandates: int = {
|
99
|
-
'PRE_REP': 0, # Président de la République
|
100
|
-
'MIN': 0, # Différents ministres
|
101
|
-
'PRE_AS': 0, # Président de l'Assemblée Nationale
|
102
|
-
'REPR': 0 # Député
|
103
|
-
}
|
104
|
-
|
105
|
-
self.contributions: dict = {
|
106
|
-
'propose_project': 0,
|
107
|
-
'success_project': 0,
|
108
|
-
'vote_law': 0
|
109
|
-
}
|
110
|
-
|
111
|
-
class Administration:
|
112
|
-
def __init__(self) -> None:
|
113
|
-
self.president: Official
|
114
|
-
self.members: list[Official] = []
|
115
|
-
|
116
|
-
class Government:
|
117
|
-
def __init__(self, president: Official) -> None:
|
118
|
-
self.president: Official = president
|
119
|
-
self.prime_minister: Official
|
120
|
-
|
121
|
-
self.inner_minister: Official
|
122
|
-
self.economy_minister: Official
|
123
|
-
self.justice_minister: Official
|
124
|
-
self.press_minister: Official
|
125
|
-
self.outer_minister: Official
|
126
|
-
|
127
|
-
class Court:
|
128
|
-
def __init__(self) -> None:
|
129
|
-
self.president: Official
|
130
|
-
# On discutera de la mise en place d'un potentiel président. Pour l'instant c'est le Ministre de la Justice
|
131
|
-
self.members: list[Official] = []
|
132
|
-
|
133
|
-
class Assembly:
|
134
|
-
def __init__(self) -> None:
|
135
|
-
self.president: Official
|
136
|
-
self.members: list[Official] = []
|
137
|
-
|
138
|
-
class PoliceForces:
|
139
|
-
def __init__(self) -> None:
|
140
|
-
self.president: Official
|
141
|
-
self.members: list[Official] = []
|
142
|
-
|
143
|
-
class State:
|
144
|
-
def __init__(self) -> None:
|
145
|
-
self.administration: Administration
|
146
|
-
self.government: Government
|
147
|
-
self.court: Court
|
148
|
-
self.assembly: Assembly
|
149
|
-
self.police: PoliceForces
|
nsarchive/instances/_entities.py
DELETED
@@ -1,281 +0,0 @@
|
|
1
|
-
from ..cls.base import *
|
2
|
-
from ..cls.entities import *
|
3
|
-
|
4
|
-
from ..cls import entities # Pour les default_headers
|
5
|
-
|
6
|
-
class EntityInstance(Instance):
|
7
|
-
"""
|
8
|
-
Instance qui vous permettra d'interagir avec les profils des membres ainsi que les différents métiers et secteurs d'activité.
|
9
|
-
|
10
|
-
## Informations disponibles
|
11
|
-
- Profil des membres et des entreprises: `.User | .Organization | .Entity`
|
12
|
-
- Participation d'un membre à différent votes: `.User | .Organization | .Entity`
|
13
|
-
- Appartenance et permissions d'un membre dans un groupe: `.GroupMember.MemberPermissions`
|
14
|
-
- Position légale et permissions d'une entité: `.Position.Permissions`
|
15
|
-
- Sanctions et modifications d'une entité: `.Action[ .AdminAction | .Sanction ]`
|
16
|
-
"""
|
17
|
-
|
18
|
-
def __init__(self, url: str, token: str = None) -> None:
|
19
|
-
super().__init__(url, token)
|
20
|
-
|
21
|
-
entities.default_headers = self.default_headers
|
22
|
-
|
23
|
-
"""
|
24
|
-
---- ENTITÉS ----
|
25
|
-
"""
|
26
|
-
|
27
|
-
def get_entity(self, id: NSID, _class: str = None) -> User | Organization | Entity:
|
28
|
-
"""
|
29
|
-
Fonction permettant de récupérer le profil public d'une entité.\n
|
30
|
-
|
31
|
-
## Paramètres
|
32
|
-
id: `NSID`
|
33
|
-
ID héxadécimal de l'entité à récupérer
|
34
|
-
_class: `str`
|
35
|
-
Classe du modèle à prendre (`.User` ou `.Organization`)
|
36
|
-
|
37
|
-
## Renvoie
|
38
|
-
- `.User` dans le cas où l'entité choisie est un membre
|
39
|
-
- `.Organization` dans le cas où c'est un groupe
|
40
|
-
- `.Entity` dans le cas où c'est indéterminé
|
41
|
-
"""
|
42
|
-
|
43
|
-
id = NSID(id)
|
44
|
-
|
45
|
-
if _class == "user":
|
46
|
-
_data = self._get_by_ID('individuals', id)
|
47
|
-
elif _class == "group":
|
48
|
-
_data = self._get_by_ID('organizations', id)
|
49
|
-
else:
|
50
|
-
_data = self._get_by_ID('entities', id)
|
51
|
-
|
52
|
-
if _data is None: # ID inexistant chez les entités
|
53
|
-
return None
|
54
|
-
|
55
|
-
if _data['_class'] == 'individuals':
|
56
|
-
entity = User(id)
|
57
|
-
entity._url = f"{self.url}/model/individuals/{id}"
|
58
|
-
|
59
|
-
entity._load(_data)
|
60
|
-
elif _data['_class'] == 'organizations':
|
61
|
-
entity = Organization(id)
|
62
|
-
entity._url = f"{self.url}/model/organizations/{id}"
|
63
|
-
|
64
|
-
_owner = _data['owner']
|
65
|
-
|
66
|
-
if _owner['_class'] == 'individuals':
|
67
|
-
entity.owner = User(_owner['id'])
|
68
|
-
entity.owner._load(_owner)
|
69
|
-
elif _owner['class'] == 'organizations':
|
70
|
-
entity.owner = Organization(_owner['id'])
|
71
|
-
entity.owner._load(_owner)
|
72
|
-
else:
|
73
|
-
entity.owner = self.get_entity(0x0)
|
74
|
-
|
75
|
-
entity._load(_data)
|
76
|
-
else:
|
77
|
-
entity = Entity(id)
|
78
|
-
entity._url = f"{self.url}/model/entities/{id}"
|
79
|
-
|
80
|
-
entity.name = _data['name']
|
81
|
-
entity.position._load(_data['position']) # Métier si c'est un utilisateur, domaine professionnel si c'est un collectif
|
82
|
-
entity.registerDate = _data['register_date']
|
83
|
-
|
84
|
-
for key, value in _data.get('additional', {}).items():
|
85
|
-
if isinstance(value, str) and value.startswith('\n'):
|
86
|
-
entity.additional[key] = int(value[1:])
|
87
|
-
else:
|
88
|
-
entity.additional[key] = value
|
89
|
-
|
90
|
-
entity.position._url = f"{self.url}/positions/{id}"
|
91
|
-
|
92
|
-
return entity
|
93
|
-
|
94
|
-
def get_entity_groups(self, entity: User) -> list[Organization]:
|
95
|
-
res = requests.get(f"{entity._url}/groups", headers = self.default_headers)
|
96
|
-
|
97
|
-
if res.status_code == 200:
|
98
|
-
data = res.json()
|
99
|
-
groups = []
|
100
|
-
|
101
|
-
for grp in data:
|
102
|
-
if grp is None: continue
|
103
|
-
|
104
|
-
group = Organization(grp["id"])
|
105
|
-
group._url = f"{self.url}/model/organizations/{grp['id']}"
|
106
|
-
|
107
|
-
group._load(grp)
|
108
|
-
|
109
|
-
groups.append(group)
|
110
|
-
|
111
|
-
return groups
|
112
|
-
else:
|
113
|
-
res.raise_for_status()
|
114
|
-
return []
|
115
|
-
|
116
|
-
def save_entity(self, entity: Entity):
|
117
|
-
"""
|
118
|
-
Fonction permettant de créer ou modifier une entité.
|
119
|
-
|
120
|
-
## Paramètres
|
121
|
-
entity: `.Entity`\n
|
122
|
-
L'entité à sauvegarder
|
123
|
-
"""
|
124
|
-
|
125
|
-
entity.id = NSID(entity.id)
|
126
|
-
|
127
|
-
_data = {
|
128
|
-
'id': entity.id,
|
129
|
-
'name': entity.name,
|
130
|
-
'position': entity.position.id,
|
131
|
-
'register_date': entity.registerDate,
|
132
|
-
'additional': {},
|
133
|
-
}
|
134
|
-
|
135
|
-
for key, value in entity.additional.items():
|
136
|
-
if isinstance(value, int) and len(str(int)) >= 15:
|
137
|
-
_data['additional'][key] = '\n' + str(value)
|
138
|
-
elif type(value) in (str, int):
|
139
|
-
_data['additional'][key] = value
|
140
|
-
|
141
|
-
if type(entity) == Organization:
|
142
|
-
_data['owner_id'] = NSID(entity.owner.id) if entity.owner else NSID("0")
|
143
|
-
_data['members'] = []
|
144
|
-
_data['certifications'] = entity.certifications
|
145
|
-
|
146
|
-
for member in entity.members:
|
147
|
-
_member = {
|
148
|
-
'id': NSID(member.id),
|
149
|
-
'level': member.permission_level
|
150
|
-
}
|
151
|
-
|
152
|
-
_data['members'] += [_member]
|
153
|
-
|
154
|
-
entity.save_avatar()
|
155
|
-
elif type(entity) == User:
|
156
|
-
_data['xp'] = entity.xp
|
157
|
-
_data['boosts'] = entity.boosts
|
158
|
-
_data['votes'] = [ NSID(vote) for vote in entity.votes]
|
159
|
-
else:
|
160
|
-
return
|
161
|
-
|
162
|
-
self._put_in_db(
|
163
|
-
f"/new_model/{'individuals' if isinstance(entity, User) else 'organizations'}?id={urllib.parse.quote(entity.id)}&name={urllib.parse.quote(entity.name)}",
|
164
|
-
_data,
|
165
|
-
headers = self.default_headers,
|
166
|
-
use_PUT = True
|
167
|
-
)
|
168
|
-
|
169
|
-
entity._url = f"{self.url}/model/{'individuals' if isinstance(entity, User) else 'organizations'}/{entity.id}"
|
170
|
-
|
171
|
-
|
172
|
-
def delete_entity(self, entity: Entity):
|
173
|
-
"""
|
174
|
-
Fonction permettant de supprimer le profil d'une entité
|
175
|
-
|
176
|
-
## Paramètres
|
177
|
-
entity: `.Entity`\n
|
178
|
-
L'entité à supprimer
|
179
|
-
"""
|
180
|
-
|
181
|
-
res = requests.post(f"{entity._url}/delete", headers = self.default_headers,)
|
182
|
-
|
183
|
-
if res.status_code != 200:
|
184
|
-
res.raise_for_status()
|
185
|
-
|
186
|
-
def fetch_entities(self, **query: typing.Any) -> list[ Entity | User | Organization ]:
|
187
|
-
"""
|
188
|
-
Récupère une liste d'entités en fonction d'une requête.
|
189
|
-
|
190
|
-
## Paramètres
|
191
|
-
query: `**dict`\n
|
192
|
-
La requête pour filtrer les entités.
|
193
|
-
|
194
|
-
## Renvoie
|
195
|
-
- `list[.Entity | .User | .Organization]`
|
196
|
-
"""
|
197
|
-
|
198
|
-
if "_class" in query.keys():
|
199
|
-
if query["_class"] == "individuals":
|
200
|
-
del query["_class"]
|
201
|
-
_res = self.fetch('individuals', **query)
|
202
|
-
elif query["_class"] == "organizations":
|
203
|
-
del query["_class"]
|
204
|
-
_res = self.fetch('organizations', **query)
|
205
|
-
else:
|
206
|
-
del query["_class"]
|
207
|
-
_res = self.fetch('entities', **query)
|
208
|
-
else:
|
209
|
-
_res = self.fetch('entities', **query)
|
210
|
-
|
211
|
-
res = []
|
212
|
-
|
213
|
-
for _entity in _res:
|
214
|
-
if _entity is None: continue
|
215
|
-
|
216
|
-
if _entity['_class'] == 'individuals':
|
217
|
-
entity = User(_entity["id"])
|
218
|
-
entity._url = f"{self.url}/model/individuals/{_entity['id']}"
|
219
|
-
|
220
|
-
entity._load(_entity)
|
221
|
-
elif _entity['_class'] == 'organizations':
|
222
|
-
entity = Organization(_entity["id"])
|
223
|
-
entity._url = f"{self.url}/model/organizations/{_entity['id']}"
|
224
|
-
|
225
|
-
_owner = _entity['owner']
|
226
|
-
if _owner['_class'] == 'individuals':
|
227
|
-
entity.owner = User(_owner['id'])
|
228
|
-
entity.owner._load(_owner)
|
229
|
-
elif _owner['class'] == 'organizations':
|
230
|
-
entity.owner = Organization(_owner['id'])
|
231
|
-
entity.owner._load(_owner)
|
232
|
-
else:
|
233
|
-
entity.owner = self.get_entity(0x0)
|
234
|
-
|
235
|
-
entity._load(_entity)
|
236
|
-
else:
|
237
|
-
entity = Entity(_entity["id"])
|
238
|
-
entity._url = f"{self.url}/model/organizations/{_entity['id']}"
|
239
|
-
|
240
|
-
entity.name = _entity['name']
|
241
|
-
entity.position._load(_entity['position'])
|
242
|
-
entity.registerDate = _entity['register_date']
|
243
|
-
|
244
|
-
for key, value in _entity.get('additional', {}).items():
|
245
|
-
if isinstance(value, str) and value.startswith('\n'):
|
246
|
-
entity.additional[key] = int(value[1:])
|
247
|
-
else:
|
248
|
-
entity.additional[key] = value
|
249
|
-
|
250
|
-
entity.position._url = f"{self.url}/positions/{_entity['id']}"
|
251
|
-
|
252
|
-
res.append(entity)
|
253
|
-
|
254
|
-
return res
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
def get_position(self, id: str) -> Position:
|
259
|
-
"""
|
260
|
-
Récupère une position légale (métier, domaine professionnel).
|
261
|
-
|
262
|
-
## Paramètres
|
263
|
-
id: `str`\n
|
264
|
-
ID de la position (SENSIBLE À LA CASSE !)
|
265
|
-
|
266
|
-
## Renvoie
|
267
|
-
- `.Position`
|
268
|
-
"""
|
269
|
-
|
270
|
-
_data = self._get_by_ID('positions', id)
|
271
|
-
|
272
|
-
if _data is None:
|
273
|
-
return None
|
274
|
-
|
275
|
-
position = Position(id)
|
276
|
-
position._url = f"{self.url}/positions/{id}"
|
277
|
-
position.name = _data['name']
|
278
|
-
position.permissions.merge(_data['permissions'])
|
279
|
-
position.manager_permissions.merge(_data['manager_permissions'])
|
280
|
-
|
281
|
-
return position
|