From 5d5fbfcfd9fa5d16059de8aec9732c04b96a963b Mon Sep 17 00:00:00 2001 From: Michael Villeneuve Date: Wed, 15 Jan 2025 13:34:05 +0100 Subject: [PATCH] feat: Do not offer to compare files with identical urls --- reviews/templatetags/documents_list.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/reviews/templatetags/documents_list.py b/reviews/templatetags/documents_list.py index 3abd7586..9597c5ff 100644 --- a/reviews/templatetags/documents_list.py +++ b/reviews/templatetags/documents_list.py @@ -16,6 +16,10 @@ register = template.Library() +def is_identical(new_file, old_file): + return new_file.url == old_file.url + + @register.inclusion_tag("reviews/simple_compare_link.html") def simple_compare_link(obj, file): """Generates a compare icon""" @@ -102,6 +106,11 @@ def simple_compare_link(obj, file): "attribute": file.field.name, } + # Do not offer to compare identical files + old_file = getattr(parent_obj, file.field.name) + if is_identical(file, old_file): + return {} + # CompareDocumentsView expects the following args: # - old pk # - new pk