|
@@ -3,7 +3,7 @@ Provides access to the models stored in the database, via the server.
|
3
|
3
|
"""
|
4
|
4
|
import datetime
|
5
|
5
|
import logging
|
6
|
|
-from typing import NamedTuple, Sequence
|
|
6
|
+from typing import NamedTuple, Sequence, Tuple, Any, Optional
|
7
|
7
|
from urllib.parse import urljoin
|
8
|
8
|
|
9
|
9
|
import requests
|
|
@@ -19,7 +19,7 @@ class ServerStatus:
|
19
|
19
|
""" Provides helper classes to check whether the server is up. """
|
20
|
20
|
|
21
|
21
|
@classmethod
|
22
|
|
- def is_server_running(cls) -> bool:
|
|
22
|
+ def is_server_running(cls) -> Tuple[bool, Any]:
|
23
|
23
|
try:
|
24
|
24
|
req = requests.get(urljoin(SERVER_URL, "ping"))
|
25
|
25
|
|
|
@@ -50,11 +50,16 @@ class ServerStatus:
|
50
|
50
|
class Person(NamedTuple):
|
51
|
51
|
""" Represents a Person, as retrieved from the database. """
|
52
|
52
|
|
53
|
|
- name: str
|
|
53
|
+ full_name: str
|
|
54
|
+ display_name: Optional[str]
|
54
|
55
|
active: bool = True
|
55
|
|
- person_id: int = None
|
|
56
|
+ person_id: Optional[int] = None
|
56
|
57
|
consumptions: dict = {}
|
57
|
58
|
|
|
59
|
+ @property
|
|
60
|
+ def name(self) -> str:
|
|
61
|
+ return self.display_name or self.full_name
|
|
62
|
+
|
58
|
63
|
def add_consumption(self, type_id: str) -> bool:
|
59
|
64
|
""" Register a consumption for this Person. """
|
60
|
65
|
req = requests.post(
|
|
@@ -182,7 +187,8 @@ class Person(NamedTuple):
|
182
|
187
|
def from_dict(cls, data: dict) -> "Person":
|
183
|
188
|
""" Reconstruct a Person object from a dict. """
|
184
|
189
|
return Person(
|
185
|
|
- name=data["name"],
|
|
190
|
+ full_name=data["full_name"],
|
|
191
|
+ display_name=data["display_name"],
|
186
|
192
|
active=data["active"],
|
187
|
193
|
person_id=data["person_id"],
|
188
|
194
|
consumptions=data["consumptions"],
|