Skip to content

Commit

Permalink
Inheritance of attributes for #269
Browse files Browse the repository at this point in the history
  • Loading branch information
nutjob4life committed Aug 9, 2023
1 parent f35e547 commit 170b060
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/edrnsite.content/src/edrnsite/content/_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ class _Attribute:
data_type: str
explanatory_note: str
permissible_values: list[str]
inheritance: bool
def __hash__(self):
return hash(self.text)
def instantiate(self, obj):
attr_obj = CDEExplorerAttribute(
text=self.text, definition=self.definition, required=self.required, data_type=self.data_type,
explanatory_note=self.explanatory_note, obj=obj
explanatory_note=self.explanatory_note, obj=obj, inheritance=self.inheritance
)
attr_obj.save()
for pv in self.permissible_values:
Expand Down Expand Up @@ -106,23 +107,26 @@ def _read_sheet(self, url):

def _parse_attributes(self, name, sheet):
'''Using the data in ``sheet``, find the tab ``name`` and get all the attributes there.'''
self._log(f'Parsing attributes in tab "{name}"')

frame = sheet[name]
row_number, attrs = 0, []
for text in frame['Text']:
# Gather data from the spreadsheet tab
pvs_text, defn = frame['Permissible Values'][row_number], frame['Definition'][row_number]
req, dt = frame['Requirement'][row_number], frame['Data Type'][row_number]
note = frame['Explanatory Note'][row_number]
note, inheritance = frame['Explanatory Note'][row_number], frame['Inheritance'][row_number]

# Handle the empty cells
pvs = [] if pandas.isna(pvs_text) else [i.strip() for i in pvs_text.split('\n')]
defn = '' if pandas.isna(defn) else defn
req = '' if pandas.isna(req) else req
dt = '' if pandas.isna(dt) else dt
note = '' if pandas.isna(note) else note
inh = False if pandas.isna(inheritance) else inheritance

# Create the temporary attribute and add it to the sequence
attrs.append(_Attribute(text, defn, req, dt, note, pvs))
attrs.append(_Attribute(text, defn, req, dt, note, pvs, inh))
row_number += 1
return attrs

Expand Down Expand Up @@ -225,13 +229,15 @@ class CDEExplorerAttribute(models.Model):
required = models.CharField(null=False, blank=True, max_length=50, help_text='Required, not, or something else?')
data_type = models.CharField(null=False, blank=True, max_length=30, help_text='Kind of data')
explanatory_note = models.TextField(null=False, blank=True, help_text='Note helping explain use of the CDE')
inheritance = models.BooleanField(null=False, blank=False, default=False, help_text='Attribute inherits values')
panels = [
FieldPanel('text'),
FieldPanel('obj'),
FieldPanel('definition'),
FieldPanel('required'),
FieldPanel('data_type'),
FieldPanel('explanatory_note')
FieldPanel('explanatory_note'),
FieldPanel('inheritance')
]
def __str__(self):
return self.text
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{% load wagtailcore_tags edrnsite_content_tags %}
<a class='btn btn-sm{% if required %} btn-outline-danger{% else %} btn-outline-primary{% endif %}'
<a class='btn btn-sm
{% if required %}
btn-outline-danger
{% elif inheritance %}
btn-outline-secondary
{% else %}
btn-outline-primary
{% endif %}'
data-bs-toggle='offcanvas' href='#{{id}}' role='button'
data-bs-target='#{{id}}' aria-controls='{{id}}'>
{% if required %}<i class='bi bi-key-fill'></i>{% endif %} {{text}}
{% if required %}<i class='bi bi-key-fill'></i>{% endif %}{% if inheritance %}<i class="bi bi-box-seam"></i>{% endif %} {{text}}
</a>
{# -*- Django HTML -*- #}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ <h4 class='offcanvas-title' id='{{id}}-label'>{{text}}</h4>
<small>(Information not provided.)</small>
{% endif %}
</dd>
<dt>Inheritance</dt>
<dd>
{% if inheritance %}
If no values are specified, this attribute inherits values from other objects.
{% else %}
This attribute does not inherit values from other objects.
{% endif %}
</dd>
<dt>Data Type</dt>
<dd>
{% if data_type %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ <h3>{{name}}</h3>

{% if attributes %}
<h4>Attributes</h4>
<p class='small'>Attributes shown with <i class='text-danger bi bi-key-fill'></i> are <em>required</em>.</p>
<p class='small'>
Attributes shown with <i class='text-danger bi bi-key-fill'></i> are <em>required</em>, while
those with <i class="text-secondary bi bi-box-seam"></i> inherit values from other objects.
</p>
<p style='line-height: 2rem;'>
{% for attribute in attributes %}
{% render_cde_attribute_button attribute %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def render_cde_attribute_button(attribute: CDEExplorerAttribute) -> dict:
return {
'id': f'cde-{slugify(attribute.obj.name)}-{slugify(attribute.text)}',
'text': attribute.text,
'required': attribute.required == 'Required'
'required': attribute.required == 'Required',
'inheritance': attribute.inheritance
}


Expand All @@ -53,5 +54,6 @@ def render_cde_attribute_canvas(attribute: CDEExplorerAttribute) -> dict:
'required': attribute.required,
'data_type': attribute.data_type,
'note': attribute.explanatory_note,
'pvs': attribute.permissible_values.all()
'pvs': attribute.permissible_values.all(),
'inheritance': attribute.inheritance
}

0 comments on commit 170b060

Please sign in to comment.