Skip to content

Commit 921a6cc

Browse files
authored
Implement QA fixes on /v2/creatures endpoint (#717)
* updated CreatureTraits serializer, rmv'd CreatureTraits View * updated field names on CreatureActionSerializer for better readibility * refactored action usage limits on CreatureActionSerializer * renamed 'legendary_cost' to 'legendary_action_cost' on CreatureActionSerializer * update tests * rmvd unneeded 'parent' field from CreatureAttackActionSerializer
1 parent 2379e38 commit 921a6cc

8 files changed

+135
-228
lines changed

api_v2/serializers/creature.py

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,59 @@ class CreatureActionAttackSerializer(serializers.ModelSerializer):
2222

2323
class Meta:
2424
model = models.CreatureActionAttack
25-
fields = '__all__'
25+
fields = [
26+
'name',
27+
'attack_type',
28+
'to_hit_mod',
29+
'reach',
30+
'range',
31+
'long_range',
32+
'target_creature_only',
33+
'damage_die_count',
34+
'damage_die_type',
35+
'damage_bonus',
36+
'damage_type',
37+
'extra_damage_die_count',
38+
'extra_damage_die_type',
39+
'extra_damage_bonus',
40+
'extra_damage_type',
41+
'distance_unit',
42+
]
2643

2744
# todo: type is any
2845
@extend_schema_field(OpenApiTypes.STR)
2946
def get_distance_unit(self, CreatureActionAttack):
3047
return CreatureActionAttack.get_distance_unit
3148

32-
3349
class CreatureActionSerializer(serializers.ModelSerializer):
34-
key = serializers.ReadOnlyField()
3550
attacks = CreatureActionAttackSerializer(many=True, read_only=True)
51+
usage_limits = serializers.SerializerMethodField()
52+
53+
# rename model fields to improve readibility of JSON
54+
order_in_statblock = serializers.IntegerField(source='order')
55+
limited_to_form = serializers.CharField(source='form_condition')
56+
legendary_action_cost = serializers.IntegerField(source='legendary_cost')
57+
3658
class Meta:
3759
model = models.CreatureAction
38-
fields = '__all__'
60+
fields = [
61+
'name',
62+
'desc',
63+
'attacks',
64+
'action_type',
65+
'order_in_statblock',
66+
'legendary_action_cost',
67+
'limited_to_form',
68+
'usage_limits'
69+
]
3970

71+
# Gathers 'uses_type' and 'uses_param' into a single 'usage_limits' obj.
72+
def get_usage_limits(self, obj):
73+
if obj.uses_type and obj.uses_param:
74+
return {
75+
'type': obj.uses_type,
76+
'param': obj.uses_param
77+
}
4078

4179
class CreatureTypeSerializer(GameContentSerializer):
4280
'''Serializer for the Creature Type object'''
@@ -59,11 +97,9 @@ class Meta:
5997

6098
class CreatureTraitSerializer(GameContentSerializer):
6199
'''Serializer for the Creature Trait object'''
62-
key = serializers.ReadOnlyField()
63-
64100
class Meta:
65101
model = models.CreatureTrait
66-
fields = '__all__'
102+
fields = ['name', 'desc']
67103

68104
class CreatureLanguageSerializer(GameContentSerializer):
69105
as_string = serializers.CharField(source="languages_desc")

api_v2/tests/responses/TestObjects.test_creature_ancient_example.approved.json

Lines changed: 37 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,20 @@
2222
"extra_damage_die_count": null,
2323
"extra_damage_die_type": null,
2424
"extra_damage_type": "thunder",
25-
"key": "srd_ancient-red-dragon_bite_bite-attack",
2625
"long_range": null,
2726
"name": "Bite attack",
28-
"parent": "srd_ancient-red-dragon_bite",
2927
"range": null,
3028
"reach": 15.0,
3129
"target_creature_only": false,
3230
"to_hit_mod": 17
3331
}
3432
],
3533
"desc": "Melee Weapon Attack: +17 to hit, reach 15 ft., one target. Hit: 21 (2d10 + 10) piercing damage plus 14 (4d6) fire damage.",
36-
"form_condition": null,
37-
"key": "srd_ancient-red-dragon_bite",
38-
"legendary_cost": 1,
34+
"legendary_action_cost": 1,
35+
"limited_to_form": null,
3936
"name": "Bite",
40-
"order": 1,
41-
"parent": "srd_ancient-red-dragon",
42-
"uses_param": null,
43-
"uses_type": null
37+
"order_in_statblock": 1,
38+
"usage_limits": null
4439
},
4540
{
4641
"action_type": "ACTION",
@@ -56,77 +51,60 @@
5651
"extra_damage_die_count": null,
5752
"extra_damage_die_type": null,
5853
"extra_damage_type": null,
59-
"key": "srd_ancient-red-dragon_claw_claw-attack",
6054
"long_range": null,
6155
"name": "Claw attack",
62-
"parent": "srd_ancient-red-dragon_claw",
6356
"range": null,
6457
"reach": 10.0,
6558
"target_creature_only": false,
6659
"to_hit_mod": 17
6760
}
6861
],
6962
"desc": "Melee Weapon Attack: +17 to hit, reach 10 ft., one target. Hit: 17 (2d6 + 10) slashing damage.",
70-
"form_condition": null,
71-
"key": "srd_ancient-red-dragon_claw",
72-
"legendary_cost": 1,
63+
"legendary_action_cost": 1,
64+
"limited_to_form": null,
7365
"name": "Claw",
74-
"order": 2,
75-
"parent": "srd_ancient-red-dragon",
76-
"uses_param": null,
77-
"uses_type": null
66+
"order_in_statblock": 2,
67+
"usage_limits": null
7868
},
7969
{
8070
"action_type": "LEGENDARY_ACTION",
8171
"attacks": [],
8272
"desc": "The dragon makes a Wisdom (Perception) check.",
83-
"form_condition": null,
84-
"key": "srd_ancient-red-dragon_detect",
85-
"legendary_cost": 1,
73+
"legendary_action_cost": 1,
74+
"limited_to_form": null,
8675
"name": "Detect",
87-
"order": 0,
88-
"parent": "srd_ancient-red-dragon",
89-
"uses_param": null,
90-
"uses_type": null
76+
"order_in_statblock": 0,
77+
"usage_limits": null
9178
},
9279
{
9380
"action_type": "ACTION",
9481
"attacks": [],
9582
"desc": "The dragon exhales fire in a 90-foot cone. Each creature in that area must make a DC 24 Dexterity saving throw, taking 91 (26d6) fire damage on a failed save, or half as much damage on a successful one.",
96-
"form_condition": null,
97-
"key": "srd_ancient-red-dragon_fire-breath",
98-
"legendary_cost": 1,
83+
"legendary_action_cost": 1,
84+
"limited_to_form": null,
9985
"name": "Fire Breath",
100-
"order": 5,
101-
"parent": "srd_ancient-red-dragon",
102-
"uses_param": null,
103-
"uses_type": null
86+
"order_in_statblock": 5,
87+
"usage_limits": null
10488
},
10589
{
10690
"action_type": "ACTION",
10791
"attacks": [],
10892
"desc": "Each creature of the dragon's choice that is within 120 feet of the dragon and aware of it must succeed on a DC 21 Wisdom saving throw or become frightened for 1 minute. A creature can repeat the saving throw at the end of each of its turns, ending the effect on itself on a success. If a creature's saving throw is successful or the effect ends for it, the creature is immune to the dragon's Frightful Presence for the next 24 hours.",
109-
"form_condition": null,
110-
"key": "srd_ancient-red-dragon_frightful-presence",
111-
"legendary_cost": 1,
93+
"legendary_action_cost": 1,
94+
"limited_to_form": null,
11295
"name": "Frightful Presence",
113-
"order": 4,
114-
"parent": "srd_ancient-red-dragon",
115-
"uses_param": null,
116-
"uses_type": null
96+
"order_in_statblock": 4,
97+
"usage_limits": null
11798
},
11899
{
119100
"action_type": "ACTION",
120101
"attacks": [],
121102
"desc": "The dragon can use its Frightful Presence. It then makes three attacks: one with its bite and two with its claws.",
122-
"form_condition": null,
123-
"key": "srd_ancient-red-dragon_multiattack",
124-
"legendary_cost": 1,
103+
"legendary_action_cost": 1,
104+
"limited_to_form": null,
125105
"name": "Multiattack",
126-
"order": 0,
127-
"parent": "srd_ancient-red-dragon",
128-
"uses_param": null,
129-
"uses_type": null
106+
"order_in_statblock": 0,
107+
"usage_limits": null
130108
},
131109
{
132110
"action_type": "ACTION",
@@ -142,51 +120,40 @@
142120
"extra_damage_die_count": null,
143121
"extra_damage_die_type": null,
144122
"extra_damage_type": null,
145-
"key": "srd_ancient-red-dragon_tail_tail-attack",
146123
"long_range": null,
147124
"name": "Tail attack",
148-
"parent": "srd_ancient-red-dragon_tail",
149125
"range": null,
150126
"reach": 20.0,
151127
"target_creature_only": false,
152128
"to_hit_mod": 17
153129
}
154130
],
155131
"desc": "Melee Weapon Attack: +17 to hit, reach 20 ft., one target. Hit: 19 (2d8 + 10) bludgeoning damage.",
156-
"form_condition": null,
157-
"key": "srd_ancient-red-dragon_tail",
158-
"legendary_cost": 1,
132+
"legendary_action_cost": 1,
133+
"limited_to_form": null,
159134
"name": "Tail",
160-
"order": 3,
161-
"parent": "srd_ancient-red-dragon",
162-
"uses_param": null,
163-
"uses_type": null
135+
"order_in_statblock": 3,
136+
"usage_limits": null
164137
},
165138
{
166139
"action_type": "LEGENDARY_ACTION",
167140
"attacks": [],
168141
"desc": "The dragon makes a tail attack.",
169-
"form_condition": null,
170-
"key": "srd_ancient-red-dragon_tail-attack",
171-
"legendary_cost": 1,
142+
"legendary_action_cost": 1,
143+
"limited_to_form": null,
172144
"name": "Tail Attack",
173-
"order": 1,
174-
"parent": "srd_ancient-red-dragon",
175-
"uses_param": null,
176-
"uses_type": null
145+
"order_in_statblock": 1,
146+
"usage_limits": null
177147
},
178148
{
179149
"action_type": "LEGENDARY_ACTION",
180150
"attacks": [],
181151
"desc": "The dragon beats its wings. Each creature within 15 ft. of the dragon must succeed on a DC 25 Dexterity saving throw or take 17 (2d6 + 10) bludgeoning damage and be knocked prone. The dragon can then fly up to half its flying speed.",
182-
"form_condition": null,
183-
"key": "srd_ancient-red-dragon_wing-attack",
184-
"legendary_cost": 2,
152+
"legendary_action_cost": 2,
153+
"limited_to_form": null,
185154
"name": "Wing Attack",
186-
"order": 2,
187-
"parent": "srd_ancient-red-dragon",
188-
"uses_param": null,
189-
"uses_type": null
155+
"order_in_statblock": 2,
156+
"usage_limits": null
190157
}
191158
],
192159
"alignment": "chaotic evil",
@@ -333,11 +300,7 @@
333300
"traits": [
334301
{
335302
"desc": "If the dragon fails a saving throw, it can choose to succeed instead.",
336-
"key": "srd_ancient-red-dragon_legendary-resistance-3day",
337-
"name": "Legendary Resistance (3/Day)",
338-
"parent": "http://localhost:8000/v2/creatures/srd_ancient-red-dragon/",
339-
"type": null,
340-
"url": "http://localhost:8000/v2/creaturetraits/srd_ancient-red-dragon_legendary-resistance-3day/"
303+
"name": "Legendary Resistance (3/Day)"
341304
}
342305
],
343306
"tremorsense_range": null,

api_v2/tests/responses/TestObjects.test_creature_goblin_example.approved.json

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,20 @@
2222
"extra_damage_die_count": null,
2323
"extra_damage_die_type": null,
2424
"extra_damage_type": null,
25-
"key": "srd_goblin_scimitar_scimitar-attack",
2625
"long_range": null,
2726
"name": "Scimitar attack",
28-
"parent": "srd_goblin_scimitar",
2927
"range": null,
3028
"reach": 5.0,
3129
"target_creature_only": false,
3230
"to_hit_mod": 4
3331
}
3432
],
3533
"desc": "Melee Weapon Attack: +4 to hit, reach 5 ft., one target. Hit: 5 (1d6 + 2) slashing damage.",
36-
"form_condition": null,
37-
"key": "srd_goblin_scimitar",
38-
"legendary_cost": 1,
34+
"legendary_action_cost": 1,
35+
"limited_to_form": null,
3936
"name": "Scimitar",
40-
"order": 0,
41-
"parent": "srd_goblin",
42-
"uses_param": null,
43-
"uses_type": null
37+
"order_in_statblock": 0,
38+
"usage_limits": null
4439
},
4540
{
4641
"action_type": "ACTION",
@@ -56,25 +51,20 @@
5651
"extra_damage_die_count": null,
5752
"extra_damage_die_type": null,
5853
"extra_damage_type": null,
59-
"key": "srd_goblin_shortbow_shortbow-attack",
6054
"long_range": 320.0,
6155
"name": "Shortbow attack",
62-
"parent": "srd_goblin_shortbow",
6356
"range": 80.0,
6457
"reach": null,
6558
"target_creature_only": false,
6659
"to_hit_mod": 4
6760
}
6861
],
6962
"desc": "Ranged Weapon Attack: +4 to hit, range 80/320 ft., one target. Hit: 5 (1d6 + 2) piercing damage.",
70-
"form_condition": null,
71-
"key": "srd_goblin_shortbow",
72-
"legendary_cost": 1,
63+
"legendary_action_cost": 1,
64+
"limited_to_form": null,
7365
"name": "Shortbow",
74-
"order": 1,
75-
"parent": "srd_goblin",
76-
"uses_param": null,
77-
"uses_type": null
66+
"order_in_statblock": 1,
67+
"usage_limits": null
7868
}
7969
],
8070
"alignment": "neutral evil",
@@ -262,11 +252,7 @@
262252
"traits": [
263253
{
264254
"desc": "The goblin can take the Disengage or Hide action as a bonus action on each of its turns.",
265-
"key": "srd_goblin_nimble-escape",
266-
"name": "Nimble Escape",
267-
"parent": "http://localhost:8000/v2/creatures/srd_goblin/",
268-
"type": null,
269-
"url": "http://localhost:8000/v2/creaturetraits/srd_goblin_nimble-escape/"
255+
"name": "Nimble Escape"
270256
}
271257
],
272258
"tremorsense_range": null,

api_v2/tests/responses/TestObjects.test_creature_guard_example.approved.json

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
"extra_damage_die_count": null,
2323
"extra_damage_die_type": null,
2424
"extra_damage_type": null,
25-
"key": "srd_guard_spear_spear-melee-attack",
2625
"long_range": 60.0,
2726
"name": "Spear Melee attack",
28-
"parent": "srd_guard_spear",
2927
"range": 20.0,
3028
"reach": 5.0,
3129
"target_creature_only": false,
@@ -42,25 +40,20 @@
4240
"extra_damage_die_count": null,
4341
"extra_damage_die_type": null,
4442
"extra_damage_type": null,
45-
"key": "srd_guard_spear_spear-ranged-attack",
4643
"long_range": 60.0,
4744
"name": "Spear Ranged attack",
48-
"parent": "srd_guard_spear",
4945
"range": 20.0,
5046
"reach": null,
5147
"target_creature_only": false,
5248
"to_hit_mod": 3
5349
}
5450
],
5551
"desc": "Melee or Ranged Weapon Attack: +3 to hit, reach 5 ft. or range 20/60 ft., one target. Hit: 4 (1d6 + 1) piercing damage, or 5 (1d8 + 1) piercing damage if used with two hands to make a melee attack.",
56-
"form_condition": null,
57-
"key": "srd_guard_spear",
58-
"legendary_cost": 1,
52+
"legendary_action_cost": 1,
53+
"limited_to_form": null,
5954
"name": "Spear",
60-
"order": 0,
61-
"parent": "srd_guard",
62-
"uses_param": null,
63-
"uses_type": null
55+
"order_in_statblock": 0,
56+
"usage_limits": null
6457
}
6558
],
6659
"alignment": "any alignment",

0 commit comments

Comments
 (0)