From b70ee7dff60759b5853534e10baff26b11665b1b Mon Sep 17 00:00:00 2001 From: Hasan-Ahmad Date: Fri, 19 Oct 2018 18:51:48 +0100 Subject: Added snake idioms api --- api/viewsets.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'api/viewsets.py') diff --git a/api/viewsets.py b/api/viewsets.py index 22862c16..a9294109 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -12,12 +12,14 @@ from rest_framework_bulk import BulkCreateModelMixin from .models import ( DocumentationLink, Member, OffTopicChannelName, SnakeFact, - SnakeName, Tag + SnakeIdiom, SnakeName, + Tag ) from .serializers import ( DocumentationLinkSerializer, MemberSerializer, OffTopicChannelNameSerializer, SnakeFactSerializer, - SnakeNameSerializer, TagSerializer + SnakeIdiomSerializer, SnakeNameSerializer, + TagSerializer ) @@ -199,6 +201,11 @@ class SnakeFactViewSet(ListModelMixin, GenericViewSet): queryset = SnakeFact.objects.all() +class SnakeIdiomViewSet(ListModelMixin, GenericViewSet): + serializer_class = SnakeIdiomSerializer + queryset = SnakeIdiom.objects.all() + + class SnakeNameViewSet(ViewSet): """ View providing snake names for the bot's snake cog from our first code jam's winners. -- cgit v1.2.3 From 01bbe1af142b9c94a11a567d04a5c908a7589ec5 Mon Sep 17 00:00:00 2001 From: Hasan-Ahmad Date: Sat, 20 Oct 2018 10:44:16 +0100 Subject: Added Snake idioms documentation, fixed docs for snake facts --- api/viewsets.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'api/viewsets.py') diff --git a/api/viewsets.py b/api/viewsets.py index a9294109..0025d736 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -181,7 +181,7 @@ class SnakeFactViewSet(ListModelMixin, GenericViewSet): View providing snake facts created by the Pydis community in the first code jam. ## Routes - ### GET /bot/snake-fact/ + ### GET /bot/snake-facts Returns a snake fact in the database. #### Response format @@ -202,6 +202,24 @@ class SnakeFactViewSet(ListModelMixin, GenericViewSet): class SnakeIdiomViewSet(ListModelMixin, GenericViewSet): + """ + View providing snake idioms for the snake cog. + + ## Routes + ### GET /bot/snake-idioms + Returns a snake idiom in the database. + + #### Response format + >>> [ + ... {'idiom': 'Sneky snek'}, + ... {'idiom': 'Snooky Snake'} + ... ] + #### Status codes + - 200: returned on success + ## Authentication + Requires and API token + """ + serializer_class = SnakeIdiomSerializer queryset = SnakeIdiom.objects.all() -- cgit v1.2.3 From f9072b84d0ac408d9e9347647567530ce0a85f77 Mon Sep 17 00:00:00 2001 From: Hasan-Ahmad Date: Sat, 20 Oct 2018 10:56:35 +0100 Subject: Fixed linting issues, added SnakeIdioms to test_models.py --- api/admin.py | 2 +- api/tests/test_models.py | 5 ++++- api/viewsets.py | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'api/viewsets.py') diff --git a/api/admin.py b/api/admin.py index de544b52..829d74ed 100644 --- a/api/admin.py +++ b/api/admin.py @@ -3,7 +3,7 @@ from django.contrib import admin from .models import ( DocumentationLink, Member, OffTopicChannelName, Role, - SnakeFact, SnakeIdiom, + SnakeFact, SnakeIdiom, SnakeName, Tag ) diff --git a/api/tests/test_models.py b/api/tests/test_models.py index 55009bf6..af2ef5d5 100644 --- a/api/tests/test_models.py +++ b/api/tests/test_models.py @@ -2,7 +2,9 @@ from django.test import SimpleTestCase from ..models import ( DocumentationLink, Member, ModelReprMixin, - OffTopicChannelName, Role, SnakeFact, SnakeName, Tag + OffTopicChannelName, Role, + SnakeFact, SnakeIdiom, + SnakeName, Tag ) @@ -28,6 +30,7 @@ class StringDunderMethodTests(SimpleTestCase): ), OffTopicChannelName(name='bob-the-builders-playground'), SnakeFact(fact='snakes are cute'), + SnakeIdiom(idiom='snake snacks'), SnakeName(name='python', scientific='3'), Role( id=5, name='test role', diff --git a/api/viewsets.py b/api/viewsets.py index 0025d736..e633c8b7 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -11,13 +11,13 @@ from rest_framework_bulk import BulkCreateModelMixin from .models import ( DocumentationLink, Member, - OffTopicChannelName, SnakeFact, + OffTopicChannelName, SnakeFact, SnakeIdiom, SnakeName, Tag ) from .serializers import ( DocumentationLinkSerializer, MemberSerializer, - OffTopicChannelNameSerializer, SnakeFactSerializer, + OffTopicChannelNameSerializer, SnakeFactSerializer, SnakeIdiomSerializer, SnakeNameSerializer, TagSerializer ) @@ -212,7 +212,7 @@ class SnakeIdiomViewSet(ListModelMixin, GenericViewSet): #### Response format >>> [ ... {'idiom': 'Sneky snek'}, - ... {'idiom': 'Snooky Snake'} + ... {'idiom': 'Snooky Snake'} ... ] #### Status codes - 200: returned on success -- cgit v1.2.3 From 6b8022b0cbc56fa4137666c3c7a2e488df927e56 Mon Sep 17 00:00:00 2001 From: Hasan-Ahmad Date: Sat, 20 Oct 2018 20:09:22 +0100 Subject: ficksed gramar and kept imports 2 per line --- api/migrations/0011_auto_20181020_1904.py | 18 ++++++++++++++++++ api/models.py | 2 +- api/serializers.py | 4 ++-- api/viewsets.py | 8 ++++---- 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 api/migrations/0011_auto_20181020_1904.py (limited to 'api/viewsets.py') diff --git a/api/migrations/0011_auto_20181020_1904.py b/api/migrations/0011_auto_20181020_1904.py new file mode 100644 index 00000000..bb5a6325 --- /dev/null +++ b/api/migrations/0011_auto_20181020_1904.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.2 on 2018-10-20 19:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0010_snakeidiom'), + ] + + operations = [ + migrations.AlterField( + model_name='snakeidiom', + name='idiom', + field=models.CharField(help_text='A saying about a snake.', max_length=140, primary_key=True, serialize=False), + ), + ] diff --git a/api/models.py b/api/models.py index 81cd63aa..bb520f8c 100644 --- a/api/models.py +++ b/api/models.py @@ -79,7 +79,7 @@ class SnakeIdiom(ModelReprMixin, models.Model): idiom = models.CharField( primary_key=True, max_length=140, - help_text="A snake idiom" + help_text="A saying about a snake." ) def __str__(self): diff --git a/api/serializers.py b/api/serializers.py index fae5abd9..add81335 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -4,8 +4,8 @@ from rest_framework_bulk import BulkSerializerMixin from .models import ( DocumentationLink, Member, OffTopicChannelName, Role, - SnakeFact, SnakeIdiom, SnakeName, - Tag + SnakeFact, SnakeIdiom, + SnakeName, Tag ) diff --git a/api/viewsets.py b/api/viewsets.py index e633c8b7..eef0daa0 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -182,7 +182,7 @@ class SnakeFactViewSet(ListModelMixin, GenericViewSet): ## Routes ### GET /bot/snake-facts - Returns a snake fact in the database. + Returns snake facts from the database. #### Response format >>> [ @@ -203,11 +203,11 @@ class SnakeFactViewSet(ListModelMixin, GenericViewSet): class SnakeIdiomViewSet(ListModelMixin, GenericViewSet): """ - View providing snake idioms for the snake cog. + View providing for the snake cog. ## Routes ### GET /bot/snake-idioms - Returns a snake idiom in the database. + Returns snake idioms from the database. #### Response format >>> [ @@ -217,7 +217,7 @@ class SnakeIdiomViewSet(ListModelMixin, GenericViewSet): #### Status codes - 200: returned on success ## Authentication - Requires and API token + Requires an API token """ serializer_class = SnakeIdiomSerializer -- cgit v1.2.3 From 4c610d1478c76ed22724db18dfa838b7a10d9d55 Mon Sep 17 00:00:00 2001 From: Hasan-Ahmad Date: Sat, 20 Oct 2018 21:55:21 +0100 Subject: added whitespace before headers --- api/viewsets.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'api/viewsets.py') diff --git a/api/viewsets.py b/api/viewsets.py index eef0daa0..6c488747 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -214,8 +214,10 @@ class SnakeIdiomViewSet(ListModelMixin, GenericViewSet): ... {'idiom': 'Sneky snek'}, ... {'idiom': 'Snooky Snake'} ... ] + #### Status codes - 200: returned on success + ## Authentication Requires an API token """ -- cgit v1.2.3 From 05c0de61477c1e30012c6b23cb56527ea4c1fdd7 Mon Sep 17 00:00:00 2001 From: Hasan-Ahmad Date: Sat, 20 Oct 2018 21:58:26 +0100 Subject: fixed linting issues --- api/viewsets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'api/viewsets.py') diff --git a/api/viewsets.py b/api/viewsets.py index 6c488747..24c2aef9 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -217,7 +217,7 @@ class SnakeIdiomViewSet(ListModelMixin, GenericViewSet): #### Status codes - 200: returned on success - + ## Authentication Requires an API token """ -- cgit v1.2.3