-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.py
131 lines (101 loc) · 3.05 KB
/
service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
from pocketbase import PocketBase
from ampalibe import Configuration as config
client = PocketBase(config.POCKET_URL)
client.admins.auth_with_password(config.ADMIN_EMAIL, config.ADMIN_PASSWORD)
def _struct(data):
data.logo_url = client.get_file_url(data, data.logo, {})
return data.__dict__
def participants():
return list(
map(
_struct,
client.collection("participants").get_full_list(
query_params={"sort": "univ_name"}
),
)
)
def participants_from_name_like(name):
return list(
map(
_struct,
client.collection("participants")
.get_list(query_params={"filter": f"(univ_name~'%{name}%')"})
.items,
)
)
def participant_vote(participant):
return map(
lambda x: x.__dict__,
client.collection("votes").get_full_list(
query_params={"filter": f'participant = "{participant._id}"'}
),
)
def participant(_id):
return _struct(client.collection("participants").get_one(_id))
def voter(_id):
return client.collection("voters").get_one(_id).__dict__
def voter_from_fb_id(fb_id):
return client.collection("voters").get_full_list(
query_params={"filter": f'fb_id = "{fb_id}"'}
)
def voter_vote(voter, participant=True):
res = client.collection("votes").get_list(
query_params={
"filter": f'voter = "{voter.id}"',
"expand": "participant",
}
)
return (
(_struct(getattr(res.items[0], "expand")["participant"]) if res.items else {})
if participant
else res.items[0].__dict__
)
def voter_create(fb_id, name, profil_pic):
return (
client.collection("voters")
.create({"fb_id": fb_id, "name": name, "profil_pic": profil_pic})
.__dict__
)
def vote_save(vote):
return client.collection("votes").create(
{
"voter": vote.voter.id,
"participant": vote.participant.id,
"comment": vote.comment,
}
)
def vote_update(vote):
return client.collection("votes").update(
vote.id,
{
"voter": vote.voter.id,
"participant": vote.participant.id,
"comment": vote.comment,
},
)
def contre_vote_save(contre_vote):
return client.collection("contre_votes").create(
{
"voter": contre_vote.voter.id,
"participant": contre_vote.participant.id,
"comment": contre_vote.comment,
}
)
def contre_vote_number(voter):
return len(
client.collection("contre_votes").get_full_list(
query_params={"filter": f'voter = "{voter.id}"'}
)
)
def contre_vote_from_fb_id(fb_id):
return list(
map(
lambda x: x.__dict__,
client.collection("contre_votes").get_full_list(
query_params={
"filter": f'voter.fb_id = "{fb_id}"',
"expand": "participant,voter",
}
),
)
)