From 66b6545d3cb52198c06899800a089eec583d9056 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Mon, 13 Nov 2023 16:45:45 +0000 Subject: [PATCH] change sort ordering and date displays on dashboards --- doajtest/testdrive/todo_associate.py | 1 + doajtest/testdrive/todo_editor.py | 1 + .../testdrive/todo_maned_editor_associate.py | 1 + portality/bll/services/todo.py | 52 ++++++++++++------- portality/models/v2/application.py | 11 +++- portality/templates/dashboard/_todo.html | 4 +- 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/doajtest/testdrive/todo_associate.py b/doajtest/testdrive/todo_associate.py index be877c3a2f..a6a103fa15 100644 --- a/doajtest/testdrive/todo_associate.py +++ b/doajtest/testdrive/todo_associate.py @@ -95,6 +95,7 @@ def build_application(title, lmu_diff, cd_diff, status, editor=None): ap.set_id(ap.makeid()) ap.set_last_manual_update(dates.before(datetime.utcnow(), lmu_diff)) ap.set_created(dates.before(datetime.utcnow(), cd_diff)) + ap.set_date_applied(dates.before(datetime.utcnow(), cd_diff)) ap.set_application_status(status) if editor is not None: diff --git a/doajtest/testdrive/todo_editor.py b/doajtest/testdrive/todo_editor.py index c73939597d..7380b483ba 100644 --- a/doajtest/testdrive/todo_editor.py +++ b/doajtest/testdrive/todo_editor.py @@ -55,6 +55,7 @@ def build_application(title, lmu_diff, cd_diff, status, editor=None, editor_grou ap.application_type = constants.APPLICATION_TYPE_NEW_APPLICATION ap.set_last_manual_update(dates.before(datetime.utcnow(), lmu_diff)) ap.set_created(dates.before(datetime.utcnow(), cd_diff)) + ap.set_date_applied(dates.before(datetime.utcnow(), cd_diff)) ap.set_application_status(status) if editor is not None: diff --git a/doajtest/testdrive/todo_maned_editor_associate.py b/doajtest/testdrive/todo_maned_editor_associate.py index 5b038f2153..a6efd6f747 100644 --- a/doajtest/testdrive/todo_maned_editor_associate.py +++ b/doajtest/testdrive/todo_maned_editor_associate.py @@ -166,6 +166,7 @@ def build_application(title, lmu_diff, cd_diff, status, editor=None, editor_grou ap.application_type = constants.APPLICATION_TYPE_NEW_APPLICATION ap.set_last_manual_update(dates.before(datetime.utcnow(), lmu_diff)) ap.set_created(dates.before(datetime.utcnow(), cd_diff)) + ap.set_date_applied(dates.before(datetime.utcnow(), cd_diff)) ap.set_application_status(status) if editor is not None: diff --git a/portality/bll/services/todo.py b/portality/bll/services/todo.py index 8a0a54b51c..36f86fc4af 100644 --- a/portality/bll/services/todo.py +++ b/portality/bll/services/todo.py @@ -158,6 +158,7 @@ def _rationalise_todos(self, todos, size): class TodoRules(object): @classmethod def maned_stalled(cls, size, maned_of): + sort_date = "created_date" stalled = TodoQuery( musts=[ TodoQuery.lmu_older_than(8), @@ -166,13 +167,14 @@ def maned_stalled(cls, size, maned_of): must_nots=[ TodoQuery.status([constants.APPLICATION_STATUS_ACCEPTED, constants.APPLICATION_STATUS_REJECTED]) ], - sort="last_manual_update", + sort=sort_date, size=size ) - return constants.TODO_MANED_STALLED, stalled, "last_manual_update", 0 + return constants.TODO_MANED_STALLED, stalled, sort_date, 0 @classmethod def maned_follow_up_old(cls, size, maned_of): + sort_date = "created_date" follow_up_old = TodoQuery( musts=[ TodoQuery.cd_older_than(10), @@ -181,38 +183,41 @@ def maned_follow_up_old(cls, size, maned_of): must_nots=[ TodoQuery.status([constants.APPLICATION_STATUS_ACCEPTED, constants.APPLICATION_STATUS_REJECTED]) ], - sort="created_date", + sort=sort_date, size=size ) - return constants.TODO_MANED_FOLLOW_UP_OLD, follow_up_old, "created_date", 0 + return constants.TODO_MANED_FOLLOW_UP_OLD, follow_up_old, sort_date, 0 @classmethod def maned_ready(cls, size, maned_of): + sort_date = "created_date" ready = TodoQuery( musts=[ TodoQuery.status([constants.APPLICATION_STATUS_READY]), TodoQuery.editor_group(maned_of) ], - sort="last_manual_update", + sort=sort_date, size=size ) - return constants.TODO_MANED_READY, ready, "created_date", 1 + return constants.TODO_MANED_READY, ready, sort_date, 1 @classmethod def maned_completed(cls, size, maned_of): + sort_date = "created_date" completed = TodoQuery( musts=[ TodoQuery.status([constants.APPLICATION_STATUS_COMPLETED]), TodoQuery.lmu_older_than(2), TodoQuery.editor_group(maned_of) ], - sort="last_manual_update", + sort=sort_date, size=size ) - return constants.TODO_MANED_COMPLETED, completed, "last_manual_update", 0 + return constants.TODO_MANED_COMPLETED, completed, sort_date, 0 @classmethod def maned_assign_pending(cls, size, maned_of): + sort_date = "created_date" assign_pending = TodoQuery( musts=[ TodoQuery.exists("admin.editor_group"), @@ -223,13 +228,14 @@ def maned_assign_pending(cls, size, maned_of): must_nots=[ TodoQuery.exists("admin.editor") ], - sort="created_date", + sort=sort_date, size=size ) - return constants.TODO_MANED_ASSIGN_PENDING, assign_pending, "last_manual_update", 0 + return constants.TODO_MANED_ASSIGN_PENDING, assign_pending, sort_date, 0 @classmethod def editor_stalled(cls, groups, size): + sort_date = "created_date" stalled = TodoQuery( musts=[ TodoQuery.lmu_older_than(6), @@ -243,13 +249,14 @@ def editor_stalled(cls, groups, size): constants.APPLICATION_STATUS_READY ]) ], - sort="last_manual_update", + sort=sort_date, size=size ) - return constants.TODO_EDITOR_STALLED, stalled, "last_manual_update", 0 + return constants.TODO_EDITOR_STALLED, stalled, sort_date, 0 @classmethod def editor_follow_up_old(cls, groups, size): + sort_date = "created_date" follow_up_old = TodoQuery( musts=[ TodoQuery.cd_older_than(8), @@ -263,26 +270,28 @@ def editor_follow_up_old(cls, groups, size): constants.APPLICATION_STATUS_READY ]) ], - sort="created_date", + sort=sort_date, size=size ) - return constants.TODO_EDITOR_FOLLOW_UP_OLD, follow_up_old, "created_date", 0 + return constants.TODO_EDITOR_FOLLOW_UP_OLD, follow_up_old, sort_date, 0 @classmethod def editor_completed(cls, groups, size): + sort_date = "created_date" completed = TodoQuery( musts=[ TodoQuery.status([constants.APPLICATION_STATUS_COMPLETED]), TodoQuery.editor_groups(groups), TodoQuery.is_new_application() ], - sort="last_manual_update", + sort=sort_date, size=size ) - return constants.TODO_EDITOR_COMPLETED, completed, "last_manual_update", 1 + return constants.TODO_EDITOR_COMPLETED, completed, sort_date, 1 @classmethod def editor_assign_pending(cls, groups, size): + sort_date = "created_date" assign_pending = TodoQuery( musts=[ TodoQuery.editor_groups(groups), @@ -292,14 +301,14 @@ def editor_assign_pending(cls, groups, size): must_nots=[ TodoQuery.exists("admin.editor") ], - sort="created_date", + sort=sort_date, size=size ) - return constants.TODO_EDITOR_ASSIGN_PENDING, assign_pending, "created_date", 1 + return constants.TODO_EDITOR_ASSIGN_PENDING, assign_pending, sort_date, 1 @classmethod def associate_stalled(cls, acc_id, size): - sort_field = "last_manual_update" + sort_field = "created_date" stalled = TodoQuery( musts=[ TodoQuery.lmu_older_than(3), @@ -383,7 +392,10 @@ class TodoQuery(object): ~~^->Elasticsearch:Technology~~ """ lmu_sort = {"last_manual_update" : {"order" : "asc"}} - cd_sort = {"created_date" : {"order" : "asc"}} + # cd_sort = {"created_date" : {"order" : "asc"}} + # NOTE that admin.date_applied and created_date should be the same for applications, but for some reason this is not always the case + # therefore, we take a created_date sort to mean a date_applied sort + cd_sort = {"admin.date_applied": {"order": "asc"}} def __init__(self, musts=None, must_nots=None, sort="last_manual_update", size=10): self._musts = [] if musts is None else musts diff --git a/portality/models/v2/application.py b/portality/models/v2/application.py index 2b0d523720..4e8bece5ed 100644 --- a/portality/models/v2/application.py +++ b/portality/models/v2/application.py @@ -2,7 +2,7 @@ from portality import constants from portality.core import app -from portality.lib import es_data_mapping +from portality.lib import es_data_mapping, coerce, dates from portality.models.v2 import shared_structs from portality.models.v2.journal import JournalLikeObject, Journal from portality.lib.coerce import COERCE_MAP @@ -150,10 +150,19 @@ def application_status(self): def set_application_status(self, val): self.__seamless__.set_with_struct("admin.application_status", val) + def set_date_applied(self, date=None): + if date is None: + date = dates.now_str() + self.__seamless__.set_with_struct("admin.date_applied", date) + @property def date_applied(self): return self.__seamless__.get_single("admin.date_applied") + @property + def date_applied_timestamp(self): + return self.__seamless__.get_single("admin.date_applied", coerce=coerce.to_datestamp()) + @date_applied.setter def date_applied(self, val): self.__seamless__.set_with_struct("admin.date_applied", val) diff --git a/portality/templates/dashboard/_todo.html b/portality/templates/dashboard/_todo.html index 35bccf0c93..5206cb0cab 100644 --- a/portality/templates/dashboard/_todo.html +++ b/portality/templates/dashboard/_todo.html @@ -135,8 +135,8 @@ {% set action = TODOS[todo.action_id[0]] %} {% set app_route = "admin.application" if current_user.has_role("admin") else "editor.application" %} {% set app_url = url_for(app_route, application_id=todo.object_id) %} - {% set app_date = todo.object.created_timestamp %} -
  • + {% set app_date = todo.object.date_applied_timestamp %} +