Add the circular next methods for Task.
This commit is contained in:
@@ -25,4 +25,6 @@
|
|||||||
Add right alignment for buttons in a task item.
|
Add right alignment for buttons in a task item.
|
||||||
** 0.3.5 <2023-07-22 Sat>
|
** 0.3.5 <2023-07-22 Sat>
|
||||||
Update the style of buttons.
|
Update the style of buttons.
|
||||||
|
** 0.3.6 <2023-07-23 Sun>
|
||||||
|
Add the circular next methods for Task.
|
||||||
|
|
||||||
|
|||||||
@@ -25,3 +25,23 @@ class Task(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
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()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user