diff --git a/src/backoffice/templates/backoffice/schedule_source_import-detail.html b/src/backoffice/templates/backoffice/schedule_source_import-detail.html index 831850a1fb54d02e65186a09547f67f8659e5188..66e80322c4d9214e992e5d48b23e705d4a9d1bc6 100644 --- a/src/backoffice/templates/backoffice/schedule_source_import-detail.html +++ b/src/backoffice/templates/backoffice/schedule_source_import-detail.html @@ -4,74 +4,87 @@ {% block content %} -<h1>ScheduleSourceImport for "<span title="{{ object.schedule_source.assembly.name }}">{{ object.schedule_source.assembly.slug }}</span>"</h1> + <h1>ScheduleSourceImport for "<span title="{{ object.schedule_source.assembly.name }}">{{ object.schedule_source.assembly.slug }}</span>"</h1> -<div class="card mb-3"> - <div class="card-header"> - Import ID <code>{{ object.id }}</code>, - Source <a href="{% url 'backoffice:schedulesource-detail' pk=object.schedule_source_id %}"><code>{{ object.schedule_source_id }}</code></a> + <div class="card mb-3"> + <div class="card-header"> + Import ID <code>{{ object.id }}</code>, + Source <a href="{% url 'backoffice:schedulesource-detail' pk=object.schedule_source_id %}"><code>{{ object.schedule_source_id }}</code></a> + </div> + <div class="card-body"> + <p>State: <strong class="{{ object.text_color_class }}">{{ object.state }}</strong></p> + <p>Summary: <br/><strong>{{ object.summary|linebreaks }}</strong></p> + <p>Start: <strong title="{{ object.start }}">{{ object.start|naturaltime }}</strong></p> + <p>End: <strong title="{{ object.end }}">{{ object.end|naturaltime }}</strong></p> + </div> </div> - <div class="card-body"> - <p>State: <strong class="{{ object.text_color_class }}">{{ object.state }}</strong></p> - <p>Summary: <br/><strong>{{ object.summary|linebreaks }}</strong></p> - <p>Start: <strong title="{{ object.start }}">{{ object.start|naturaltime }}</strong></p> - <p>End: <strong title="{{ object.end }}">{{ object.end|naturaltime }}</strong></p> - </div> -</div> -{% if object.errors %} -<div class="card mb-3 border-warning"> - <div class="card-header text-bg-warning"> - Errors - </div> - <table class="card-body table table-sm table-hover"> - <thead> - <tr><th>Type</th><th>Action</th><th>Source ID</th><th>Local ID</th><th>Message</th></tr> - </thead> - <tbody> - {% for error in object.errors %} - <tr> - <td>{{ error.type|default:"???" }}</td> - <td>{{ error.action|default:"???" }}</td> - <td>{{ error.source_id|default:"-/-" }}</td> - <td>{{ error.local_id|default:"-/-" }}</td> - <td>{{ error.message }}</td> - </tr> - {% endfor %} - </tbody> - </table> -</div> -{%endif%} + {% if object.errors %} + <div class="card mb-3 border-warning"> + <div class="card-header text-bg-warning"> + Errors + </div> + <table class="card-body table table-sm table-hover"> + <thead> + <tr> + <th>Type</th> + <th>Action</th> + <th>Source ID</th> + <th>Local ID</th> + <th>Message</th> + </tr> + </thead> + <tbody> + {% for error in object.errors %} + <tr> + <td>{{ error.action|default:"???" }}</td> + <td>{{ error.type|default:"???" }}</td> + <td>{{ error.source_id|default:"-/-" }}</td> + <td>{{ error.local_id|default:"-/-" }}</td> + <td>{{ error.message }}</td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + {% endif %} -{% if activity %} -<div class="card mb-3 border-primary"> - <div class="card-header text-bg-primary"> - Activity - </div> - <table class="card-body table table-sm table-hover"> - <thead> - <tr><th>Type</th><th>Action</th><th>Source ID</th><th>Local ID</th></tr> - </thead> - <tbody> - {% for item in activity %} - <tr{% if item.action != "seen" %} class="fw-bold"{% endif %}> - <td class="{% if item.action == "seen" %}text-muted{% elif item.action == "error" %}text-danger{% endif %}">{{ item.type|default:"???" }}</td> - <td class="{% if item.action == "seen" %}text-muted{% elif item.action == "error" %}text-danger{% endif %}">{{ item.action|default:"???" }}</td> - <td class="{% if item.action == "seen" %}text-muted{% elif item.action == "error" %}text-danger{% endif %}">{{ item.source_id|default:"-/-" }}</td> - <td class="{% if item.action == "seen" %}text-muted{% elif item.action == "error" %}text-danger{% endif %}">{{ item.local_id|default:"-/-" }}</td> - </tr> - {% endfor %} - </tbody> - </table> -</div> -{% endif %} + {% if activity %} + <div class="card mb-3 border-primary"> + <div class="card-header text-bg-primary"> + Activity + </div> + <div class="card-body"> + <table class="table table-sm table-hover"> + <thead> + <tr> + <th>Type</th> + <th>Action</th> + <th>Source ID</th> + <th>Local ID</th> + </tr> + </thead> + <tbody> + {% for item in activity %} + <tr> + <td class="{% if item.action == "seen" %}text-muted{% elif item.action == "error" %}text-danger{% elif item.action == "missing" or item.action == "removed" %}text-warning{% elif item.action == "added" %}text-success{% endif %}">{{ item.action|default:"???" }}</td> + <td class="{% if item.action == "seen" %}text-muted{% elif item.action == "error" %}text-danger{% elif item.action == "missing" or item.action == "removed" %}text-warning{% elif item.action == "added" %}text-success{% endif %}">{{ item.type|default:"???" }}</td> + <td class="{% if item.action == "seen" %}text-muted{% elif item.action == "error" %}text-danger{% elif item.action == "missing" or item.action == "removed" %}text-warning{% elif item.action == "added" %}text-success{% endif %}">{{ item.source_id|default:"-/-" }}</td> + <td class="{% if item.action == "seen" %}text-muted{% elif item.action == "error" %}text-danger{% elif item.action == "missing" or item.action == "removed" %}text-warning{% elif item.action == "added" %}text-success{% endif %}">{{ item.local_id|default:"-/-" }}</td> + </tr> + {% endfor %} + </tbody> + </table> + </div> + </div> + {% endif %} -{% if object.data %} -<div class="text-center"> - <a href="{% url 'backoffice:schedulesourceimport-detail-data' pk=object.pk %}" class="btn btn-outline-primary"> - data as JSON - </a> -</div> -{% endif %} + {% if object.data %} + <div class="text-center"> + <a href="{% url 'backoffice:schedulesourceimport-detail-data' pk=object.pk %}" class="btn btn-outline-primary"> + data as JSON + </a> + </div> + {% endif %} {% endblock %} diff --git a/src/backoffice/views/schedules.py b/src/backoffice/views/schedules.py index 6cf5223869beb9fbe69929917b8616c8eb996085..e993d94c9108f10a5ff2d566cad0253fce908ef8 100644 --- a/src/backoffice/views/schedules.py +++ b/src/backoffice/views/schedules.py @@ -122,13 +122,13 @@ class ScheduleSourceImportDetailView(ScheduleAdminMixin, DetailView): model = ScheduleSourceImport def get_context_data(self, *args, **kwargs): - action2sort = {'error': '01', 'removed': '02', 'added': '03', 'seen': '08'} - type2sort = {'room': '10', 'event': '20', 'speaker': '50'} + action2sort = {'error': 10, 'removed': 20, 'missing': 25, 'added': 30, 'seen': 80} + type2sort = {'room': 10, 'event': 20, 'speaker': 50} ctx = super().get_context_data(*args, **kwargs) if data := ctx['object'].data: ctx['activity'] = sorted( data.get('_activity', []), - key=lambda item: f'{action2sort.get(item["action"], "99")}__{type2sort.get(item["type"], "99")}__{item["source_id"]:>10}', + key=lambda item: (action2sort.get(item["action"], 99), type2sort.get(item["type"], 99), item["source_id"]), ) else: ctx['activity'] = None