Skip to content

Commit

Permalink
Revert "fix: circular import in models"
Browse files Browse the repository at this point in the history
This reverts commit 9e24dfb.
  • Loading branch information
ImMohammad20000 committed Jan 9, 2025
1 parent 5454c1c commit 216e81c
Showing 2 changed files with 14 additions and 19 deletions.
25 changes: 11 additions & 14 deletions app/models/user.py
Original file line number Diff line number Diff line change
@@ -2,12 +2,13 @@
import secrets
from datetime import datetime
from enum import Enum
from typing import Dict, List, Literal, Optional, Union
from typing import Dict, List, 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
@@ -56,15 +57,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)
@@ -287,9 +288,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")
@@ -327,10 +328,10 @@ def cast_to_int(cls, v):


class SubscriptionUserResponse(UserResponse):
admin: Literal["Admin"] | None = Field(default=None, exclude=True)
excluded_inbounds: Dict["ProxyTypes", List[str]] | None = Field(None, exclude=True)
admin: 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)

@@ -363,7 +364,3 @@ 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: 3 additions & 5 deletions app/models/user_template.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from typing import Dict, List, Optional

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

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


class UserTemplate(BaseModel):
@@ -16,7 +17,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):
@@ -62,6 +63,3 @@ 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 216e81c

Please sign in to comment.