From 0766dab8306d24b22550e1a4a054ff3f2956a0b1 Mon Sep 17 00:00:00 2001 From: Hasan-Ahmad Date: Mon, 22 Oct 2018 11:22:48 +0100 Subject: Added special snakes api --- api/viewsets.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'api/viewsets.py') diff --git a/api/viewsets.py b/api/viewsets.py index 24c2aef9..098b34f6 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -11,15 +11,16 @@ from rest_framework_bulk import BulkCreateModelMixin from .models import ( DocumentationLink, Member, - OffTopicChannelName, SnakeFact, - SnakeIdiom, SnakeName, + OffTopicChannelName, + SnakeFact, SnakeIdiom, + SpecialSnake, SnakeName, Tag ) from .serializers import ( + OffTopicChannelNameSerializer, DocumentationLinkSerializer, MemberSerializer, - OffTopicChannelNameSerializer, SnakeFactSerializer, - SnakeIdiomSerializer, SnakeNameSerializer, - TagSerializer + SnakeFactSerializer, SnakeIdiomSerializer, + SnakeNameSerializer, SpecialSnakeSerializer, TagSerializer ) @@ -282,6 +283,11 @@ class SnakeNameViewSet(ViewSet): return Response({}) +class SpecialSnakeViewSet(ListModelMixin, GenericViewSet): + serializer_class = SpecialSnakeSerializer + queryset = SpecialSnake.objects.all() + + class TagViewSet(ModelViewSet): """ View providing CRUD operations on tags shown by our bot. -- cgit v1.2.3 From cac5ea311608508585437481ccb184e376eba36c Mon Sep 17 00:00:00 2001 From: Hasan-Ahmad Date: Wed, 24 Oct 2018 14:43:00 +0100 Subject: Added special snake documentation, fixed linting errors --- api/serializers.py | 6 +++--- api/viewsets.py | 35 +++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) (limited to 'api/viewsets.py') diff --git a/api/serializers.py b/api/serializers.py index 6c878c5d..69ae1da7 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -2,10 +2,10 @@ from rest_framework.serializers import ModelSerializer, PrimaryKeyRelatedField from rest_framework_bulk import BulkSerializerMixin from .models import ( - DocumentationLink, + DocumentationLink, Member, OffTopicChannelName, - Role, SnakeFact, - SnakeIdiom, SnakeName, + Role, SnakeFact, + SnakeIdiom, SnakeName, SpecialSnake, Tag ) diff --git a/api/viewsets.py b/api/viewsets.py index 098b34f6..70fc96f8 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -11,15 +11,15 @@ from rest_framework_bulk import BulkCreateModelMixin from .models import ( DocumentationLink, Member, - OffTopicChannelName, + OffTopicChannelName, SnakeFact, SnakeIdiom, - SpecialSnake, SnakeName, + SnakeName, SpecialSnake, Tag ) from .serializers import ( - OffTopicChannelNameSerializer, - DocumentationLinkSerializer, MemberSerializer, - SnakeFactSerializer, SnakeIdiomSerializer, + DocumentationLinkSerializer, + MemberSerializer, OffTopicChannelNameSerializer, + SnakeFactSerializer, SnakeIdiomSerializer, SnakeNameSerializer, SpecialSnakeSerializer, TagSerializer ) @@ -204,7 +204,7 @@ class SnakeFactViewSet(ListModelMixin, GenericViewSet): class SnakeIdiomViewSet(ListModelMixin, GenericViewSet): """ - View providing for the snake cog. + View providing snake idioms for the snake cog. ## Routes ### GET /bot/snake-idioms @@ -284,6 +284,29 @@ class SnakeNameViewSet(ViewSet): 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() -- cgit v1.2.3 From aebf48cff6e41eb6d8dde695b10380da4e57d733 Mon Sep 17 00:00:00 2001 From: Hasan-Ahmad Date: Thu, 25 Oct 2018 21:02:42 +0100 Subject: code presentasion and help text on models --- api/migrations/0014_auto_20181025_1959.py | 23 +++++++++++++++++++++++ api/models.py | 12 ++++++++---- api/tests/test_models.py | 3 ++- api/viewsets.py | 11 ++++++----- 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 api/migrations/0014_auto_20181025_1959.py (limited to 'api/viewsets.py') diff --git a/api/migrations/0014_auto_20181025_1959.py b/api/migrations/0014_auto_20181025_1959.py new file mode 100644 index 00000000..3599d2cd --- /dev/null +++ b/api/migrations/0014_auto_20181025_1959.py @@ -0,0 +1,23 @@ +# Generated by Django 2.1.2 on 2018-10-25 19:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0013_specialsnake_image'), + ] + + operations = [ + migrations.AlterField( + model_name='specialsnake', + name='info', + field=models.TextField(help_text='Info about a special snake.'), + ), + migrations.AlterField( + model_name='specialsnake', + name='name', + field=models.CharField(help_text='A special snake name.', max_length=140, primary_key=True, serialize=False), + ), + ] diff --git a/api/models.py b/api/models.py index 2ba50adf..eb9c2e16 100644 --- a/api/models.py +++ b/api/models.py @@ -104,12 +104,16 @@ class SnakeName(ModelReprMixin, models.Model): class SpecialSnake(ModelReprMixin, models.Model): - """A special snake used by the bot's snake cog.""" + """A special snake's name, info and image from our database used by the bot's snake cog.""" name = models.CharField( - max_length=140, primary_key=True - ) - info = models.TextField() + max_length=140, + primary_key=True, + help_text='A special snake name.' + ) + info = models.TextField( + help_text='Info about a special snake.' + ) image = models.URLField() def __str__(self): diff --git a/api/tests/test_models.py b/api/tests/test_models.py index 7dea68b5..a1561a07 100644 --- a/api/tests/test_models.py +++ b/api/tests/test_models.py @@ -34,7 +34,8 @@ class StringDunderMethodTests(SimpleTestCase): SnakeIdiom(idiom='snake snacks'), SnakeName(name='python', scientific='3'), SpecialSnake(name='Pythagoras Pythonista', - info='The only python snake that is born a triangle'), + info='The only python snake that is born a triangle' + ), Role( id=5, name='test role', colour=0x5, permissions=0 diff --git a/api/viewsets.py b/api/viewsets.py index 70fc96f8..08660810 100644 --- a/api/viewsets.py +++ b/api/viewsets.py @@ -20,7 +20,8 @@ from .serializers import ( DocumentationLinkSerializer, MemberSerializer, OffTopicChannelNameSerializer, SnakeFactSerializer, SnakeIdiomSerializer, - SnakeNameSerializer, SpecialSnakeSerializer, TagSerializer + SnakeNameSerializer, SpecialSnakeSerializer, + TagSerializer ) @@ -294,10 +295,10 @@ class SpecialSnakeViewSet(ListModelMixin, GenericViewSet): #### Response Format >>> [ ... { - ... 'name':'Snakky sneakatus', - ... 'info':'Scary snek', - ... 'image':'https://discordapp.com/assets/53ef346458017da2062aca5c7955946b.svg' - ... }, + ... 'name': 'Snakky sneakatus', + ... 'info': 'Scary snek', + ... 'image': 'https://discordapp.com/assets/53ef346458017da2062aca5c7955946b.svg' + ... } ... ] #### Status codes -- cgit v1.2.3