-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.py
85 lines (61 loc) · 2.45 KB
/
constants.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from typing import cast, TypeVar, NewType, overload, Union, Callable, Optional
from decouple import config
from flet import colors
LOGO_PATH = '/Fox_Hub_logo.png'
SHEET = '#9FA2B4'
PRIMARY = colors.PRIMARY
BORDER_COLOR = colors.GREY
BG_COLOR = colors.WHITE
SHEET_BG_COLOR = colors.with_opacity(0.1, color=SHEET)
class Fonts:
URLS = {
"Kanit": "https://raw.githubusercontent.com/google/fonts/master/ofl/kanit/Kanit-Bold.ttf",
"Open Sans": "/fonts/OpenSans-Regular.ttf"
}
T = TypeVar("T")
V = TypeVar("V")
Sentinel = NewType("Sentinel", object)
_MISSING = cast(Sentinel, object())
@overload
def _get_config(search_path: str, cast: None = None, default: Union[V, Sentinel] = _MISSING) -> Union[str, V]:
...
@overload
def _get_config(search_path: str, cast: Callable[[str], T], default: Union[V, Sentinel] = _MISSING) -> Union[T, V]:
...
def _get_config(
search_path: str,
cast: Optional[Callable[[str], object]] = None,
default: object = _MISSING,
) -> object:
"""Wrapper around decouple.config that can handle typing better."""
if cast is None:
cast = lambda x: x
if default is not _MISSING:
obj = config(search_path, cast=cast, default=default)
else:
obj = config(search_path, cast=cast)
return obj
class Settings:
DEBUG = _get_config("DEBUG", bool, default=False)
class Connection:
"""Config connection to database"""
DEV = _get_config("DEV", bool, False)
if DEV:
DATABASE_URL = _get_config("DATABASE_URL") # postgresql+psycopg2://{user}:{password}@{host}:{port}/{db_name}
ASYNC_DATABASE_URL = _get_config("ASYNC_DATABASE_URL")
else:
DATABASE_URL = _get_config("LOCAL_DB_URL")
ASYNC_DATABASE_URL = _get_config("ASYNC_LOCAL_DB_URL")
DATABASE_USERNAME = _get_config("DATABASE_USERNAME", str, "postgres")
DATABASE_PASSWORD = _get_config("DATABASE_PASSWORD", str, "12345678")
DATABASE_PORT = _get_config("DATABASE_PORT", str, "5432")
DATABASE_HOSTNAME = _get_config("DATABASE_HOSTNAME", str, "postgres")
DATABASE_NAME = _get_config("DATABASE_NAME", str, default="postgres")
TEST_DATABASE = _get_config(
"TEST_DATABASE", str,
default='postgresql+psycopg2://postgres:postgres@localhost:5432/test_db'
)
class UserDefaults:
"""User default setting"""
DEFAULT_USERNAME = _get_config("DEFAULT_USERNAME", str, "admin")
DEFAULT_PASSWORD = _get_config("DEFAULT_PASSWORD", str, "admin")