Skip to content

Commit

Permalink
fix: circular import in models
Browse files Browse the repository at this point in the history
  • Loading branch information
SaintShit committed Jan 9, 2025
1 parent 40041f2 commit 9e24dfb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
25 changes: 14 additions & 11 deletions app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
import secrets
from datetime import datetime
from enum import Enum
from typing import Dict, List, Optional, Union
from typing import Dict, List, Literal, Optional, Union

from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator
from pydantic import (BaseModel, ConfigDict, Field, field_validator,
model_validator)

from app import xray
from app.models.admin import Admin
from app.models.proxy import ProxySettings, ProxyTypes
from app.subscription.share import generate_v2ray_links
from app.utils.jwt import create_subscription_token
from config import XRAY_SUBSCRIPTION_PATH, XRAY_SUBSCRIPTION_URL_PREFIX
Expand Down Expand Up @@ -57,15 +56,15 @@ class NextPlanModel(BaseModel):


class User(BaseModel):
proxies: Dict[ProxyTypes, ProxySettings] = {}
proxies: Dict["ProxyTypes", "ProxySettings"] = {}
expire: Optional[int] = Field(None, nullable=True)
data_limit: Optional[int] = Field(
ge=0, default=None, description="data_limit can be 0 or greater"
)
data_limit_reset_strategy: UserDataLimitResetStrategy = (
UserDataLimitResetStrategy.no_reset
)
inbounds: Dict[ProxyTypes, List[str]] = {}
inbounds: Dict["ProxyTypes", List[str]] = {}
note: Optional[str] = Field(None, nullable=True)
sub_updated_at: Optional[datetime] = Field(None, nullable=True)
sub_last_user_agent: Optional[str] = Field(None, nullable=True)
Expand Down Expand Up @@ -288,9 +287,9 @@ class UserResponse(User):
links: List[str] = []
subscription_url: str = ""
proxies: dict
excluded_inbounds: Dict[ProxyTypes, List[str]] = {}
excluded_inbounds: Dict["ProxyTypes", List[str]] = {}

admin: Optional[Admin] = None
admin: Optional["Admin"] = None
model_config = ConfigDict(from_attributes=True)

@model_validator(mode="after")
Expand Down Expand Up @@ -328,10 +327,10 @@ def cast_to_int(cls, v):


class SubscriptionUserResponse(UserResponse):
admin: Admin | None = Field(default=None, exclude=True)
excluded_inbounds: Dict[ProxyTypes, List[str]] | None = Field(None, exclude=True)
admin: Literal["Admin"] | None = Field(default=None, exclude=True)
excluded_inbounds: Dict["ProxyTypes", List[str]] | None = Field(None, exclude=True)
note: str | None = Field(None, exclude=True)
inbounds: Dict[ProxyTypes, List[str]] | None = Field(None, exclude=True)
inbounds: Dict["ProxyTypes", List[str]] | None = Field(None, exclude=True)
auto_delete_in_days: int | None = Field(None, exclude=True)
model_config = ConfigDict(from_attributes=True)

Expand Down Expand Up @@ -364,3 +363,7 @@ class UserUsagesResponse(BaseModel):

class UsersUsagesResponse(BaseModel):
usages: List[UserUsageResponse]


from app.models.admin import Admin # noqa
from app.models.proxy import ProxySettings, ProxyTypes # noqa
8 changes: 5 additions & 3 deletions app/models/user_template.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from typing import Dict, List, Optional

from pydantic import field_validator, ConfigDict, BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field, field_validator

from app import xray
from app.models.proxy import ProxyTypes


class UserTemplate(BaseModel):
Expand All @@ -17,7 +16,7 @@ class UserTemplate(BaseModel):
username_prefix: Optional[str] = Field(max_length=20, min_length=1, default=None)
username_suffix: Optional[str] = Field(max_length=20, min_length=1, default=None)

inbounds: Dict[ProxyTypes, List[str]] = {}
inbounds: Dict["ProxyTypes", List[str]] = {}


class UserTemplateCreate(UserTemplate):
Expand Down Expand Up @@ -63,3 +62,6 @@ def validate_inbounds(cls, v):
final[protocol] = [inbound["tag"]]
return final
model_config = ConfigDict(from_attributes=True)


from app.models.proxy import ProxyTypes # noqa

0 comments on commit 9e24dfb

Please sign in to comment.