diff --git a/api_v2/enums.py b/api_v2/enums.py new file mode 100644 index 00000000..a524baee --- /dev/null +++ b/api_v2/enums.py @@ -0,0 +1,11 @@ +"""This file is meant to store enumerations for standard values.""" + + +SIZE_CHOICES = [ + (1, "Tiny"), + (2, "Small"), + (3, "Medium"), + (4, "Large"), + (5, "Huge"), + (6, "Gargantuan") +] diff --git a/api_v2/models/abstracts.py b/api_v2/models/abstracts.py index 07dcca0b..58131f8c 100644 --- a/api_v2/models/abstracts.py +++ b/api_v2/models/abstracts.py @@ -4,6 +4,7 @@ from django.core.validators import MaxValueValidator, MinValueValidator from django.template.defaultfilters import slugify +from api_v2 import enums class HasName(models.Model): @@ -48,14 +49,8 @@ class Object(HasName): Basically it describes any sort of matter in the 5e world. """ - # Enumerating sizes, so they are sortable. - SIZE_CHOICES = [ - (1, "Tiny"), - (2, "Small"), - (3, "Medium"), - (4, "Large"), - (5, "Huge"), - (6, "Gargantuan")] + # Enumerating sizes + SIZE_CHOICES = enums.SIZE_CHOICES # Setting a reasonable maximum for AC. ARMOR_CLASS_MAXIMUM = 100 diff --git a/api_v2/views.py b/api_v2/views.py index 05914471..2ee1dbb3 100644 --- a/api_v2/views.py +++ b/api_v2/views.py @@ -3,9 +3,12 @@ from django_filters.rest_framework import DjangoFilterBackend import django_filters from rest_framework import viewsets +from rest_framework import views +from rest_framework.response import Response from api_v2 import models from api_v2 import serializers +from api_v2 import enums from api.schema_generator import CustomSchema @@ -259,5 +262,9 @@ class RaceViewSet(viewsets.ReadOnlyModelViewSet): filterset_class = RaceFilterSet - - +class EnumView(views.APIView): + def get(self, request, format=None): + """ + Return a list of all enums. + """ + return Response(enums.SIZE_CHOICES) \ No newline at end of file diff --git a/server/urls.py b/server/urls.py index 3bddfd09..dfa0b701 100644 --- a/server/urls.py +++ b/server/urls.py @@ -76,7 +76,8 @@ # Versioned API routes (above routes default to v1) re_path(r'^v1/', include(router.urls)), re_path(r'^v1/search/', include('haystack.urls')), - re_path(r'^v2/', include(router_v2.urls)) + re_path(r'^v2/', include(router_v2.urls)), + re_path(r'^v2/enums/',views_v2.EnumView.as_view()) ] if settings.DEBUG is True: