aboutsummaryrefslogtreecommitdiffstats
path: root/pydis_site/apps/api/viewsets
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-08-29 10:00:45 -0700
committerGravatar MarkKoz <[email protected]>2020-08-29 10:00:45 -0700
commitdae68c46831ef14e6a0715add1025f9af1b5a73d (patch)
tree9d7983d6979e6b4d7ce5cb0264a1f98361cca34a /pydis_site/apps/api/viewsets
parentMerge pull request #348 from ks129/off-topic-non-random (diff)
Revert pull request #348
Revert commit 330a27926a7f2a9bdae56a5928cd81e55ccb38ed to reverse changes made to 6c08da2f3e48db9c9dd452f2e0505c4a61e46592. Migrations were failing when those changes were deployed.
Diffstat (limited to 'pydis_site/apps/api/viewsets')
-rw-r--r--pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py27
1 files changed, 2 insertions, 25 deletions
diff --git a/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py b/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py
index 826ad25e..d6da2399 100644
--- a/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py
+++ b/pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py
@@ -1,4 +1,3 @@
-from django.db.models import Case, Value, When
from django.db.models.query import QuerySet
from django.http.request import HttpRequest
from django.shortcuts import get_object_or_404
@@ -21,9 +20,7 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):
Return all known off-topic channel names from the database.
If the `random_items` query parameter is given, for example using...
$ curl api.pythondiscord.local:8000/bot/off-topic-channel-names?random_items=5
- ... then the API will return `5` random items from the database
- that is not used in current rotation.
- When running out of names, API will mark all names to not used and start new rotation.
+ ... then the API will return `5` random items from the database.
#### Response format
Return a list of off-topic-channel names:
@@ -109,27 +106,7 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet):
'random_items': ["Must be a positive integer."]
})
- queryset = self.get_queryset().order_by('used', '?')[:random_count]
-
- # When any name is used in our listing then this means we reached end of round
- # and we need to reset all other names `used` to False
- if any(offtopic_name.used for offtopic_name in queryset):
- # These names that we just got have to be excluded from updating used to False
- self.get_queryset().update(
- used=Case(
- When(
- name__in=(offtopic_name.name for offtopic_name in queryset),
- then=Value(True)
- ),
- default=Value(False)
- )
- )
- else:
- # Otherwise mark selected names `used` to True
- self.get_queryset().filter(
- name__in=(offtopic_name.name for offtopic_name in queryset)
- ).update(used=True)
-
+ queryset = self.get_queryset().order_by('?')[:random_count]
serialized = self.serializer_class(queryset, many=True)
return Response(serialized.data)