Skip to content

Commit

Permalink
WIP #282
Browse files Browse the repository at this point in the history
  • Loading branch information
nutjob4life committed Sep 1, 2023
1 parent 67cf336 commit b2765c7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/edrnsite.content/src/edrnsite/content/_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ class _Node:
'''A temporary node in a tree before getting serialized into Django objects.'''
name: str
description: str
stewardship: str
attributes: list[_Attribute]
children: set[object] = dataclasses.field(default_factory=set, init=False, compare=False)
def __hash__(self):
return hash(self.name)
def instantiate(self, parent=None):
explorer_obj = CDEExplorerObject(name=self.name, description=self.description, parent=parent)
explorer_obj = CDEExplorerObject(
name=self.name, description=self.description, stewardship=self.stewardship, parent=parent
)
explorer_obj.save()
for c in self.children:
c.instantiate(explorer_obj)
Expand Down Expand Up @@ -137,9 +140,10 @@ def _parse_structure(self, sheet):
self._log('Parsing overall structure in the "Structure" tab and looking for referenced tabs')
row_number, nodes, roots, structure = 0, {}, [], sheet['Structure']
for name in structure['Object']:
description = structure['Description'][row_number]
description, stewardship = structure['Description'][row_number], structure['Stewardship'][row_number]
attributes = self._parse_attributes(name, sheet)
nodes[name] = _Node(name, description, attributes)
stewardship = '' if pandas.isna(stewardship) else stewardship
nodes[name] = _Node(name, description, stewardship, attributes)
row_number += 1

# Now connect parents to children and gather the roots
Expand Down Expand Up @@ -215,6 +219,7 @@ def serve(self, request: HttpRequest) -> HttpResponse:
class CDEExplorerObject(models.Model):
name = models.CharField(null=False, blank=False, max_length=200, help_text='Name of this object in a CDE hierarchy')
description = models.TextField(null=False, blank=True, help_text='A nice long description of this object')
stewardship = models.TextField(null=False, blank=True, help_text="Who's responsible for this object")
parent = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE, related_name='children')
page = models.ForeignKey(CDEExplorerPage, blank=True, null=True, on_delete=models.SET_NULL, related_name='root_objects')
panels = [FieldPanel('name'), FieldPanel('description'), FieldPanel('parent'), FieldPanel('page')]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ <h3>{{name}}</h3>
<p class='small'>(No description of this object is available.)</p>
{% endif %}

{% if stewardship %}
<h3>Stewardship</h3>
<p>{{stewardship}}</p>
{% endif %}

{% if attributes %}
<h4>Attributes</h4>
<p class='small'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def render_cde_node(node: CDEExplorerObject) -> dict:
return {
'name': node.name,
'description': node.description,
'stewardship': node.stewardship,
'attributes': node.attributes.all(),
'children': node.children.all().order_by('name')
}
Expand Down

0 comments on commit b2765c7

Please sign in to comment.