diff options
| author | 2019-07-21 10:00:53 +0200 | |
|---|---|---|
| committer | 2019-07-21 10:00:53 +0200 | |
| commit | 5766439c3b521d9a70f5469ecaa2f4820270ea67 (patch) | |
| tree | baaafbd03801af3efc25a1a3fac47bf1ee25a0a3 /pydis_site/apps/api/viewsets/bot | |
| parent | Merge pull request #220 from python-discord/django-api-bot-nomination-changes (diff) | |
| parent | Update pre-commit config to ignore migrations directory (diff) | |
Merge pull request #229 from python-discord/low-hanging-merge-fruit
Minor Merges from master
Diffstat (limited to 'pydis_site/apps/api/viewsets/bot')
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/__init__.py | 4 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/infraction.py | 5 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/nomination.py | 1 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/off_topic_channel_name.py | 4 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/snake_fact.py | 30 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/snake_idiom.py | 30 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/snake_name.py | 69 | ||||
| -rw-r--r-- | pydis_site/apps/api/viewsets/bot/special_snake.py | 33 |
8 files changed, 1 insertions, 175 deletions
diff --git a/pydis_site/apps/api/viewsets/bot/__init__.py b/pydis_site/apps/api/viewsets/bot/__init__.py index 8e7d1290..465ba5f4 100644 --- a/pydis_site/apps/api/viewsets/bot/__init__.py +++ b/pydis_site/apps/api/viewsets/bot/__init__.py @@ -6,9 +6,5 @@ from .nomination import NominationViewSet # noqa from .off_topic_channel_name import OffTopicChannelNameViewSet # noqa from .reminder import ReminderViewSet # noqa from .role import RoleViewSet # noqa -from .snake_fact import SnakeFactViewSet # noqa -from .snake_idiom import SnakeIdiomViewSet # noqa -from .snake_name import SnakeNameViewSet # noqa -from .special_snake import SpecialSnakeViewSet # noqa from .tag import TagViewSet # noqa from .user import UserViewSet # noqa diff --git a/pydis_site/apps/api/viewsets/bot/infraction.py b/pydis_site/apps/api/viewsets/bot/infraction.py index d12f0862..c471ca2c 100644 --- a/pydis_site/apps/api/viewsets/bot/infraction.py +++ b/pydis_site/apps/api/viewsets/bot/infraction.py @@ -125,7 +125,6 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge def partial_update(self, request, *_args, **_kwargs): """Method that handles the nuts and bolts of updating an Infraction.""" - for field in request.data: if field in self.frozen_fields: raise ValidationError({field: ['This field cannot be updated.']}) @@ -144,7 +143,6 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge Called by the Django Rest Framework in response to the corresponding HTTP request. """ - self.serializer_class = ExpandedInfractionSerializer return self.list(*args, **kwargs) @@ -155,7 +153,6 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge Called by the Django Rest Framework in response to the corresponding HTTP request. """ - self.serializer_class = ExpandedInfractionSerializer return self.create(*args, **kwargs) @@ -166,7 +163,6 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge Called by the Django Rest Framework in response to the corresponding HTTP request. """ - self.serializer_class = ExpandedInfractionSerializer return self.retrieve(*args, **kwargs) @@ -177,6 +173,5 @@ class InfractionViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge Called by the Django Rest Framework in response to the corresponding HTTP request. """ - self.serializer_class = ExpandedInfractionSerializer return self.partial_update(*args, **kwargs) diff --git a/pydis_site/apps/api/viewsets/bot/nomination.py b/pydis_site/apps/api/viewsets/bot/nomination.py index a9dacd68..8d551697 100644 --- a/pydis_site/apps/api/viewsets/bot/nomination.py +++ b/pydis_site/apps/api/viewsets/bot/nomination.py @@ -143,6 +143,7 @@ class NominationViewSet(CreateModelMixin, RetrieveModelMixin, ListModelMixin, Ge See operation 1 for the response format and status codes. """ + serializer_class = NominationSerializer queryset = Nomination.objects.all() filter_backends = (DjangoFilterBackend, SearchFilter, OrderingFilter) 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 4976c291..d977aade 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 @@ -60,14 +60,12 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet): If it doesn't, a HTTP 404 is returned by way of throwing an exception. """ - queryset = self.get_queryset() name = self.kwargs[self.lookup_field] return get_object_or_404(queryset, name=name) def get_queryset(self): """Returns a queryset that covers the entire OffTopicChannelName table.""" - return OffTopicChannelName.objects.all() def create(self, request): @@ -76,7 +74,6 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet): Called by the Django Rest Framework in response to the corresponding HTTP request. """ - if 'name' in request.query_params: create_data = {'name': request.query_params['name']} serializer = OffTopicChannelNameSerializer(data=create_data) @@ -95,7 +92,6 @@ class OffTopicChannelNameViewSet(DestroyModelMixin, ViewSet): Called by the Django Rest Framework in response to the corresponding HTTP request. """ - if 'random_items' in request.query_params: param = request.query_params['random_items'] try: diff --git a/pydis_site/apps/api/viewsets/bot/snake_fact.py b/pydis_site/apps/api/viewsets/bot/snake_fact.py deleted file mode 100644 index 0b2e8ede..00000000 --- a/pydis_site/apps/api/viewsets/bot/snake_fact.py +++ /dev/null @@ -1,30 +0,0 @@ -from rest_framework.mixins import ListModelMixin -from rest_framework.viewsets import GenericViewSet - -from pydis_site.apps.api.models.bot.snake_fact import SnakeFact -from pydis_site.apps.api.serializers import SnakeFactSerializer - - -class SnakeFactViewSet(ListModelMixin, GenericViewSet): - """ - View providing snake facts created by the Pydis community in the first code jam. - - ## Routes - ### GET /bot/snake-facts - Returns snake facts from the database. - - #### Response format - >>> [ - ... {'fact': 'Snakes are dangerous'}, - ... {'fact': 'Except for Python, we all love it'} - ... ] - - #### Status codes - - 200: returned on success - - ## Authentication - Requires an API token. - """ - - serializer_class = SnakeFactSerializer - queryset = SnakeFact.objects.all() diff --git a/pydis_site/apps/api/viewsets/bot/snake_idiom.py b/pydis_site/apps/api/viewsets/bot/snake_idiom.py deleted file mode 100644 index 9f274d2f..00000000 --- a/pydis_site/apps/api/viewsets/bot/snake_idiom.py +++ /dev/null @@ -1,30 +0,0 @@ -from rest_framework.mixins import ListModelMixin -from rest_framework.viewsets import GenericViewSet - -from pydis_site.apps.api.models.bot.snake_idiom import SnakeIdiom -from pydis_site.apps.api.serializers import SnakeIdiomSerializer - - -class SnakeIdiomViewSet(ListModelMixin, GenericViewSet): - """ - View providing snake idioms for the snake cog. - - ## Routes - ### GET /bot/snake-idioms - Returns snake idioms from the database. - - #### Response format - >>> [ - ... {'idiom': 'Sneky snek'}, - ... {'idiom': 'Snooky Snake'} - ... ] - - #### Status codes - - 200: returned on success - - ## Authentication - Requires an API token - """ - - serializer_class = SnakeIdiomSerializer - queryset = SnakeIdiom.objects.all() diff --git a/pydis_site/apps/api/viewsets/bot/snake_name.py b/pydis_site/apps/api/viewsets/bot/snake_name.py deleted file mode 100644 index 8e63a542..00000000 --- a/pydis_site/apps/api/viewsets/bot/snake_name.py +++ /dev/null @@ -1,69 +0,0 @@ -from rest_framework.response import Response -from rest_framework.viewsets import ViewSet - -from pydis_site.apps.api.models.bot.snake_name import SnakeName -from pydis_site.apps.api.serializers import SnakeNameSerializer - - -class SnakeNameViewSet(ViewSet): - """ - View providing snake names for the bot's snake cog from our first code jam's winners. - - ## Routes - ### GET /bot/snake-names - By default, return a single random snake name along with its name and scientific name. - If the `get_all` query parameter is given, for example using... - $ curl api.pythondiscord.local:8000/bot/snake-names?get_all=yes - ... then the API will return all snake names and scientific names in the database. - - #### Response format - Without `get_all` query parameter: - >>> { - ... 'name': "Python", - ... 'scientific': "Langus greatus" - ... } - - If the database is empty for whatever reason, this will return an empty dictionary. - - With `get_all` query parameter: - >>> [ - ... {'name': "Python 3", 'scientific': "Langus greatus"}, - ... {'name': "Python 2", 'scientific': "Langus decentus"} - ... ] - - #### Status codes - - 200: returned on success - - ## Authentication - Requires a API token. - """ - - serializer_class = SnakeNameSerializer - - def get_queryset(self): - """Returns a queryset that covers the entire SnakeName table.""" - - return SnakeName.objects.all() - - def list(self, request): - """ - DRF method for listing SnakeName entries. - - Called by the Django Rest Framework in response to the corresponding HTTP request. - """ - - if request.query_params.get('get_all'): - queryset = self.get_queryset() - serialized = self.serializer_class(queryset, many=True) - return Response(serialized.data) - - single_snake = SnakeName.objects.order_by('?').first() - if single_snake is not None: - body = { - 'name': single_snake.name, - 'scientific': single_snake.scientific - } - - return Response(body) - - return Response({}) diff --git a/pydis_site/apps/api/viewsets/bot/special_snake.py b/pydis_site/apps/api/viewsets/bot/special_snake.py deleted file mode 100644 index 446c79a1..00000000 --- a/pydis_site/apps/api/viewsets/bot/special_snake.py +++ /dev/null @@ -1,33 +0,0 @@ -from rest_framework.mixins import ListModelMixin -from rest_framework.viewsets import GenericViewSet - -from pydis_site.apps.api.models.bot import SpecialSnake -from pydis_site.apps.api.serializers import SpecialSnakeSerializer - - -class SpecialSnakeViewSet(ListModelMixin, GenericViewSet): - """ - View providing special snake names for our bot's snake cog. - - ## Routes - ### GET /bot/special-snakes - Returns a list of special snake names. - - #### Response Format - >>> [ - ... { - ... 'name': 'Snakky sneakatus', - ... 'info': 'Scary snek', - ... 'image': 'https://discordapp.com/assets/53ef346458017da2062aca5c7955946b.svg' - ... } - ... ] - - #### Status codes - - 200: returned on success - - ## Authentication - Requires an API token. - """ - - serializer_class = SpecialSnakeSerializer - queryset = SpecialSnake.objects.all() |