Merge pull request #5913 from FinnStutzenstein/fixPointOfOrderWeighting
Fix point of order weighting
This commit is contained in:
commit
e75bdeb0f7
@ -475,45 +475,34 @@ class SpeakerManager(models.Manager):
|
|||||||
Note that this method has side-effects: It might change the weight of other speakers to make
|
Note that this method has side-effects: It might change the weight of other speakers to make
|
||||||
space for the new point of order speaker.
|
space for the new point of order speaker.
|
||||||
"""
|
"""
|
||||||
if point_of_order:
|
queryset = self.filter(list_of_speakers=list_of_speakers, begin_time=None)
|
||||||
# get the first waiting speaker
|
|
||||||
first_speaker = self.filter(begin_time=None).order_by("weight").first()
|
|
||||||
|
|
||||||
if first_speaker is None:
|
# get non-poo speakers out of the way
|
||||||
return 1
|
if not point_of_order:
|
||||||
if not first_speaker.point_of_order:
|
return (queryset.aggregate(models.Max("weight"))["weight__max"] or 0) + 1
|
||||||
return first_speaker.weight - 1
|
|
||||||
|
|
||||||
# get the first non-poo speaker
|
# get the first waiting speaker
|
||||||
first_non_poo_speaker = (
|
first_speaker = queryset.order_by("weight").first()
|
||||||
self.filter(begin_time=None, point_of_order=False)
|
|
||||||
.order_by("weight")
|
|
||||||
.first()
|
|
||||||
)
|
|
||||||
|
|
||||||
if first_non_poo_speaker is None:
|
if first_speaker is None:
|
||||||
# max weight + 1, the speaker is last since there are no non-poo speakers
|
return 1 # no speakers yet
|
||||||
return (
|
if not first_speaker.point_of_order:
|
||||||
self.filter(
|
return first_speaker.weight - 1
|
||||||
list_of_speakers=list_of_speakers, begin_time=None
|
|
||||||
).aggregate(models.Max("weight"))["weight__max"]
|
|
||||||
+ 1
|
|
||||||
)
|
|
||||||
|
|
||||||
weight = first_non_poo_speaker.weight
|
# get the first non-poo speaker
|
||||||
# add +1 to all speakers with weight >= first_non_poo_speaker.weight
|
first_non_poo_speaker = (
|
||||||
self.filter(
|
queryset.filter(point_of_order=False).order_by("weight").first()
|
||||||
list_of_speakers=list_of_speakers, begin_time=None, weight__gte=weight
|
)
|
||||||
).update(weight=F("weight") + 1)
|
|
||||||
|
|
||||||
return weight
|
if first_non_poo_speaker is None:
|
||||||
else:
|
# max weight + 1, the speaker is last since there are no non-poo speakers
|
||||||
return (
|
return (queryset.aggregate(models.Max("weight"))["weight__max"] or 0) + 1
|
||||||
self.filter(list_of_speakers=list_of_speakers).aggregate(
|
|
||||||
models.Max("weight")
|
weight = first_non_poo_speaker.weight
|
||||||
)["weight__max"]
|
# add +1 to all speakers with weight >= first_non_poo_speaker.weight
|
||||||
or 0
|
queryset.filter(weight__gte=weight).update(weight=F("weight") + 1)
|
||||||
) + 1
|
|
||||||
|
return weight
|
||||||
|
|
||||||
|
|
||||||
class Speaker(RESTModelMixin, models.Model):
|
class Speaker(RESTModelMixin, models.Model):
|
||||||
|
Loading…
Reference in New Issue
Block a user