Skip to content

Commit aff29da

Browse files
committed
Merge branch 'staging' into 723/rmv-duplicated-elderberry-inn-src
2 parents a9bd0df + ade6ad1 commit aff29da

File tree

84 files changed

+2729
-2648
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+2729
-2648
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.2 on 2025-05-07 09:07
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api_v2', '0035_document_weight_unit'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='image',
15+
name='alt_text',
16+
field=models.TextField(default='', help_text='A short textual description of the image. Important for accessibility'),
17+
),
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.2 on 2025-05-07 09:13
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api_v2', '0036_image_alt_text'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='image',
15+
name='alt_text',
16+
field=models.TextField(help_text='A short textual description of the image. Important for accessibility'),
17+
),
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.2 on 2025-05-07 09:36
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api_v2', '0037_alter_image_alt_text'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='image',
15+
name='attribution',
16+
field=models.TextField(default='', help_text='Attribution information for this image. Who drew it and where we can find more of thier work?'),
17+
),
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 5.1.2 on 2025-05-07 09:38
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('api_v2', '0038_image_attribution'),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name='image',
15+
name='attribution',
16+
field=models.TextField(help_text='Attribution information for this image. Who drew it and where we can find more of thier work?'),
17+
),
18+
]

api_v2/models/image.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ class Image(HasName, FromDocument):
1515
help_text='Relative path of the file, to be used in static file resolution.'
1616
)
1717

18+
alt_text = models.TextField(
19+
help_text='A short textual description of the image. Important for accessibility',
20+
)
21+
22+
attribution = models.TextField(
23+
help_text='Attribution information for this image. Who drew it and where we can find more of thier work?',
24+
)
25+
1826
type = models.CharField(
1927
blank=True,
2028
null=True,

api_v2/serializers/abstracts.py

Lines changed: 4 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -84,65 +84,22 @@ def get_dynamic_params(self):
8484
return self.parent._context.get("dynamic_params", {})
8585
return self._context.get("dynamic_params", {})
8686

87-
def handle_depth_serialization(self, instance, representation):
88-
"""
89-
Handles the serialization of fields based on the current depth
90-
compared to the maximum allowed depth. This function modifies
91-
the representation to include only URLs for nested serializers
92-
when the maximum depth is reached.
93-
"""
94-
max_depth = self._context.get("max_depth", 0)
95-
current_depth = self._context.get("current_depth", 0)
96-
97-
# if we reach the maximum depth, nested serializers return their pk (url)
98-
if current_depth >= max_depth:
99-
for field_name, field in self.fields.items():
100-
if isinstance(field, serializers.HyperlinkedModelSerializer):
101-
nested_representation = representation.get(field_name)
102-
if nested_representation and "url" in nested_representation:
103-
representation[field_name] = nested_representation["url"]
104-
return representation
105-
106-
# otherwise, pass depth to children serializers
107-
for field_name, field in self.fields.items():
108-
# Guard clause: make sure the child is a GameContentSerializer
109-
if not isinstance(field, GameContentSerializer):
110-
continue
111-
112-
nested_instance = getattr(instance, field_name)
113-
nested_serializer = field.__class__(nested_instance, context={
114-
**self._context,
115-
"current_depth": current_depth + 1,
116-
"max_depth": max_depth,
117-
})
118-
119-
# Ensure dynamic params are specific to the child serializer
120-
child_dynamic_params = self.get_or_create_dynamic_params(field_name)
121-
nested_serializer._context['dynamic_params'] = child_dynamic_params
122-
representation[field_name] = nested_serializer.data
123-
return representation
124-
125-
12687
def __init__(self, *args, **kwargs):
12788
request = kwargs.get("context", {}).get("request")
12889
super().__init__(*args, **kwargs)
12990

91+
# Request is only present on root serializer
13092
if request:
131-
self._context["max_depth"] = int(request.query_params.get("depth", 0))
13293
dynamic_params = self.get_dynamic_params_for_root(request)
13394
self._context.update({"dynamic_params": dynamic_params})
13495

13596
def to_representation(self, instance):
97+
# if dynamic params are present, rmv requested fields and pass params
98+
# to child serializers
13699
if dynamic_params := self.get_dynamic_params().copy():
137100
self.remove_unwanted_fields(dynamic_params)
138101
self.set_dynamic_params_for_children(dynamic_params)
139-
140-
representation = super().to_representation(instance)
141-
142-
representation = self.handle_depth_serialization(instance, representation)
143-
144-
return representation
145-
102+
return super().to_representation(instance)
146103

147104
class Meta:
148105
abstract = True

api_v2/serializers/background.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .abstracts import GameContentSerializer
88
from .document import DocumentSummarySerializer
99

10-
class BackgroundBenefitSerializer(serializers.ModelSerializer):
10+
class BackgroundBenefitSerializer(GameContentSerializer):
1111
class Meta:
1212
model = models.BackgroundBenefit
1313
fields = ['name','desc','type']

api_v2/serializers/characterclass.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Meta:
6969
'feature_items'
7070
]
7171

72-
class CharacterClassSummarySerializer(serializers.ModelSerializer):
72+
class CharacterClassSummarySerializer(GameContentSerializer):
7373
'''
7474
A slimmer CharacterClassSerializer, designed to serialize Class FKs on
7575
other serializers. ie. The `subclass_of` field on the

api_v2/serializers/creature.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
from drf_spectacular.utils import extend_schema_field, inline_serializer
1717
from drf_spectacular.types import OpenApiTypes
1818

19-
class CreatureActionAttackSerializer(serializers.ModelSerializer):
20-
19+
class CreatureActionAttackSerializer(GameContentSerializer):
2120
distance_unit = serializers.SerializerMethodField()
21+
damage_type = DamageTypeSummarySerializer()
22+
extra_damage_type = DamageTypeSummarySerializer()
2223

2324
class Meta:
2425
model = models.CreatureActionAttack
@@ -46,7 +47,7 @@ class Meta:
4647
def get_distance_unit(self, CreatureActionAttack):
4748
return CreatureActionAttack.get_distance_unit
4849

49-
class CreatureActionSerializer(serializers.ModelSerializer):
50+
class CreatureActionSerializer(GameContentSerializer):
5051
attacks = CreatureActionAttackSerializer(many=True, read_only=True)
5152
usage_limits = serializers.SerializerMethodField()
5253

@@ -85,7 +86,7 @@ class Meta:
8586
model = models.CreatureType
8687
fields = '__all__'
8788

88-
class CreatureTypeSummarySerializer(serializers.ModelSerializer):
89+
class CreatureTypeSummarySerializer(GameContentSerializer):
8990
'''
9091
A slimmer CreatureTypeSerializer, designed to serialize CreatureType FKs on
9192
other serializers . Not intended to be used directly with in a ModelViewset.

api_v2/serializers/damagetype.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Meta:
1313
model = models.DamageType
1414
fields = '__all__'
1515

16-
class DamageTypeSummarySerializer(serializers.ModelSerializer):
16+
class DamageTypeSummarySerializer(GameContentSerializer):
1717
'''
1818
A slimmer DamageTypeSerializer, designed to serialize DamageType FKs on
1919
other serializers. Not intended to be used directly with in a ModelViewset.

0 commit comments

Comments
 (0)