diff --git a/src/backend/templates/collections_table_line.html b/src/backend/templates/collections_table_line.html index d950b47e2d05de8f2553919c848c3307ed6d83ce..de92ac1697dcb078667bf71d177eafa64d67c3db 100644 --- a/src/backend/templates/collections_table_line.html +++ b/src/backend/templates/collections_table_line.html @@ -19,7 +19,7 @@ </div> {% comment %} We need to put in the same td to avoid breaking the table {% endcomment %} <div class="d-flex justify-content-center align-items-center" style="flex: 1 1 0px;"> - {% if col.has_events %}<a href="{% url 'history' %}?search=&col={{col.pid}}&status=error&month=all" class="btn btn-danger">View Errors</a>{% endif %} + {% if col.has_error %}<a href="{% url 'history' %}?search=&col={{col.pid}}&status=error&month=all" class="btn btn-danger">View Errors</a>{% endif %} </div> </div> </td> diff --git a/src/backend/views.py b/src/backend/views.py index 4e7a45ae84a58941ae174f684b0d12563ef59288..74001016245c562d80ace548fbd8028941dd34b5 100644 --- a/src/backend/views.py +++ b/src/backend/views.py @@ -333,8 +333,13 @@ class CollectionsView(AuthentificatedView, TemplateView): context = super().get_context_data(**kwargs) collections_with_events = Collection.objects.annotate( - # Annotate whether the collection has related history events with "ERROR" status - has_events=Exists(HistoryEvent.objects.filter(col=OuterRef("pid"), status="ERROR")), + # Annotate whether the collection has related history events with "ERROR" status and the last import is an error + last_event=HistoryEvent.objects.filter( + col=OuterRef("pid"), + type="import", + ) + .order_by("-created_on") + .values("status")[:1] ).exclude( Exists( ContainerSource.objects.filter( @@ -370,7 +375,7 @@ class CollectionsView(AuthentificatedView, TemplateView): "title_tex": collection.title_tex, "imported": True, "can_be_imported": True, - "has_events": collection.has_events, + "has_error": collection.last_event == "ERROR", } def can_be_imported(sources): @@ -390,7 +395,7 @@ class CollectionsView(AuthentificatedView, TemplateView): "title_tex": value["title"], "imported": False, "can_be_imported": can_be_imported(value["sources"]), - "has_events": False, + "has_error": False, } for value in get_all_cols().values() if value["pid"] not in collections