Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Pole-Web
Website
Commits
5ad9cc0e
Commit
5ad9cc0e
authored
Oct 14, 2021
by
VAN ZUIJLEN Nils
Browse files
Merge branch '66-lenteur-de-events' into 'master'
Resolve "Lenteur de /events/" Closes
#66
See merge request
!63
parents
765baa25
f838738c
Changes
1
Hide whitespace changes
Inline
Side-by-side
events/models.py
View file @
5ad9cc0e
...
...
@@ -90,14 +90,35 @@ class Event(models.Model):
@
staticmethod
def
to_come
(
user
):
events
=
[
event
for
event
in
Event
.
objects
.
filter
(
Q
(
model
=
False
),
Q
(
end_inscriptions__gt
=
timezone
.
now
()),
Q
(
inscriptions__user
=
user
)
|
Q
(
private
=
False
)
).
distinct
().
prefetch_related
(
'formulas'
).
order_by
(
'start_time'
)
.
annotate
(
reg_nb
=
(
Count
(
'inscriptions'
,
distinct
=
True
)
+
Count
(
'extern_inscriptions'
,
distinct
=
True
)
+
Count
(
'invitations'
,
distinct
=
True
)))
.
extra
(
select
=
{
'ins'
:
"(SELECT COUNT(*) FROM events_inscription WHERE events_inscription.event_id=events_event.id AND events_inscription.user_id=%d)"
%
user
.
id
})]
return
[(
event
.
ins
,
event
)
for
event
in
events
]
events
=
list
(
Event
.
objects
.
filter
(
Q
(
model
=
False
),
Q
(
end_inscriptions__gt
=
timezone
.
now
()),
Q
(
inscriptions__user
=
user
)
|
Q
(
private
=
False
)
).
distinct
().
prefetch_related
(
'formulas'
).
order_by
(
'start_time'
)
.
extra
(
select
=
{
# Pour savoir si l'utilisateur actuel est inscrit
'ins'
:
"(SELECT COUNT(*) FROM events_inscription "
"WHERE events_inscription.event_id=events_event.id "
"AND events_inscription.user_id=%d)"
%
user
.
id
})
)
events_by_id
=
{
e
.
pk
:
[
e
,
0
]
for
e
in
events
}
counts_ins
=
Event
.
objects
.
filter
(
pk__in
=
events_by_id
.
keys
()).
annotate
(
ins_cnt
=
Count
(
'inscriptions'
))
counts_ext
=
Event
.
objects
.
filter
(
pk__in
=
events_by_id
.
keys
()).
annotate
(
ext_cnt
=
Count
(
'extern_inscriptions'
))
counts_inv
=
Event
.
objects
.
filter
(
pk__in
=
events_by_id
.
keys
()).
annotate
(
inv_cnt
=
Count
(
'invitations'
))
for
e
in
counts_ins
:
events_by_id
[
e
.
pk
][
1
]
+=
e
.
ins_cnt
for
e
in
counts_ext
:
events_by_id
[
e
.
pk
][
1
]
+=
e
.
ext_cnt
for
e
in
counts_inv
:
events_by_id
[
e
.
pk
][
1
]
+=
e
.
inv_cnt
for
e
,
cnt
in
events_by_id
.
values
():
e
.
reg_nb
=
cnt
return
[(
e
.
ins
,
e
)
for
e
in
events
]
def
formulas_json
(
self
):
res
=
{
f
.
name
:
"{} <br>(Cotisant: {}€ / Non cotisant: {}€)"
.
format
(
f
.
name
,
f
.
price_contributor
,
f
.
price_non_contributor
)
for
f
in
self
.
formulas
.
all
()}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment