step sections
This commit is contained in:
parent
98c77cb102
commit
e4890b6fd8
3 changed files with 48 additions and 11 deletions
|
@ -205,6 +205,14 @@ class IngredientInstance(Element):
|
|||
price=price,
|
||||
)
|
||||
|
||||
class StepSection(Element):
|
||||
def __init__(self, ctx: Context, title: str, steps: List[str]) -> None:
|
||||
self.title = title
|
||||
self.steps = steps
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, ctx: Context, dct: Dict[str, Any]) -> Self:
|
||||
return cls(ctx, dct["section"], dct["steps"])
|
||||
|
||||
class Recipe(Element):
|
||||
def __init__(
|
||||
|
@ -214,7 +222,7 @@ class Recipe(Element):
|
|||
ingredients: List[IngredientInstance],
|
||||
subrecipes: List["Recipe"],
|
||||
price: Optional["PriceDB"],
|
||||
steps: List[str],
|
||||
stepsections: List[StepSection],
|
||||
) -> None:
|
||||
super().__init__(ctx)
|
||||
self.srcpath = ""
|
||||
|
@ -223,7 +231,7 @@ class Recipe(Element):
|
|||
self.ingredients = ingredients
|
||||
self.subrecipes = subrecipes
|
||||
self.price = price
|
||||
self.steps = steps
|
||||
self.stepsections = stepsections
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, ctx: Context, dct: Dict[str, Any]) -> Self:
|
||||
|
@ -268,16 +276,24 @@ class Recipe(Element):
|
|||
currency=currency,
|
||||
)
|
||||
|
||||
steps = []
|
||||
stepsections: List[StepSection] = []
|
||||
if "steps" in dct:
|
||||
steps = dct["steps"]
|
||||
defaultstepsection = StepSection(ctx, "default", [])
|
||||
stepsections = [defaultstepsection]
|
||||
for step in dct["steps"]:
|
||||
if isinstance(step, str):
|
||||
defaultstepsection.steps.append(step)
|
||||
if isinstance(step, dict):
|
||||
section = StepSection.from_dict(ctx, step)
|
||||
stepsections.append(section)
|
||||
|
||||
return cls(
|
||||
ctx=ctx,
|
||||
title=dct["title"],
|
||||
ingredients=ingredients,
|
||||
subrecipes=subrecipes,
|
||||
price=price,
|
||||
steps=steps,
|
||||
stepsections=stepsections,
|
||||
)
|
||||
|
||||
class Conversion(Element):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue