initial-setup #1
18
.flake8
Normal file
18
.flake8
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[flake8]
|
||||||
|
max-line-length = 88
|
||||||
|
select = E,W,F,C,N
|
||||||
|
ignore = E203,E501,W503
|
||||||
|
exclude =
|
||||||
|
.git,
|
||||||
|
__pycache__,
|
||||||
|
build,
|
||||||
|
dist,
|
||||||
|
.eggs,
|
||||||
|
*.egg-info,
|
||||||
|
.venv,
|
||||||
|
venv,
|
||||||
|
.tox
|
||||||
|
per-file-ignores =
|
||||||
|
tests/*:F401,F811
|
||||||
|
__init__.py:F401
|
||||||
|
max-complexity = 10
|
||||||
@@ -110,7 +110,7 @@ class PagesEndpoint(BaseEndpoint):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# Build variables object
|
# Build variables object
|
||||||
variables = {}
|
variables: Dict[str, Any] = {}
|
||||||
if limit is not None:
|
if limit is not None:
|
||||||
variables["limit"] = limit
|
variables["limit"] = limit
|
||||||
if offset is not None:
|
if offset is not None:
|
||||||
@@ -129,10 +129,10 @@ class PagesEndpoint(BaseEndpoint):
|
|||||||
variables["orderDirection"] = order_direction
|
variables["orderDirection"] = order_direction
|
||||||
|
|
||||||
# Make request with query and variables
|
# Make request with query and variables
|
||||||
json_data = {"query": query}
|
json_data: Dict[str, Any] = {"query": query}
|
||||||
if variables:
|
if variables:
|
||||||
json_data["variables"] = variables
|
json_data["variables"] = variables
|
||||||
|
|
||||||
response = self._post("/graphql", json_data=json_data)
|
response = self._post("/graphql", json_data=json_data)
|
||||||
|
|
||||||
# Parse response
|
# Parse response
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from datetime import datetime
|
|||||||
from typing import Any, Dict, Optional
|
from typing import Any, Dict, Optional
|
||||||
|
|
||||||
from pydantic import BaseModel as PydanticBaseModel
|
from pydantic import BaseModel as PydanticBaseModel
|
||||||
from pydantic import ConfigDict
|
from pydantic import ConfigDict, field_serializer
|
||||||
|
|
||||||
|
|
||||||
class BaseModel(PydanticBaseModel):
|
class BaseModel(PydanticBaseModel):
|
||||||
@@ -26,8 +26,6 @@ class BaseModel(PydanticBaseModel):
|
|||||||
use_enum_values=True,
|
use_enum_values=True,
|
||||||
# Allow extra fields for forward compatibility
|
# Allow extra fields for forward compatibility
|
||||||
extra="ignore",
|
extra="ignore",
|
||||||
# Serialize datetime as ISO format
|
|
||||||
json_encoders={datetime: lambda v: v.isoformat() if v else None},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def to_dict(self, exclude_none: bool = True) -> Dict[str, Any]:
|
def to_dict(self, exclude_none: bool = True) -> Dict[str, Any]:
|
||||||
@@ -83,6 +81,11 @@ class TimestampedModel(BaseModel):
|
|||||||
created_at: Optional[datetime] = None
|
created_at: Optional[datetime] = None
|
||||||
updated_at: Optional[datetime] = None
|
updated_at: Optional[datetime] = None
|
||||||
|
|
||||||
|
@field_serializer('created_at', 'updated_at')
|
||||||
|
def serialize_datetime(self, value: Optional[datetime]) -> Optional[str]:
|
||||||
|
"""Serialize datetime to ISO format."""
|
||||||
|
return value.isoformat() if value else None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_new(self) -> bool:
|
def is_new(self) -> bool:
|
||||||
"""Check if this is a new (unsaved) model."""
|
"""Check if this is a new (unsaved) model."""
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import re
|
import re
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
from pydantic import Field, validator
|
from pydantic import Field, field_validator
|
||||||
|
|
||||||
from .base import BaseModel, TimestampedModel
|
from .base import BaseModel, TimestampedModel
|
||||||
|
|
||||||
@@ -37,7 +37,8 @@ class Page(TimestampedModel):
|
|||||||
# Editor information
|
# Editor information
|
||||||
editor: Optional[str] = Field(None, description="Editor used")
|
editor: Optional[str] = Field(None, description="Editor used")
|
||||||
|
|
||||||
@validator("path")
|
@field_validator("path")
|
||||||
|
@classmethod
|
||||||
def validate_path(cls, v: str) -> str:
|
def validate_path(cls, v: str) -> str:
|
||||||
"""Validate page path format."""
|
"""Validate page path format."""
|
||||||
if not v:
|
if not v:
|
||||||
@@ -52,7 +53,8 @@ class Page(TimestampedModel):
|
|||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@validator("title")
|
@field_validator("title")
|
||||||
|
@classmethod
|
||||||
def validate_title(cls, v: str) -> str:
|
def validate_title(cls, v: str) -> str:
|
||||||
"""Validate page title."""
|
"""Validate page title."""
|
||||||
if not v or not v.strip():
|
if not v or not v.strip():
|
||||||
@@ -132,7 +134,8 @@ class PageCreate(BaseModel):
|
|||||||
locale: str = Field("en", description="Page locale")
|
locale: str = Field("en", description="Page locale")
|
||||||
editor: str = Field("markdown", description="Editor to use")
|
editor: str = Field("markdown", description="Editor to use")
|
||||||
|
|
||||||
@validator("path")
|
@field_validator("path")
|
||||||
|
@classmethod
|
||||||
def validate_path(cls, v: str) -> str:
|
def validate_path(cls, v: str) -> str:
|
||||||
"""Validate page path format."""
|
"""Validate page path format."""
|
||||||
if not v:
|
if not v:
|
||||||
@@ -147,7 +150,8 @@ class PageCreate(BaseModel):
|
|||||||
|
|
||||||
return v
|
return v
|
||||||
|
|
||||||
@validator("title")
|
@field_validator("title")
|
||||||
|
@classmethod
|
||||||
def validate_title(cls, v: str) -> str:
|
def validate_title(cls, v: str) -> str:
|
||||||
"""Validate page title."""
|
"""Validate page title."""
|
||||||
if not v or not v.strip():
|
if not v or not v.strip():
|
||||||
@@ -172,7 +176,8 @@ class PageUpdate(BaseModel):
|
|||||||
|
|
||||||
tags: Optional[List[str]] = Field(None, description="Page tags")
|
tags: Optional[List[str]] = Field(None, description="Page tags")
|
||||||
|
|
||||||
@validator("title")
|
@field_validator("title")
|
||||||
|
@classmethod
|
||||||
def validate_title(cls, v: Optional[str]) -> Optional[str]:
|
def validate_title(cls, v: Optional[str]) -> Optional[str]:
|
||||||
"""Validate page title if provided."""
|
"""Validate page title if provided."""
|
||||||
if v is not None:
|
if v is not None:
|
||||||
|
|||||||
Reference in New Issue
Block a user