From 7372ab407535ade48ce0b642ae051990e3bef7ed Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 10 May 2020 12:50:46 +0200 Subject: Add task difficulty and priority fields --- src/model/difficulty.py | 30 ++++++++++++++++++++++++++++++ src/model/priority.py | 30 ++++++++++++++++++++++++++++++ src/model/task.py | 12 +++++++++--- 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/model/difficulty.py create mode 100644 src/model/priority.py (limited to 'src/model') diff --git a/src/model/difficulty.py b/src/model/difficulty.py new file mode 100644 index 0000000..595f844 --- /dev/null +++ b/src/model/difficulty.py @@ -0,0 +1,30 @@ +from enum import IntEnum +from typing import Optional + +class Difficulty(IntEnum): + LOW = 0 + MEDIUM = 1 + HIGH = 2 + +values = [ + Difficulty.LOW, + Difficulty.MEDIUM, + Difficulty.HIGH] + +def format(difficulty: Difficulty) -> str: + if difficulty == Difficulty.LOW: + return 'Low' + elif difficulty == Difficulty.MEDIUM: + return 'Medium' + elif difficulty == Difficulty.HIGH: + return 'High' + +def parse(string: str) -> Optional[Difficulty]: + if string == 'Low': + return Difficulty.LOW + elif string == 'Medium': + return Difficulty.MEDIUM + elif string == 'High': + return Difficulty.HIGH + else: + return None diff --git a/src/model/priority.py b/src/model/priority.py new file mode 100644 index 0000000..873369d --- /dev/null +++ b/src/model/priority.py @@ -0,0 +1,30 @@ +from enum import IntEnum +from typing import Optional + +class Priority(IntEnum): + LOW = 0 + MEDIUM = 1 + HIGH = 2 + +values = [ + Priority.LOW, + Priority.MEDIUM, + Priority.HIGH] + +def format(priority: Priority) -> str: + if priority == Priority.LOW: + return 'Low' + elif priority == Priority.MEDIUM: + return 'Medium' + elif priority == Priority.HIGH: + return 'High' + +def parse(string: str) -> Optional[Priority]: + if string == 'Low': + return Priority.LOW + elif string == 'Medium': + return Priority.MEDIUM + elif string == 'High': + return Priority.HIGH + else: + return None diff --git a/src/model/task.py b/src/model/task.py index cc7758d..f5e0ae5 100644 --- a/src/model/task.py +++ b/src/model/task.py @@ -1,17 +1,23 @@ from typing import NamedTuple -from datetime import datetime + +from model.difficulty import Difficulty +from model.priority import Priority class Task(NamedTuple): id: int created_at: int modified_at: int name: str - description: str duration: int tag: str + difficulty: Difficulty + priority: Priority + description: str class ValidTaskForm(NamedTuple): name: str - description: str duration: int tag: str + difficulty: Difficulty + priority: Priority + description: str -- cgit v1.2.3