Skip to content

Commit

Permalink
Add child interests to the rendering process
Browse files Browse the repository at this point in the history
Switch to header structure for different levels of interests

- Start at h4 to allow for the structure of
  the twfy page for h1-3.
  • Loading branch information
ajparsons committed Dec 12, 2024
1 parent 5105e99 commit fa4e1d1
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions pyscraper/regmem/commons/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,37 @@ def multi_to_camel(value: str) -> AliasChoices:

interest_template = Template(
"""
<p class="interest-summary">{{ interest.summary|e }}</p>
<ul class="interest-details-list">
{% for field in interest.present_fields() %}
{{field.to_html()}}
{% endfor %}
{% if interest.registration_date %}
<li class="registration-date">Registration Date: {{ interest.registration_date.strftime('%d %B %Y') }}</li>
<div class="interest-item" id="{{ interest.id }}">
{% if is_child %}
<h6 class="interest-summary">{{ interest.summary|e }}</h6>
{% else %}
<h4 class="interest-summary">{{ interest.summary|e }}</h4>
{% endif %}
{% if interest.published_date %}
<li class="published-date">Published Date: {{ interest.published_date.strftime('%d %B %Y') }}</li>
{% endif %}
{% if interest.last_updated_date %}
<li class="last-updated-date">Last Updated Date: {{ interest.last_updated_date.strftime('%d %B %Y') }}</li>
<ul class="interest-details-list">
{% for field in interest.present_fields() %}
{{field.to_html()}}
{% endfor %}
{% if interest.registration_date %}
<li class="registration-date">Registration Date: {{ interest.registration_date.strftime('%d %B %Y') }}</li>
{% endif %}
{% if interest.published_date %}
<li class="published-date">Published Date: {{ interest.published_date.strftime('%d %B %Y') }}</li>
{% endif %}
{% if interest.last_updated_date %}
<li class="last-updated-date">Last Updated Date: {{ interest.last_updated_date.strftime('%d %B %Y') }}</li>
{% endif %}
</ul>
{% if interest.child_items %}
<h5 class="child-item-header">Specific work or payments</h5>
<div class="interest-child-items" id="parent-{{ interest.id }}">
{% for child in interest.child_items %}
{{ child.to_html(is_child=True) }}
{% endfor %}
</div>
{% endif %}
</ul>
</div>
"""
)
Expand Down Expand Up @@ -201,8 +215,8 @@ def last_updated_date(self) -> Optional[date]:
return self.updated_date[-1]
return None

def to_html(self) -> str:
result = interest_template.render(interest=self)
def to_html(self, is_child: bool = False) -> str:
result = interest_template.render(interest=self, is_child=is_child)

# remove blank lines
result = "\n".join([x for x in result.split("\n") if x.strip()])
Expand Down

0 comments on commit fa4e1d1

Please sign in to comment.