Skip to content

Commit

Permalink
Saving my work for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Oct 27, 2023
1 parent fd98109 commit 99be4af
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
11 changes: 11 additions & 0 deletions api_v2/enums.py
Original file line number Diff line number Diff line change
@@ -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")
]
11 changes: 3 additions & 8 deletions api_v2/models/abstracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions api_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 99be4af

Please sign in to comment.