From f18912bed45381ea58b0b9d88f1a9c9de7681700 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 23 Jul 2023 19:14:38 +0300 Subject: [PATCH] Add the circular next methods for Task. --- CHANGELOG.org | 2 ++ tasks/models.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG.org b/CHANGELOG.org index e418df0..a08ade0 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -25,4 +25,6 @@ Add right alignment for buttons in a task item. ** 0.3.5 <2023-07-22 Sat> Update the style of buttons. +** 0.3.6 <2023-07-23 Sun> + Add the circular next methods for Task. diff --git a/tasks/models.py b/tasks/models.py index 215fbda..69486d5 100644 --- a/tasks/models.py +++ b/tasks/models.py @@ -25,3 +25,23 @@ class Task(models.Model): def __str__(self): return self.name + @staticmethod + def get_statuses(): + return list(map(lambda _: _[1], Task.STATUSES)) + + def _get_status_index(self): + return Task.get_statuses().index(self.status) + + def circular_next_status_index(self): + current_index = self._get_status_index() + next_index = (current_index + 1) % len(Task.STATUSES) + return next_index + + def circular_next_status(self): + next_index = self.circular_next_status_index() + return Task.get_statuses()[next_index] + + def set_circular_next_status(self): + self.status = self.circular_next_status() + self.save() +