Coverage for opt/mealie/lib/python3.12/site-packages/mealie/schema/admin/settings.py: 70%

21 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-11-25 17:29 +0000

1from typing import Annotated 1a

2 

3from pydantic import ConfigDict, Field, field_validator 1a

4from slugify import slugify 1a

5 

6from mealie.schema._mealie import MealieModel 1a

7 

8from ..recipe.recipe_category import RecipeCategoryResponse 1a

9 

10 

11class CustomPageBase(MealieModel): 1a

12 name: str 1a

13 slug: Annotated[str | None, Field(validate_default=True)] 1a

14 position: int 1a

15 categories: list[RecipeCategoryResponse] = [] 1a

16 model_config = ConfigDict(from_attributes=True) 1a

17 

18 @field_validator("slug", mode="before") 1a

19 def validate_slug(slug: str, values): 1a

20 name: str = values["name"] 

21 calc_slug: str = slugify(name) 

22 

23 if slug != calc_slug: 

24 slug = calc_slug 

25 

26 return slug 

27 

28 

29class CustomPageOut(CustomPageBase): 1a

30 id: int 1a

31 model_config = ConfigDict(from_attributes=True) 1a