Add the circular next methods for Task.
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user