Skip to content

Commit

Permalink
Merge pull request #524 from open5e/523-add-document-filter-to-all-v2…
Browse files Browse the repository at this point in the history
…-endpoints

Adding filter to all relevant document endpoints.
  • Loading branch information
augustjohnson authored Aug 26, 2024
2 parents 0609296 + b9f753a commit 4410e69
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 106 deletions.
2 changes: 0 additions & 2 deletions api_v2/views/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from api_v2 import serializers




class BackgroundFilterSet(FilterSet):
class Meta:
model = models.Background
Expand Down
13 changes: 12 additions & 1 deletion api_v2/views/characterclass.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
"""Viewset and Filterset for the CharacterClass Serializers."""
from rest_framework import viewsets

from django_filters import FilterSet

from api_v2 import models
from api_v2 import serializers


class CharacterClassFilterSet(FilterSet):
class Meta:
model = models.CharacterClass
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact','contains'],
'document__key': ['in','iexact','exact'],
}


class CharacterClassViewSet(viewsets.ReadOnlyModelViewSet):
"""
Expand All @@ -13,4 +24,4 @@ class CharacterClassViewSet(viewsets.ReadOnlyModelViewSet):
"""
queryset = models.CharacterClass.objects.all().order_by('pk')
serializer_class = serializers.CharacterClassSerializer

filterset_class = CharacterClassFilterSet
16 changes: 13 additions & 3 deletions api_v2/views/condition.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from rest_framework import viewsets

from django_filters import FilterSet

from api_v2 import models
from api_v2 import serializers


class ConditionFilterSet(FilterSet):
class Meta:
model = models.Condition
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact','contains'],
'document__key': ['in','iexact','exact'],
}


class ConditionViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of conditions.
retrieve: API endpoint for returning a particular condition.
"""
queryset = models.Condition.objects.all().order_by('pk')
serializer_class = serializers.ConditionSerializer



filterset_class = ConditionFilterSet
22 changes: 22 additions & 0 deletions api_v2/views/creature.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,34 @@ class CreatureViewSet(viewsets.ReadOnlyModelViewSet):
filterset_class = CreatureFilterSet


class CreatureTypeFilterSet(FilterSet):
class Meta:
model = models.CreatureType
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact','contains'],
'document__key': ['in','iexact','exact'],
}


class CreatureTypeViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of creatures types.
retrieve: API endpoint for returning a particular creature type.
"""
queryset = models.CreatureType.objects.all().order_by('pk')
serializer_class = serializers.CreatureTypeSerializer
filterset_class = CreatureTypeFilterSet


class CreatureSetFilterSet(FilterSet):
class Meta:
model = models.CreatureSet
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact','contains'],
'document__key': ['in','iexact','exact'],
}


class CreatureSetViewSet(viewsets.ReadOnlyModelViewSet):
Expand All @@ -78,3 +99,4 @@ class CreatureSetViewSet(viewsets.ReadOnlyModelViewSet):
"""
queryset = models.CreatureSet.objects.all().order_by('pk')
serializer_class = serializers.CreatureSetSerializer
filterset_class = CreatureSetFilterSet
16 changes: 13 additions & 3 deletions api_v2/views/damagetype.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from rest_framework import viewsets

from django_filters import FilterSet

from api_v2 import models
from api_v2 import serializers


class DamageTypeFilterSet(FilterSet):
class Meta:
model = models.DamageType
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact','contains'],
'document__key': ['in','iexact','exact'],
}


class DamageTypeViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of damage types.
retrieve: API endpoint for returning a particular damage type.
"""
queryset = models.DamageType.objects.all().order_by('pk')
serializer_class = serializers.DamageTypeSerializer



filterset_class = DamageTypeFilterSet
17 changes: 14 additions & 3 deletions api_v2/views/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,28 @@

from rest_framework import viewsets

from django_filters import FilterSet

from api_v2 import models
from api_v2 import serializers


class EnvironmentFilterSet(FilterSet):
class Meta:
model = models.Environment
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact','contains'],
'document__key': ['in','iexact','exact'],
}



class EnvironmentViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of environments.
retrieve: API endpoint for returning a particular environment.
"""
queryset = models.Environment.objects.all().order_by('pk')
serializer_class = serializers.EnvironmentSerializer



filterset_class = EnvironmentFilterSet
94 changes: 0 additions & 94 deletions api_v2/views/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,97 +141,3 @@ class ArmorViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.Armor.objects.all().order_by('pk')
serializer_class = serializers.ArmorSerializer
filterset_class = ArmorFilterSet



class FeatFilterSet(FilterSet):
class Meta:
model = models.Feat
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact'],
'document__key': ['in','iexact','exact'],
}

class FeatViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of feats.
retrieve: API endpoint for returning a particular feat.
"""
queryset = models.Feat.objects.all().order_by('pk')
serializer_class = serializers.FeatSerializer
filterset_class = FeatFilterSet


class CreatureFilterSet(FilterSet):

class Meta:
model = models.Creature
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact'],
'document__key': ['in','iexact','exact'],
'size': ['exact'],
'armor_class': ['exact','lt','lte','gt','gte'],
'ability_score_strength': ['exact','lt','lte','gt','gte'],
'ability_score_dexterity': ['exact','lt','lte','gt','gte'],
'ability_score_constitution': ['exact','lt','lte','gt','gte'],
'ability_score_intelligence': ['exact','lt','lte','gt','gte'],
'ability_score_wisdom': ['exact','lt','lte','gt','gte'],
'ability_score_charisma': ['exact','lt','lte','gt','gte'],
'saving_throw_charisma': ['isnull'],
'saving_throw_strength': ['isnull'],
'saving_throw_dexterity': ['isnull'],
'saving_throw_constitution': ['isnull'],
'saving_throw_intelligence': ['isnull'],
'saving_throw_wisdom': ['isnull'],
'saving_throw_charisma': ['isnull'],
'skill_bonus_acrobatics': ['isnull'],
'skill_bonus_animal_handling': ['isnull'],
'skill_bonus_arcana': ['isnull'],
'skill_bonus_athletics': ['isnull'],
'skill_bonus_deception': ['isnull'],
'skill_bonus_history': ['isnull'],
'skill_bonus_insight': ['isnull'],
'skill_bonus_intimidation': ['isnull'],
'skill_bonus_investigation': ['isnull'],
'skill_bonus_medicine': ['isnull'],
'skill_bonus_nature': ['isnull'],
'skill_bonus_perception': ['isnull'],
'skill_bonus_performance': ['isnull'],
'skill_bonus_persuasion': ['isnull'],
'skill_bonus_religion': ['isnull'],
'skill_bonus_sleight_of_hand': ['isnull'],
'skill_bonus_stealth': ['isnull'],
'skill_bonus_survival': ['isnull'],
'passive_perception': ['exact','lt','lte','gt','gte'],
}

class CreatureViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of creatures.
retrieve: API endpoint for returning a particular creature.
"""
queryset = models.Creature.objects.all().order_by('pk')
serializer_class = serializers.CreatureSerializer
filterset_class = CreatureFilterSet


class RaceFilterSet(FilterSet):
class Meta:
model = models.Race
fields = {
'key': ['in', 'iexact', 'exact'],
'name': ['iexact', 'exact'],
'document__key': ['in', 'iexact', 'exact'],
}


class RaceViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of races.
retrieve: API endpoint for returning a particular race.
"""
queryset = models.Race.objects.all().order_by('pk')
serializer_class = serializers.RaceSerializer
filterset_class = RaceFilterSet
13 changes: 13 additions & 0 deletions api_v2/views/size.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
from rest_framework import viewsets

from django_filters import FilterSet

from api_v2 import models
from api_v2 import serializers


class SizeFilterSet(FilterSet):
class Meta:
model = models.Size
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact','contains'],
'document__key': ['in','iexact','exact'],
}


class SizeViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of damage types.
retrieve: API endpoint for returning a particular damage type.
"""
queryset = models.Size.objects.all().order_by('pk')
serializer_class = serializers.SizeSerializer
filterset_class = SizeFilterSet



10 changes: 10 additions & 0 deletions api_v2/views/spell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@
from api_v2 import serializers


class SpellFilterSet(FilterSet):
class Meta:
model = models.Spell
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact','contains'],
'document__key': ['in','iexact','exact'],
}

class SpellViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of spells.
retrieve: API endpoint for returning a particular spell.
"""
queryset = models.Spell.objects.all().order_by('pk')
serializer_class = serializers.SpellSerializer
filterset_class = SpellFilterSet

0 comments on commit 4410e69

Please sign in to comment.