My knowledge of html and Django is very limited but I have this Django project with multiple (12) HTML pages that display information in a table similar to the code below. The table is conditionally displayed if there are any fixes left to make. If any of the data in the fixes was already tested it should be highlighted in red to avoid editing. I recently added the <tr {% if p.tested in green_tested %} bgcolor="red" {% endif %}> bit to do the highlighting but it felt really dumb to have to add it manually to all 12 pages. Is there a way that I can add it as part of an external template?
{% extends "admin/base_site.html" %}
{% load static %}
{% block content %}
<p><b>Description:</b> {{ docstring }}</p>
{% if count|length %}
<p><b>Action:</b> Investigate why and fix.</p>
<p style="color:red">If any table rows are highlighted red, indicating a tested profile, flag immediately to health report owner/Automation before editing.</p>
<table>
<tr bgcolor="#ccc">
<th>Profile</th>
<th>Name</th>
<th>Type</th>
<th>Tested</th>
<th>e.g. Device</th>
</tr>
{% for p in count %}
<tr {% if p.tested in green_tested %} bgcolor="red" {% endif %}>
<td><a href={{ p.profile_url }}>{{ p.url }}</a></td>
<td>{{ p.name }}</td>
<td>{{ p.type }}</td>
<td>{{ p.tested }}</td>
<td><a href={{ p.device_url }}>{{ p.dev_id }}</a></td>
{% endfor %}
</tr>
</table>
{% else %}
No fixes left to make!
{% endif %}
{% endblock %}
My function in the views.py looks something like this:
def test_function(request):
count = test_function_count()
context = {'count': count,
'green_tested': list(map(lambda x: x[0], models.GREEN_TESTED)),
'docstring': test_function_count.__doc__}
return render(request, 'health_report/test-function-page.html', context)
It would also be nice to not have to add the 'green_tested' to all my functions in views.