From 94004907d5c4a32fcff06fb4f4a4af2c52ada0e5 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Nov 2023 15:55:26 -0500 Subject: [PATCH 1/3] Adding conditions in. --- api_v2/admin.py | 4 +++- api_v2/migrations/0022_condition.py | 26 ++++++++++++++++++++++++++ api_v2/models/__init__.py | 4 +++- api_v2/models/condition.py | 14 ++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 api_v2/migrations/0022_condition.py create mode 100644 api_v2/models/condition.py diff --git a/api_v2/admin.py b/api_v2/admin.py index 87cb0ad5..80e3f967 100644 --- a/api_v2/admin.py +++ b/api_v2/admin.py @@ -99,4 +99,6 @@ class LanguageAdmin(admin.ModelAdmin): admin.site.register(Language) -admin.site.register(Alignment) \ No newline at end of file +admin.site.register(Alignment) + +admin.site.register(Condition) \ No newline at end of file diff --git a/api_v2/migrations/0022_condition.py b/api_v2/migrations/0022_condition.py new file mode 100644 index 00000000..31507e44 --- /dev/null +++ b/api_v2/migrations/0022_condition.py @@ -0,0 +1,26 @@ +# Generated by Django 3.2.20 on 2023-11-04 20:55 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('api_v2', '0021_auto_20231104_1919'), + ] + + operations = [ + migrations.CreateModel( + name='Condition', + fields=[ + ('name', models.CharField(help_text='Name of the item.', max_length=100)), + ('desc', models.TextField(help_text='Description of the game content item. Markdown.')), + ('key', models.CharField(help_text='Unique key for the Item.', max_length=100, primary_key=True, serialize=False)), + ('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api_v2.document')), + ], + options={ + 'verbose_name_plural': 'conditions', + }, + ), + ] diff --git a/api_v2/models/__init__.py b/api_v2/models/__init__.py index b3457c1d..7b8a782c 100644 --- a/api_v2/models/__init__.py +++ b/api_v2/models/__init__.py @@ -34,4 +34,6 @@ from .language import Language -from .alignment import Alignment \ No newline at end of file +from .alignment import Alignment + +from .condition import Condition \ No newline at end of file diff --git a/api_v2/models/condition.py b/api_v2/models/condition.py new file mode 100644 index 00000000..c533e1c1 --- /dev/null +++ b/api_v2/models/condition.py @@ -0,0 +1,14 @@ +"""The model for a condition.""" +from django.db import models +from .abstracts import HasName, HasDescription +from .document import FromDocument + +class Condition(HasName, HasDescription, FromDocument): + """ + This is the model for a condition. + """ + + class Meta: + """To assist with the UI layer.""" + + verbose_name_plural = "conditions" From 3e5014b9df0be418499ab98ccbb303a4d45dd83f Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Nov 2023 16:20:09 -0500 Subject: [PATCH 2/3] Condition data. --- .../wizards-of-the-coast/srd/Condition.json | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 data/v2/wizards-of-the-coast/srd/Condition.json diff --git a/data/v2/wizards-of-the-coast/srd/Condition.json b/data/v2/wizards-of-the-coast/srd/Condition.json new file mode 100644 index 00000000..60b556eb --- /dev/null +++ b/data/v2/wizards-of-the-coast/srd/Condition.json @@ -0,0 +1,137 @@ +[ +{ + "model": "api_v2.condition", + "pk": "blinded", + "fields": { + "name": "Blinded", + "desc": "* A blinded creature can't see and automatically fails any ability check that requires sight.\r\n* Attack rolls against the creature have advantage, and the creature’s attack rolls have disadvantage.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "charmed", + "fields": { + "name": "Charmed", + "desc": "* A charmed creature can’t attack the charmer or target the charmer with harmful abilities or magical effects.\r\n* The charmer has advantage on any ability check to interact socially with the creature.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "deafened", + "fields": { + "name": "Deafened", + "desc": "* A deafened creature can’t hear and automatically fails any ability check that requires hearing.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "exhaustion", + "fields": { + "name": "Exhaustion", + "desc": "Some special abilities and environmental hazards, such as starvation and the long-­‐term effects of freezing or scorching temperatures, can lead to a special condition called exhaustion. Exhaustion is measured in six levels. An effect can give a creature one or more levels of exhaustion, as specified in the effect’s description.\r\n\r\n| Level | Effect |\r\n| --- | --- |\r\n| 1 | Disadvantage on ability checks | \r\n| 2 | Speed halved | \r\n| 3 | Disadvantage on attack rolls and saving throws | \r\n| 4 | Hit point maximum halved | \r\n| 5 | Speed reduced to 0 | \r\n| 6 | Death |\r\n\r\nIf an already exhausted creature suffers another effect that causes exhaustion, its current level of exhaustion increases by the amount specified in the effect’s description.\r\nA creature suffers the effect of its current level of exhaustion as well as all lower levels. For example, a creature suffering level 2 exhaustion has its speed halved and has disadvantage on ability checks. \r\nAn effect that removes exhaustion reduces its level as specified in the effect’s description, with all exhaustion effects ending if a creature’s exhaustion level is reduced below 1.\r\nFinishing a long rest reduces a creature’s exhaustion level by 1, provided that the creature has also ingested some food and drink.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "frightened", + "fields": { + "name": "Frightened", + "desc": "* A frightened creature has disadvantage on ability checks and attack rolls while the source of its fear\r\nis within line of sight.\r\n* The creature can’t willingly move closer to the source of its fear.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "grappled", + "fields": { + "name": "Grappled", + "desc": "* A grappled creature’s speed becomes 0, and it can’t benefit from any bonus to its speed. \r\n* The condition ends if the grappler is incapacitated (see the condition).\r\n* The condition also ends if an effect removes the grappled creature from the reach of the grappler or grappling effect, such as when a creature is hurled away by the *thunder-­wave* spell.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "incapacitated", + "fields": { + "name": "Incapacitated", + "desc": "* An incapacitated creature can’t take actions or reactions.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "invisible", + "fields": { + "name": "Invisible", + "desc": "* An invisible creature is impossible to see without the aid of magic or a special sense. For the purpose of hiding, the creature is heavily obscured. The creature’s location can be detected by any noise it makes or any tracks it leaves.\r\n* Attack rolls against the creature have disadvantage, and the creature’s attack rolls have advantage.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "paralyzed", + "fields": { + "name": "Paralyzed", + "desc": "* A paralyzed creature is incapacitated (see the condition) and can’t move or speak. \r\n* The creature automatically fails Strength and Dexterity saving throws.\r\n* Attack rolls against the creature have advantage. \r\n* Any attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "petrified", + "fields": { + "name": "Petrified", + "desc": "* A petrified creature is transformed, along with any nonmagical object it is wearing or carrying, into a solid inanimate substance (usually stone). Its weight increases by a factor of ten, and it ceases aging.\r\n* The creature is incapacitated (see the condition), can’t move or speak, and is unaware of its surroundings.\r\n* Attack rolls against the creature have advantage.\r\n* The creature automatically fails Strength and Dexterity saving throws.\r\n* The creature has resistance to all damage.\r\n* The creature is immune to poison and disease, although a poison or disease already in its system\r\nis suspended, not neutralized.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "poisoned", + "fields": { + "name": "Poisoned", + "desc": "A poisoned creature has disadvantage on attack rolls and ability checks.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "prone", + "fields": { + "name": "Prone", + "desc": "* A prone creature’s only movement option is to crawl, unless it stands up and thereby ends the condition.\r\n* The creature has disadvantage on attack rolls. \r\n* An attack roll against the creature has advantage if the attacker is within 5 feet of the creature. Otherwise, the attack roll has disadvantage.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "restrained", + "fields": { + "name": "Restrained", + "desc": "* A restrained creature’s speed becomes 0, and it can’t benefit from any bonus to its speed.\r\n* Attack rolls against the creature have advantage, and the creature’s attack rolls have disadvantage.\r\n* The creature has disadvantage on Dexterity saving throws.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "stunned", + "fields": { + "name": "Stunned", + "desc": "* A stunned creature is incapacitated (see the condition), can’t move, and can speak only falteringly.\r\n* The creature automatically fails Strength and Dexterity saving throws.\r\n* Attack rolls against the creature have advantage.", + "document": "srd" + } +}, +{ + "model": "api_v2.condition", + "pk": "unconscious", + "fields": { + "name": "Unconscious", + "desc": "* An unconscious creature is incapacitated (see the condition), can’t move or speak, and is unaware of its surroundings\r\n* The creature drops whatever it’s holding and falls prone.\r\n* The creature automatically fails Strength and Dexterity saving throws.\r\n* Attack rolls against the creature have advantage.\r\n* Any attack that hits the creature is a critical hit if the attacker is within 5 feet of the creature.", + "document": "srd" + } +} +] From 530243ed750bb9c056dfab8e70997475aa16945d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 4 Nov 2023 16:23:44 -0500 Subject: [PATCH 3/3] Exposing conditions. --- api_v2/serializers/__init__.py | 4 +++- api_v2/serializers/condition.py | 14 ++++++++++++++ api_v2/views/__init__.py | 4 +++- api_v2/views/condition.py | 16 ++++++++++++++++ server/urls.py | 9 +++++---- 5 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 api_v2/serializers/condition.py create mode 100644 api_v2/views/condition.py diff --git a/api_v2/serializers/__init__.py b/api_v2/serializers/__init__.py index fe0a218e..ec1addde 100644 --- a/api_v2/serializers/__init__.py +++ b/api_v2/serializers/__init__.py @@ -26,4 +26,6 @@ from .language import LanguageSerializer -from .alignment import AlignmentSerializer \ No newline at end of file +from .alignment import AlignmentSerializer + +from .condition import ConditionSerializer \ No newline at end of file diff --git a/api_v2/serializers/condition.py b/api_v2/serializers/condition.py new file mode 100644 index 00000000..70c95ebe --- /dev/null +++ b/api_v2/serializers/condition.py @@ -0,0 +1,14 @@ +"""Serializer for the Condition model.""" + +from rest_framework import serializers + +from api_v2 import models + +from .abstracts import GameContentSerializer + +class ConditionSerializer(GameContentSerializer): + key = serializers.ReadOnlyField() + + class Meta: + model = models.Condition + fields = '__all__' diff --git a/api_v2/views/__init__.py b/api_v2/views/__init__.py index b206f400..c924d1be 100644 --- a/api_v2/views/__init__.py +++ b/api_v2/views/__init__.py @@ -23,4 +23,6 @@ from .language import LanguageFilterSet, LanguageViewSet -from .alignment import AlignmentFilterSet, AlignmentViewSet \ No newline at end of file +from .alignment import AlignmentFilterSet, AlignmentViewSet + +from .condition import ConditionViewSet \ No newline at end of file diff --git a/api_v2/views/condition.py b/api_v2/views/condition.py new file mode 100644 index 00000000..e76e2df2 --- /dev/null +++ b/api_v2/views/condition.py @@ -0,0 +1,16 @@ +from rest_framework import viewsets + +from api_v2 import models +from api_v2 import serializers + + +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 + + + diff --git a/server/urls.py b/server/urls.py index 9db6d9e2..a643319b 100644 --- a/server/urls.py +++ b/server/urls.py @@ -64,10 +64,11 @@ router_v2.register(r'feats',views_v2.FeatViewSet) router_v2.register(r'races',views_v2.RaceViewSet) router_v2.register(r'creatures',views_v2.CreatureViewSet) - router_v2.register(r'creaturetype',views_v2.CreatureTypeViewSet) - router_v2.register(r'damagetype',views_v2.DamageTypeViewSet) - router_v2.register(r'language',views_v2.LanguageViewSet) - router_v2.register(r'alignment',views_v2.AlignmentViewSet) + router_v2.register(r'creaturetypes',views_v2.CreatureTypeViewSet) + router_v2.register(r'damagetypes',views_v2.DamageTypeViewSet) + router_v2.register(r'languages',views_v2.LanguageViewSet) + router_v2.register(r'alignments',views_v2.AlignmentViewSet) + router_v2.register(r'conditions',views_v2.ConditionViewSet) # Wire up our API using automatic URL routing. # Additionally, we include login URLs for the browsable API.