nsarchive 2.0.0a1__tar.gz → 2.0.0a2__tar.gz
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-2.0.0a1 → nsarchive-2.0.0a2}/PKG-INFO +1 -1
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/cls/archives.py +35 -29
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/instances/_economy.py +13 -16
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/instances/_entities.py +18 -30
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/instances/_republic.py +18 -22
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/pyproject.toml +1 -1
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/LICENSE +0 -0
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/README.md +0 -0
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/__init__.py +0 -0
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/assets/default_avatar.png +0 -0
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/cls/base.py +0 -0
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/cls/economy.py +0 -0
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/cls/entities.py +0 -0
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/cls/exceptions.py +0 -0
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/cls/republic.py +0 -0
- {nsarchive-2.0.0a1 → nsarchive-2.0.0a2}/nsarchive/utils/assets.py +0 -0
@@ -2,69 +2,75 @@ import time
|
|
2
2
|
|
3
3
|
from .base import *
|
4
4
|
|
5
|
-
class
|
5
|
+
class Archive:
|
6
6
|
def __init__(self, author: str | NSID = '0', target: str | NSID = '0') -> None:
|
7
7
|
self.date: int = round(time.time())
|
8
8
|
|
9
9
|
self.id: NSID = NSID(self.date)
|
10
|
-
self.action: str = ""
|
11
10
|
self.author: NSID = NSID(author)
|
12
11
|
self.target: NSID = NSID(target)
|
13
12
|
|
13
|
+
self.action: str = ""
|
14
|
+
self.details: dict = {
|
15
|
+
"reason": None
|
16
|
+
}
|
14
17
|
|
15
|
-
# Entities
|
16
18
|
|
17
|
-
|
18
|
-
def __init__(self, author: str | NSID, target: str | NSID) -> None:
|
19
|
-
super().__init__(author, target)
|
20
|
-
|
21
|
-
self.details: str = ""
|
22
|
-
self.major: bool = False # Sanction majeure ou non
|
23
|
-
self.duration: int = 0 # Durée en secondes, 0 = définitif
|
19
|
+
# Entities
|
24
20
|
|
25
|
-
class
|
21
|
+
class Sanction(Archive):
|
26
22
|
def __init__(self, author: str | NSID, target: str | NSID) -> None:
|
27
23
|
super().__init__(author, target)
|
28
24
|
|
29
|
-
self.details:
|
30
|
-
|
25
|
+
self.details: dict = {
|
26
|
+
"reason": None,
|
27
|
+
"major": False, # Sanction majeure ou non
|
28
|
+
"duration": 0 # Durée en secondes , 0 = définitif
|
29
|
+
}
|
31
30
|
|
32
|
-
class Report(
|
31
|
+
class Report(Archive):
|
33
32
|
def __init__(self, author: str | NSID, target: str | NSID) -> None:
|
34
33
|
super().__init__(author, target)
|
35
34
|
|
36
|
-
self.details:
|
35
|
+
self.details: dict = {
|
36
|
+
"reason": None,
|
37
|
+
"elements": [] # Liste des pièces jointes
|
38
|
+
}
|
37
39
|
|
38
40
|
|
39
41
|
# Community
|
40
42
|
|
41
|
-
class Election(
|
43
|
+
class Election(Archive):
|
42
44
|
def __init__(self, author: str | NSID, target: str | NSID, position: str) -> None:
|
43
45
|
super().__init__(author, target)
|
44
46
|
|
45
|
-
self.
|
46
|
-
|
47
|
-
|
47
|
+
self.details = {
|
48
|
+
"position": position,
|
49
|
+
"positive_votes": 0,
|
50
|
+
"total_votes": 0
|
51
|
+
}
|
48
52
|
|
49
|
-
class Promotion(
|
53
|
+
class Promotion(Archive):
|
50
54
|
def __init__(self, author: str | NSID, target: str | NSID, position: str) -> None:
|
51
55
|
super().__init__(author, target)
|
52
56
|
|
53
|
-
self.
|
57
|
+
self.details = {
|
58
|
+
"position": position
|
59
|
+
}
|
54
60
|
|
55
|
-
class Demotion(
|
61
|
+
class Demotion(Archive):
|
56
62
|
def __init__(self, author: str | NSID, target: str | NSID) -> None:
|
57
63
|
super().__init__(author, target)
|
58
64
|
|
59
|
-
self.reason: str = None
|
60
|
-
|
61
65
|
|
62
66
|
# Bank
|
63
67
|
|
64
|
-
class Transaction(
|
65
|
-
def __init__(self, author: str | NSID, target: str | NSID
|
68
|
+
class Transaction(Archive):
|
69
|
+
def __init__(self, author: str | NSID, target: str | NSID) -> None:
|
66
70
|
super().__init__(author, target)
|
67
71
|
|
68
|
-
self.
|
69
|
-
|
70
|
-
|
72
|
+
self.details = {
|
73
|
+
"amount": 0,
|
74
|
+
"currency": "HC",
|
75
|
+
"reason": None
|
76
|
+
}
|
@@ -185,7 +185,7 @@ class EconomyInstance(Instance):
|
|
185
185
|
---- ARCHIVES ----
|
186
186
|
"""
|
187
187
|
|
188
|
-
def _add_archive(self, archive:
|
188
|
+
def _add_archive(self, archive: Archive):
|
189
189
|
"""Ajoute une archive d'une transaction ou d'une vente dans la base de données."""
|
190
190
|
|
191
191
|
archive.id = NSID(archive.id)
|
@@ -195,14 +195,13 @@ class EconomyInstance(Instance):
|
|
195
195
|
_data = archive.__dict__.copy()
|
196
196
|
|
197
197
|
if type(archive) == Transaction:
|
198
|
-
_data['
|
199
|
-
archive.currency = archive.currency.upper()
|
198
|
+
_data['_type'] = "transaction"
|
200
199
|
else:
|
201
|
-
_data['
|
200
|
+
_data['_type'] = "unknown"
|
202
201
|
|
203
202
|
self._put_in_db('archives', _data)
|
204
203
|
|
205
|
-
def _get_archive(self, id: str | NSID) ->
|
204
|
+
def _get_archive(self, id: str | NSID) -> Archive | Transaction:
|
206
205
|
"""
|
207
206
|
Récupère une archive spécifique.
|
208
207
|
|
@@ -211,30 +210,28 @@ class EconomyInstance(Instance):
|
|
211
210
|
ID de l'archive.
|
212
211
|
|
213
212
|
## Renvoie
|
214
|
-
- `.
|
213
|
+
- `.Archive | .Transaction`
|
215
214
|
"""
|
216
215
|
|
217
216
|
id = NSID(id)
|
218
|
-
_data = self.archives
|
217
|
+
_data = self._get_by_ID('archives', id)
|
219
218
|
|
220
219
|
if _data is None:
|
221
220
|
return None
|
222
221
|
|
223
|
-
if _data['
|
224
|
-
archive = Transaction(_data['author'], _data['target']
|
225
|
-
|
226
|
-
archive.reason = _data['reason']
|
227
|
-
archive.currency = _data['currency']
|
222
|
+
if _data['_type'] == "transaction":
|
223
|
+
archive = Transaction(_data['author'], _data['target'])
|
228
224
|
else:
|
229
|
-
archive =
|
225
|
+
archive = Archive(_data['author'], _data['target'])
|
230
226
|
|
231
227
|
archive.id = id
|
232
228
|
archive.action = _data['action']
|
233
229
|
archive.date = _data['date']
|
230
|
+
archive.details = _data['details']
|
234
231
|
|
235
232
|
return archive
|
236
233
|
|
237
|
-
def _fetch_archives(self, **query) -> list[
|
234
|
+
def _fetch_archives(self, **query) -> list[ Archive | Transaction ]:
|
238
235
|
"""
|
239
236
|
Récupère une liste d'archives correspondant à la requête.
|
240
237
|
|
@@ -243,9 +240,9 @@ class EconomyInstance(Instance):
|
|
243
240
|
Requête pour filtrer les archives.
|
244
241
|
|
245
242
|
## Renvoie
|
246
|
-
- `list[
|
243
|
+
- `list[.Archive | .Transaction]`
|
247
244
|
"""
|
248
245
|
|
249
246
|
_res = self.fetch('archives', **query)
|
250
247
|
|
251
|
-
return [ self._get_archive(archive['
|
248
|
+
return [ self._get_archive(archive['id']) for archive in _res ]
|
@@ -84,7 +84,7 @@ class EntityInstance(Instance):
|
|
84
84
|
entity.append(member)
|
85
85
|
|
86
86
|
entity.certifications = _data['certifications']
|
87
|
-
entity.
|
87
|
+
entity.parts = _data['parts']
|
88
88
|
else:
|
89
89
|
entity = Entity(id)
|
90
90
|
|
@@ -155,7 +155,7 @@ class EntityInstance(Instance):
|
|
155
155
|
|
156
156
|
self._delete_by_ID('individuals' if isinstance(entity, User) else 'organizations', NSID(entity.id))
|
157
157
|
|
158
|
-
def fetch_entities(self, query: dict
|
158
|
+
def fetch_entities(self, **query: dict) -> list[ Entity | User | Organization ]:
|
159
159
|
"""
|
160
160
|
Récupère une liste d'entités en fonction d'une requête.
|
161
161
|
|
@@ -184,8 +184,8 @@ class EntityInstance(Instance):
|
|
184
184
|
"""
|
185
185
|
|
186
186
|
id = NSID(id)
|
187
|
-
groups = self.fetch_entities(
|
188
|
-
groups.extend(self.fetch_entities(
|
187
|
+
groups = self.fetch_entities(_type = 'organization')
|
188
|
+
groups.extend(self.fetch_entities(_type = 'organization', owner_id = id))
|
189
189
|
|
190
190
|
for group in groups:
|
191
191
|
if group is None:
|
@@ -230,7 +230,7 @@ class EntityInstance(Instance):
|
|
230
230
|
---- ARCHIVES --
|
231
231
|
"""
|
232
232
|
|
233
|
-
def _add_archive(self, archive:
|
233
|
+
def _add_archive(self, archive: Archive) -> None:
|
234
234
|
"""
|
235
235
|
Ajoute une archive d'une action (modification au sein d'un groupe ou sanction) dans la base de données.
|
236
236
|
"""
|
@@ -242,17 +242,15 @@ class EntityInstance(Instance):
|
|
242
242
|
_data = archive.__dict__.copy()
|
243
243
|
|
244
244
|
if type(archive) == Sanction:
|
245
|
-
_data['
|
246
|
-
elif type(archive) == AdminAction:
|
247
|
-
_data['type'] = "adminaction"
|
245
|
+
_data['_type'] = "sanction"
|
248
246
|
elif type(archive) == Report:
|
249
|
-
_data['
|
247
|
+
_data['_type'] = "report"
|
250
248
|
else:
|
251
|
-
_data['
|
249
|
+
_data['_type'] = "unknown"
|
252
250
|
|
253
251
|
self._put_in_db('archives', _data)
|
254
252
|
|
255
|
-
def _get_archive(self, id: str | NSID) ->
|
253
|
+
def _get_archive(self, id: str | NSID) -> Archive | Sanction:
|
256
254
|
"""
|
257
255
|
Récupère une archive spécifique.
|
258
256
|
|
@@ -261,7 +259,7 @@ class EntityInstance(Instance):
|
|
261
259
|
ID de l'archive.
|
262
260
|
|
263
261
|
## Renvoie
|
264
|
-
- `.
|
262
|
+
- `.Archive | .Sanction `
|
265
263
|
"""
|
266
264
|
|
267
265
|
id = NSID(id)
|
@@ -270,31 +268,21 @@ class EntityInstance(Instance):
|
|
270
268
|
if _data is None:
|
271
269
|
return None
|
272
270
|
|
273
|
-
if _data['
|
271
|
+
if _data['_type'] == "sanction": # Mute, ban, GAV, kick, détention, prune (xp seulement)
|
274
272
|
archive = Sanction(_data['author'], _data['target'])
|
275
|
-
|
276
|
-
archive.details = _data['details']
|
277
|
-
archive.major = _data['major']
|
278
|
-
archive.duration = _data['duration']
|
279
|
-
elif _data['type'] == "adminaction": # Renommage, promotion, démotion (au niveau de l'état)
|
280
|
-
archive = AdminAction(_data['author'], _data['target'])
|
281
|
-
|
282
|
-
archive.details = _data['details']
|
283
|
-
archive.new_state = _data['new_state']
|
284
|
-
elif _data['type'] == "report": # Plainte
|
273
|
+
elif _data['_type'] == "report": # Plainte
|
285
274
|
archive = Report(_data['author'], _data['target'])
|
286
|
-
|
287
|
-
archive.details = _data['details']
|
288
275
|
else:
|
289
|
-
archive =
|
276
|
+
archive = Archive(_data['author'], _data['target'])
|
290
277
|
|
291
278
|
archive.id = id
|
292
|
-
archive.action = _data['action']
|
293
279
|
archive.date = _data['date']
|
280
|
+
archive.action = _data['action']
|
281
|
+
archive.details = _data['details']
|
294
282
|
|
295
283
|
return archive
|
296
284
|
|
297
|
-
def _fetch_archives(self, **query) -> list[
|
285
|
+
def _fetch_archives(self, **query) -> list[ Archive | Sanction ]:
|
298
286
|
"""
|
299
287
|
Récupère une liste d'archives correspondant à la requête.
|
300
288
|
|
@@ -303,9 +291,9 @@ class EntityInstance(Instance):
|
|
303
291
|
Requête pour filtrer les archives.
|
304
292
|
|
305
293
|
## Renvoie
|
306
|
-
- `list[
|
294
|
+
- `list[.Archive | .Sanction]`
|
307
295
|
"""
|
308
296
|
|
309
297
|
_res = self.fetch('archives', **query)
|
310
298
|
|
311
|
-
return [ self._get_archive(archive['
|
299
|
+
return [ self._get_archive(archive['id']) for archive in _res ]
|
@@ -103,9 +103,9 @@ class RepublicInstance(Instance):
|
|
103
103
|
|
104
104
|
base = 'mandate' if current_mandate else 'archives'
|
105
105
|
|
106
|
-
_contributions = self.fetch(base, {'author': id, '
|
107
|
-
_mandates = self.fetch(base, {'target': id, '
|
108
|
-
self.fetch(base, {'target': id, '
|
106
|
+
_contributions = self.fetch(base, {'author': id, '_type': 'contrib'})
|
107
|
+
_mandates = self.fetch(base, {'target': id, '_type': 'election'}) +\
|
108
|
+
self.fetch(base, {'target': id, '_type': 'promotion'})
|
109
109
|
|
110
110
|
user = Official(id)
|
111
111
|
for mandate in _mandates:
|
@@ -209,25 +209,25 @@ class RepublicInstance(Instance):
|
|
209
209
|
---- ARCHIVES ----
|
210
210
|
"""
|
211
211
|
|
212
|
-
def _add_archive(self, archive:
|
212
|
+
def _add_archive(self, archive: Archive) -> None:
|
213
213
|
"""Ajoute une archive d'une action (élection, promotion, ou rétrogradation) dans la base de données."""
|
214
214
|
|
215
215
|
archive.id = NSID(archive.id)
|
216
216
|
_data = archive.__dict__.copy()
|
217
217
|
|
218
218
|
if type(archive) == Election:
|
219
|
-
_data['
|
219
|
+
_data['_type'] = "election"
|
220
220
|
elif type(archive) == Promotion:
|
221
|
-
_data['
|
221
|
+
_data['_type'] = "promotion"
|
222
222
|
elif type(archive) == Demotion:
|
223
|
-
_data['
|
223
|
+
_data['_type'] = "demotion"
|
224
224
|
else:
|
225
|
-
_data['
|
225
|
+
_data['_type'] = "unknown"
|
226
226
|
|
227
227
|
self._put_in_db('archives', _data)
|
228
228
|
self._put_in_db('mandate', _data) # Ajouter les archives à celle du mandat actuel
|
229
229
|
|
230
|
-
def _get_archive(self, id: str | NSID) ->
|
230
|
+
def _get_archive(self, id: str | NSID) -> Archive | Election | Promotion | Demotion:
|
231
231
|
"""
|
232
232
|
Récupère une archive spécifique.
|
233
233
|
|
@@ -236,7 +236,7 @@ class RepublicInstance(Instance):
|
|
236
236
|
ID de l'archive.
|
237
237
|
|
238
238
|
## Renvoie
|
239
|
-
- `.
|
239
|
+
- `.Archive | .Election | .Promotion | .Demotion`
|
240
240
|
"""
|
241
241
|
|
242
242
|
id = NSID(id)
|
@@ -245,27 +245,23 @@ class RepublicInstance(Instance):
|
|
245
245
|
if _data is None:
|
246
246
|
return None
|
247
247
|
|
248
|
-
if _data['
|
248
|
+
if _data['_type'] == "election":
|
249
249
|
archive = Election(_data['author'], _data['target'], _data['position'])
|
250
|
-
|
251
|
-
archive.positive_votes = _data['positive_votes']
|
252
|
-
archive.total_votes = _data['total_votes']
|
253
|
-
elif _data['type'] == "promotion":
|
250
|
+
elif _data['_type'] == "promotion":
|
254
251
|
archive = Promotion(_data['author'], _data['target'], _data['position'])
|
255
|
-
elif _data['
|
252
|
+
elif _data['_type'] == "demotion":
|
256
253
|
archive = Demotion(_data['author'], _data['target'])
|
257
|
-
|
258
|
-
archive.reason = _data['reason']
|
259
254
|
else:
|
260
|
-
archive =
|
255
|
+
archive = Archive(_data['author'], _data['target'])
|
261
256
|
|
262
257
|
archive.id = id
|
263
258
|
archive.action = _data['action']
|
264
259
|
archive.date = _data['date']
|
260
|
+
archive.details = _data['details']
|
265
261
|
|
266
262
|
return archive
|
267
263
|
|
268
|
-
def _fetch_archives(self, **query) -> list[
|
264
|
+
def _fetch_archives(self, **query) -> list[ Archive | Election | Promotion | Demotion ]:
|
269
265
|
"""
|
270
266
|
Récupère une liste d'archives correspondant à la requête.
|
271
267
|
|
@@ -274,9 +270,9 @@ class RepublicInstance(Instance):
|
|
274
270
|
Requête pour filtrer les archives.
|
275
271
|
|
276
272
|
## Renvoie
|
277
|
-
- `list[
|
273
|
+
- `list[.Archive | .Election | .Promotion | .Demotion]`
|
278
274
|
"""
|
279
275
|
|
280
276
|
_res = self.fetch('archives', **query)
|
281
277
|
|
282
|
-
return [ self._get_archive(archive['
|
278
|
+
return [ self._get_archive(archive['id']) for archive in _res ]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|