Skip to content

Commit

Permalink
Add parent attributes to full export
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar authored and MyPyDavid committed Jun 19, 2024
1 parent 0aa4f2e commit deb4d41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 7 additions & 3 deletions rdmo/domain/renderers/mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AttributeRendererMixin:

def render_attribute(self, xml, attribute):
def render_attribute(self, xml, attribute, include_children=True):
if attribute['uri'] not in self.uris:
self.uris.add(attribute['uri'])

Expand All @@ -12,6 +12,10 @@ def render_attribute(self, xml, attribute):
self.render_text_element(xml, 'parent', {'dc:uri': attribute['parent']}, None)
xml.endElement('attribute')

if 'children' in attribute and attribute['children']:
for child in attribute['children']:
if include_children:
for child in attribute.get('children', []):
self.render_attribute(xml, child)

parent_data = attribute.get('parent_data')
if parent_data:
self.render_attribute(xml, parent_data, include_children=False)
8 changes: 7 additions & 1 deletion rdmo/domain/serializers/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class AttributeExportSerializer(serializers.ModelSerializer):

parent = serializers.CharField(source='parent.uri', default=None, read_only=True)
parent_data = serializers.SerializerMethodField()

class Meta:
model = Attribute
Expand All @@ -15,5 +16,10 @@ class Meta:
'key',
'path',
'comment',
'parent'
'parent',
'parent_data'
)

def get_parent_data(self, obj):
if obj.parent is not None:
return AttributeExportSerializer(obj.parent).data

0 comments on commit deb4d41

Please sign in to comment.