Files
rengine/shared/models/tag.py
T
Yogesh OjhaandClaude Fable 5.1 0a69f3201c copy: state the fact, delete the explanation
Repo-wide sweep of every user-facing string: frontend components, routes,
config and stores; API details and route docs; shared definitions and
models; stage config help; report prose; MCP, toolbox, interest and
connector text; notification and worker messages.

Descriptions that explained, reassured, justified or restated their title
are deleted. Confirm dialogs name what is removed and stop. Failed actions
read "<Noun> not <verbed>", successes "<Noun> <verbed>". No reader address,
no product-as-subject, no em-dashes or parentheticals in prose.

Mirrors updated on both sides: EPSS band help, compare refusal reasons,
interest labels. Four tests asserting on old wording follow the new text.
The rules are condensed into CLAUDE.md under Writing.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SK5o8xR96cbSnAfjYSTPSe
2026-09-12 11:35:07 +05:30

98 lines
2.5 KiB
Python

import uuid
from datetime import datetime
from typing import TYPE_CHECKING
from pydantic import BaseModel, field_validator
from sqlmodel import Field, Relationship, SQLModel, UniqueConstraint
from shared.utils.datetime import utc_now
from shared.utils.validation import validate_hex_color
if TYPE_CHECKING:
from shared.models.target import Target
class TagSummary(BaseModel):
id: uuid.UUID
name: str
slug: str
color: str
class TargetTag(SQLModel, table=True):
__tablename__ = "target_tags"
target_id: uuid.UUID = Field(
foreign_key="targets.id", primary_key=True, ondelete="CASCADE"
)
tag_id: uuid.UUID = Field(
foreign_key="tags.id", primary_key=True, ondelete="CASCADE"
)
class TagBase(SQLModel):
name: str = Field(max_length=50)
color: str = Field(
max_length=7, description="Hex color code such as #FF5733", default="#6B7280"
)
@field_validator("color")
@classmethod
def validate_color_format(cls, v: str) -> str:
return validate_hex_color(v)
class Tag(TagBase, table=True):
__tablename__ = "tags"
__table_args__ = (
UniqueConstraint("name", "project_id", name="uq_tag_name_project"),
UniqueConstraint("slug", "project_id", name="uq_tag_slug_project"),
)
id: uuid.UUID = Field(default_factory=uuid.uuid4, primary_key=True)
slug: str = Field(max_length=100, index=True)
project_id: uuid.UUID = Field(
foreign_key="projects.id", index=True, ondelete="CASCADE"
)
created_at: datetime = Field(default_factory=utc_now)
created_by: uuid.UUID = Field(foreign_key="users.id")
targets: list["Target"] = Relationship(
link_model=TargetTag, sa_relationship_kwargs={"lazy": "selectin"}
)
class TagCreate(TagBase):
project_slug: str
class TagUpdate(SQLModel):
name: str | None = Field(default=None, max_length=50)
color: str | None = Field(
default=None, max_length=7, description="Hex color code such as #FF5733"
)
@field_validator("color")
@classmethod
def validate_color_format(cls, v: str | None) -> str | None:
if v is None:
return v
return validate_hex_color(v)
class TagRead(TagBase):
id: uuid.UUID
slug: str
project_id: uuid.UUID
created_at: datetime
created_by: uuid.UUID
PREDEFINED_TAGS = [
{"name": "production", "color": "#DC2626"},
{"name": "staging", "color": "#F59E0B"},
{"name": "dev", "color": "#3B82F6"},
{"name": "internal", "color": "#8B5CF6"},
{"name": "external", "color": "#10B981"},
]