From f74038af12c577aa5b6ed6f87180f880f0ce8edc Mon Sep 17 00:00:00 2001 From: Johannes Christ Date: Sat, 1 Sep 2018 18:42:06 +0200 Subject: Add support for deleting off-topic-channel names. --- api/viewsets.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'api/viewsets.py') diff --git a/api/viewsets.py b/api/viewsets.py index 0bbb70f2..82f8aea9 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -1,3 +1,4 @@ +from django.shortcuts import get_object_or_404 from rest_framework.exceptions import ParseError from rest_framework.mixins import CreateModelMixin, DestroyModelMixin, ListModelMixin, RetrieveModelMixin from rest_framework.response import Response @@ -70,7 +71,7 @@ class DocumentationLinkViewSet(CreateModelMixin, DestroyModelMixin, ListModelMix lookup_field = 'package' -class OffTopicChannelNameViewSet(ViewSet): +class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet): """ View of off-topic channel names used by the bot to rotate our off-topic names on a daily basis. @@ -102,12 +103,30 @@ class OffTopicChannelNameViewSet(ViewSet): - 201: returned on success - 400: if the request body has invalid fields, see the response for details + ### DELETE /bot/off-topic-channel-names/ + Delete the off-topic-channel name with the given `name`. + + #### Status codes + - 204: returned on success + - 404: returned when the given `name` was not found + ## Authentication Requires a API token. """ + lookup_field = 'name' serializer_class = OffTopicChannelNameSerializer + def get_object(self): + queryset = self.get_queryset() + if self.lookup_field not in self.kwargs: + raise ParseError(detail={ + 'name': ["This query parameter is required."] + }) + + name = self.kwargs[self.lookup_field] + return get_object_or_404(queryset, name=name) + def get_queryset(self): return OffTopicChannelName.objects.all() -- cgit v1.2.3