41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# Classes utilisées pour représenter des données
|
|
class TodoElement():
|
|
STATE_NOT_STARTED = 0 # Sorte d'enum qui représente l'état d'une tâche
|
|
STATE_STARTED = 1
|
|
STATE_COMPLETED = 2
|
|
|
|
name: str
|
|
state: int
|
|
|
|
def __init__(self, name:str, description:str=None):
|
|
self.name = name
|
|
self.description = description
|
|
self.state = TodoElement.STATE_NOT_STARTED
|
|
|
|
def __str__(self)->str:
|
|
"""
|
|
Affiche la tâche, son nom et son statut
|
|
Affichera aussi la description de la tâche si elle a été définie ET est en cours
|
|
|
|
Returns:
|
|
str: Représentation écrite de la tâche
|
|
"""
|
|
return f"Tâche \"{self.name}\": {self.__getStateName()}." + \
|
|
(f" Description: {self.description}" if self.description and self.state == TodoElement.STATE_STARTED else '')
|
|
|
|
def __getStateName(self)->str:
|
|
if self.state == TodoElement.STATE_NOT_STARTED:
|
|
return "Non commencée"
|
|
elif self.state == TodoElement.STATE_STARTED:
|
|
return "En cours"
|
|
elif self.state == TodoElement.STATE_COMPLETED:
|
|
return "Terminée"
|
|
else:
|
|
return "Inconnu"
|
|
|
|
if __name__ == "__main__":
|
|
test = TodoElement("TEST tâche", "OUI")
|
|
test.state = TodoElement.STATE_STARTED
|
|
print(test)
|
|
print([str(test)])
|