-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
67 lines (51 loc) · 1.74 KB
/
settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from typing import Any, Optional, List, Dict, Tuple
from pydantic import BaseSettings, validator
LINE_DELIMITER = "|"
NAME_PRICE_DELIMITER = ";"
class Settings(BaseSettings):
"""Application settings, cors, paths"""
# supplier
SUPPLIER_NAME: str
SUPPLIER_ADDRESS_LINES: List[str]
SUPPLIER_IC: str
SUPPLIER_INFO_LINES: List[str]
SUPPLIER_ISSUED_BY_LINES: List[str]
# customer
CUSTOMER_NAME: str
CUSTOMER_ADDRESS_LINES: List[str]
CUSTOMER_IC: str
CUSTOMER_INFO_LINES: List[str]
# naming
INVOICE_NO_SUFFIX: Optional[str]
@validator("INVOICE_NO_SUFFIX")
@classmethod
def default_invoice_no_suffix(cls, v: Optional[str], values: Dict[str, str]) -> str:
if isinstance(v, str):
return v
return f"-{values.get('CUSTOMER_IC')}-01"
# bank details
BANK_CONNECTION_NAME: str
BANK_ACCOUNT_NO: str
BANK_PAYMENT_REF_NO: Optional[str]
BANK_IBAN: Optional[str]
BANK_SWIFT: Optional[str]
# invoice details
PROJECTS: List[Tuple[str, float]]
class Config:
env_file = ".env"
@classmethod
def parse_env_var(cls, field_name: str, raw_val: str) -> Any:
# converts `str` to `List[str]`
if field_name.endswith("_LINES"):
return raw_val.split(LINE_DELIMITER)
# converts `str` to `List[tuple[str, float]]`
if field_name == "PROJECTS":
return [
(name, price)
for (name, price) in (
line.strip().split(NAME_PRICE_DELIMITER)
for line in raw_val.split(LINE_DELIMITER)
)
]
return cls.json_loads(raw_val)
config = Settings()