Spaces:
Running
Running
Shri
commited on
Commit
·
5be7c9b
1
Parent(s):
1ac4304
fix: added pydantic validation env
Browse files- requirements/dev.txt +3 -2
- src/core/config.py +38 -8
- src/core/models.py +0 -2
requirements/dev.txt
CHANGED
|
@@ -11,8 +11,9 @@ idna==3.11
|
|
| 11 |
Mako==1.3.10
|
| 12 |
MarkupSafe==3.0.3
|
| 13 |
psycopg2-binary==2.9.11
|
| 14 |
-
pydantic==
|
| 15 |
-
|
|
|
|
| 16 |
python-dotenv==1.2.1
|
| 17 |
sniffio==1.3.1
|
| 18 |
SQLAlchemy==2.0.44
|
|
|
|
| 11 |
Mako==1.3.10
|
| 12 |
MarkupSafe==3.0.3
|
| 13 |
psycopg2-binary==2.9.11
|
| 14 |
+
pydantic==2.12.4
|
| 15 |
+
pydantic-settings==2.12.0
|
| 16 |
+
pydantic_core==2.41.5
|
| 17 |
python-dotenv==1.2.1
|
| 18 |
sniffio==1.3.1
|
| 19 |
SQLAlchemy==2.0.44
|
src/core/config.py
CHANGED
|
@@ -1,14 +1,44 @@
|
|
| 1 |
-
import
|
|
|
|
| 2 |
|
| 3 |
-
from dotenv import load_dotenv
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
-
class Settings:
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
settings = Settings()
|
|
|
|
| 1 |
+
from pydantic import PostgresDsn, computed_field
|
| 2 |
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 3 |
|
|
|
|
| 4 |
|
| 5 |
+
class SMTPConfig(BaseSettings):
|
| 6 |
+
server: str = "smtp_server"
|
| 7 |
+
port: int = 587
|
| 8 |
+
username: str = "smtp_user"
|
| 9 |
+
password: str = "smtp_password"
|
| 10 |
|
| 11 |
|
| 12 |
+
class Settings(BaseSettings):
|
| 13 |
+
JWT_ALGORITHM: str
|
| 14 |
+
JWT_EXPIRE: str
|
| 15 |
+
|
| 16 |
+
POSTGRES_USER: str
|
| 17 |
+
POSTGRES_PASSWORD: str
|
| 18 |
+
POSTGRES_HOST: str
|
| 19 |
+
POSTGRES_DB: str
|
| 20 |
+
|
| 21 |
+
APP_NAME: str = "MyApp"
|
| 22 |
+
ENV: str = "development"
|
| 23 |
+
DEBUG: bool = False
|
| 24 |
+
PORT: int = 8000
|
| 25 |
+
|
| 26 |
+
EMAIL_SERVER: str = "smtp_server"
|
| 27 |
+
EMAIL_PORT: int = 587
|
| 28 |
+
EMAIL_USERNAME: str = "smtp_user"
|
| 29 |
+
EMAIL_PASSWORD: str = "smtp_password"
|
| 30 |
+
|
| 31 |
+
@computed_field
|
| 32 |
+
@property
|
| 33 |
+
def DATABASE_URL(self) -> PostgresDsn:
|
| 34 |
+
return f"postgresql://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}/{self.POSTGRES_DB}"
|
| 35 |
+
|
| 36 |
+
@computed_field
|
| 37 |
+
@property
|
| 38 |
+
def ASYNC_DATABASE_URL(self) -> PostgresDsn:
|
| 39 |
+
return f"postgresql+asyncpg://{self.POSTGRES_USER}:{self.POSTGRES_PASSWORD}@{self.POSTGRES_HOST}/{self.POSTGRES_DB}"
|
| 40 |
+
|
| 41 |
+
model_config = SettingsConfigDict(env_file=".env", case_sensitive=False)
|
| 42 |
+
|
| 43 |
|
| 44 |
settings = Settings()
|
src/core/models.py
CHANGED
|
@@ -23,8 +23,6 @@ class Users(SQLModel, table=True):
|
|
| 23 |
is_verified: bool = Field(
|
| 24 |
default=False, sa_column_kwargs={"server_default": "false"}
|
| 25 |
)
|
| 26 |
-
verification_token: Optional[str] = None
|
| 27 |
-
verification_expires_at: Optional[datetime] = None
|
| 28 |
dob: Optional[date] = None
|
| 29 |
address: Optional[str] = None
|
| 30 |
profile_picture: Optional[str] = None
|
|
|
|
| 23 |
is_verified: bool = Field(
|
| 24 |
default=False, sa_column_kwargs={"server_default": "false"}
|
| 25 |
)
|
|
|
|
|
|
|
| 26 |
dob: Optional[date] = None
|
| 27 |
address: Optional[str] = None
|
| 28 |
profile_picture: Optional[str] = None
|