-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.py
58 lines (47 loc) · 1.99 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
"""Конфигурационный файл с настройками проекта."""
import os
from functools import lru_cache
from os.path import join
from pathlib import Path
from typing import Dict
from dotenv import load_dotenv
from pydantic import BaseSettings
BASE_DIR: Path = Path(__file__).resolve(strict=False).parent
load_dotenv(dotenv_path=join(BASE_DIR, '.env'))
CONFIG_EMAIL = {
'MAIL_USERNAME': os.getenv('EMAIL_USERNAME'),
'MAIL_PASSWORD': os.getenv('EMAIL_PASSWORD'),
'MAIL_FROM': os.getenv('EMAIL_FROM'),
'MAIL_TO': os.getenv('EMAIL_TO'),
'MAIL_PORT': os.getenv('EMAIL_PORT'),
'MAIL_SERVER': os.getenv('EMAIL_SERVER')
}
MAIL_TO = os.getenv('EMAIL_TO')
NOTIFICATION_SEND_TIME = os.getenv('NOTIFICATION_SEND_TIME')
SECRET_KEY = os.getenv('SECRET_KEY')
class Settings(BaseSettings):
"""Класс настроек."""
base_dir: Path = BASE_DIR
template_dir: Path = join(BASE_DIR, 'templates')
static_dir: Path = join(BASE_DIR, 'static')
database: Dict[str, str] = {key: os.getenv(key) for key in ('DB_SERVICE',
'DB_USER',
'DB_PASS',
'DB_HOST',
'DB_PORT',
'DB_NAME')}
@property
def db_sync_connections(self) -> str: # noqa
"""Функция для получения настроек базы данных."""
return '%s://%s:%s@%s:%s/%s' % ( # noqa
self.database['DB_SERVICE'],
self.database['DB_USER'],
self.database['DB_PASS'],
self.database['DB_HOST'],
self.database['DB_PORT'],
self.database['DB_NAME']
)
@lru_cache()
def get_settings() -> Settings:
"""Функция получения настроек."""
return Settings()