2019-02-05 13:29:33 +00:00
|
|
|
from typing import Dict, Any, Optional
|
2019-02-05 15:10:31 +00:00
|
|
|
|
2018-08-17 14:26:46 +00:00
|
|
|
from color import Color
|
2019-02-05 15:10:31 +00:00
|
|
|
import api.projects
|
2018-04-03 10:56:07 +00:00
|
|
|
|
|
|
|
COLOR_TITLE = Color(Color.YELLOW)
|
|
|
|
COLOR_HEADER = Color(Color.CYAN)
|
|
|
|
COLOR_WHITE = Color(Color.BRIGHT_WHITE)
|
|
|
|
|
2018-08-17 13:51:40 +00:00
|
|
|
COLOR_PLANNED = Color(Color.BRIGHT_BLACK)
|
|
|
|
COLOR_STARTED = Color(226)
|
|
|
|
COLOR_FINISHED = Color(Color.BRIGHT_BLUE)
|
|
|
|
COLOR_DELIVERED = Color(208)
|
|
|
|
COLOR_ACCEPTED = Color(Color.BRIGHT_GREEN)
|
|
|
|
COLOR_REJECTED = Color(Color.BRIGHT_RED)
|
|
|
|
|
2018-04-03 10:56:07 +00:00
|
|
|
|
2019-02-05 13:29:33 +00:00
|
|
|
def _format_state(state: str, header: Optional[bool] = False) -> str:
|
2018-04-03 10:56:07 +00:00
|
|
|
STATES = {
|
2019-02-05 13:29:33 +00:00
|
|
|
'accepted': COLOR_ACCEPTED.format('Acc' if header else 'accepted'),
|
|
|
|
'rejected': COLOR_REJECTED.format('Rej' if header else 'rejected'),
|
|
|
|
'delivered': COLOR_DELIVERED.format('Del' if header else 'delivered'),
|
|
|
|
'finished': COLOR_FINISHED.format('Fin' if header else 'finished'),
|
|
|
|
'started': COLOR_STARTED.format('Sta' if header else 'started'),
|
|
|
|
'planned': COLOR_PLANNED.format('Pln' if header else 'planned'),
|
|
|
|
'unstarted': COLOR_PLANNED.format('Uns' if header else 'unstarted'),
|
2018-04-03 10:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return STATES[state]
|
|
|
|
|
|
|
|
|
2019-02-05 15:10:31 +00:00
|
|
|
def _get_persons(project_id: int) -> Dict[int, Dict[str, Any]]:
|
|
|
|
memberships = api.projects.get_memberships(project_id)
|
2018-04-03 10:56:07 +00:00
|
|
|
|
|
|
|
persons: Dict[int, Dict[str, Any]] = {}
|
|
|
|
for membership in memberships:
|
|
|
|
person = membership['person']
|
|
|
|
persons[person['id']] = person
|
|
|
|
|
|
|
|
return persons
|