From 523a25fbc2fcb52f2600ede69ad9e192bb096bbd Mon Sep 17 00:00:00 2001
From: SwoopDoable <swoop-doable.0v@icloud.com>
Date: Mon, 12 Aug 2024 17:16:46 +0200
Subject: [PATCH] Add common and organization filters

---
 .../common/templatetags/common_extras.py      |  8 ++++++-
 .../publication_administration.py             | 24 ++++++-------------
 2 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/scipost_django/common/templatetags/common_extras.py b/scipost_django/common/templatetags/common_extras.py
index 10e70ba34..f3b539fe8 100644
--- a/scipost_django/common/templatetags/common_extras.py
+++ b/scipost_django/common/templatetags/common_extras.py
@@ -8,7 +8,6 @@ from django import template
 from django.urls import reverse
 from django.utils.safestring import mark_safe
 
-
 register = template.Library()
 
 
@@ -49,6 +48,13 @@ def int_divide(a, b):
 def multiply(a, b):
     return a * b
 
+@register.filter
+def index(list, index):
+    return list[index]
+
+@register.filter
+def zip_dj(list1, list2):
+    return zip(list1, list2)
 
 # HTML
 @register.filter
diff --git a/scipost_django/journals/templatetags/publication_administration.py b/scipost_django/journals/templatetags/publication_administration.py
index 366678d0c..5fb474deb 100644
--- a/scipost_django/journals/templatetags/publication_administration.py
+++ b/scipost_django/journals/templatetags/publication_administration.py
@@ -4,33 +4,23 @@ __license__ = "AGPL v3"
 
 from django import template
 
+from journals.models.publication import Publication
+
 register = template.Library()
 
 
 @register.filter
-def has_all_author_relations(publication):
+def has_all_author_relations(publication: Publication) -> bool:
     """
     Check if all authors are added to the Publication object, just by counting.
     """
-    return len(publication.author_list.split(",")) == publication.authors.count()
-
-
-@register.filter
-def authors_in_right_order(publication):
-    """
-    Checks if all author orderings correspond to those in author list.
-    """
-    if not has_all_author_relations(publication):
-        return False
-    list_of_authors = publication.author_list.split(",")
-    for author in publication.authors.all():
-        if author.last_name and author.last_name not in list_of_authors[author.order - 1]:
-            return False
-    return True
+    submission_string_authors = publication.author_list.split(",")
+    associated_authors = publication.authors.filter(profile__isnull=False) # exclude temp authors without profiles
 
+    return len(submission_string_authors) == associated_authors.count()
 
 @register.filter
-def author_affiliations_complete(publication):
+def author_affiliations_complete(publication: Publication) -> bool:
     """
     Checks if each author has a non-empty affiliations field.
     """
-- 
GitLab