small cleanup
This commit is contained in:
parent
9264bba243
commit
009a556c32
1 changed files with 14 additions and 14 deletions
26
recipes.py
26
recipes.py
|
@ -101,7 +101,7 @@ class Units:
|
||||||
for unit in self.units:
|
for unit in self.units:
|
||||||
if unit["name"] == name or "aliases" in unit and name in unit["aliases"]:
|
if unit["name"] == name or "aliases" in unit and name in unit["aliases"]:
|
||||||
return unit
|
return unit
|
||||||
raise RuntimeError(f"unit {name} not found")
|
return None
|
||||||
|
|
||||||
|
|
||||||
class Ingredient(Element):
|
class Ingredient(Element):
|
||||||
|
@ -133,7 +133,7 @@ class Ingredients:
|
||||||
for ing in self.ingredients:
|
for ing in self.ingredients:
|
||||||
if ing["name"] == name or "aliases" in ing and name in ing["aliases"]:
|
if ing["name"] == name or "aliases" in ing and name in ing["aliases"]:
|
||||||
return ing
|
return ing
|
||||||
raise RuntimeError(f"ingredient {name} not found")
|
return None
|
||||||
|
|
||||||
|
|
||||||
class PriceDBs:
|
class PriceDBs:
|
||||||
|
@ -154,28 +154,28 @@ class PriceDB(Element):
|
||||||
self["amount"] = 1.0
|
self["amount"] = 1.0
|
||||||
|
|
||||||
if "unit" in dct:
|
if "unit" in dct:
|
||||||
try:
|
unitstr = dct["unit"]
|
||||||
self["unit"] = self.ctx.units.get(dct["unit"])
|
self["unit"] = self.ctx.units.get(unitstr)
|
||||||
except RuntimeError as e:
|
if self["unit"] == None:
|
||||||
self.ctx.issues.append(str(e))
|
self.ctx.issues.append(f"unknown unit {unitstr}")
|
||||||
else:
|
else:
|
||||||
self["unit"] = None
|
self["unit"] = None
|
||||||
|
|
||||||
|
|
||||||
class IngredientInstance(Element):
|
class IngredientInstance(Element):
|
||||||
def load(self, dct: Dict[str, Any]) -> None:
|
def load(self, dct: Dict[str, Any]) -> None:
|
||||||
try:
|
|
||||||
self["ingredient"] = self.ctx.ingredients.get(dct["name"])
|
self["ingredient"] = self.ctx.ingredients.get(dct["name"])
|
||||||
except RuntimeError as e:
|
if self["ingredient"] == None:
|
||||||
self.ctx.issues.append(str(e))
|
self.ctx.issues.append(f"unknown ingredient {dct['name']}")
|
||||||
|
|
||||||
if "amount" not in dct:
|
if "amount" not in dct:
|
||||||
self["amount"] = 1.0
|
self["amount"] = 1.0
|
||||||
|
|
||||||
if "unit" in dct:
|
if "unit" in dct:
|
||||||
try:
|
unitstr = dct["unit"]
|
||||||
self["unit"] = self.ctx.units.get(dct["unit"])
|
self["unit"] = self.ctx.units.get(unitstr)
|
||||||
except RuntimeError as e:
|
if self["unit"] == None:
|
||||||
self.ctx.issues.append(str(e))
|
self.ctx.issues.append("unknown unit {unitstr}")
|
||||||
else:
|
else:
|
||||||
self["unit"] = None
|
self["unit"] = None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue