diff --git a/boot.sh b/boot.sh index d2f1d09f4..def7aeea6 100644 --- a/boot.sh +++ b/boot.sh @@ -84,7 +84,6 @@ python manage.py migrate echo "Collecting static files, this may take a while..." -python manage.py collectstatic_js_reverse python manage.py collectstatic --noinput echo "Done" diff --git a/cookbook/helper/automation_helper.py b/cookbook/helper/automation_helper.py index fa333fb3c..87d92b459 100644 --- a/cookbook/helper/automation_helper.py +++ b/cookbook/helper/automation_helper.py @@ -109,7 +109,7 @@ class AutomationEngine: Moves a string that should never be treated as a unit to next token and optionally replaced with default unit e.g. NEVER_UNIT: param1: egg, param2: None would modify ['1', 'egg', 'white'] to ['1', '', 'egg', 'white'] or NEVER_UNIT: param1: egg, param2: pcs would modify ['1', 'egg', 'yolk'] to ['1', 'pcs', 'egg', 'yolk'] - :param1 string: string that should never be considered a unit, will be moved to token[2] + :param1 tokens: string that should never be considered a unit, will be moved to token[2] :param2 (optional) unit as string: will insert unit string into token[1] :return: unit as string (possibly changed by automation) """ @@ -135,7 +135,7 @@ class AutomationEngine: new_unit = self.never_unit[tokens[1].lower()] never_unit = True except KeyError: - return tokens + return tokens, never_unit else: if a := Automation.objects.annotate(param_1_lower=Lower('param_1')).filter(space=self.request.space, type=Automation.NEVER_UNIT, param_1_lower__in=[ tokens[1].lower(), alt_unit.lower()], disabled=False).order_by('order').first(): @@ -144,7 +144,7 @@ class AutomationEngine: if never_unit: tokens.insert(1, new_unit) - return tokens + return tokens, never_unit def apply_transpose_automation(self, string): """ diff --git a/cookbook/helper/image_processing.py b/cookbook/helper/image_processing.py index 70125a33d..d09f08b44 100644 --- a/cookbook/helper/image_processing.py +++ b/cookbook/helper/image_processing.py @@ -84,7 +84,6 @@ def handle_image(request, image_object, filetype): if filetype == '.png': return rescale_image_png(image_object) else: - print('STripping image') return strip_image_meta(image_object, file_format) # TODO webp and gifs bypass the scaling and metadata checks, fix diff --git a/cookbook/helper/ingredient_parser.py b/cookbook/helper/ingredient_parser.py index b4bf0568b..66c94415c 100644 --- a/cookbook/helper/ingredient_parser.py +++ b/cookbook/helper/ingredient_parser.py @@ -212,38 +212,43 @@ class IngredientParser: # a fraction for the amount if len(tokens) > 2: if not self.ignore_rules: - tokens = self.automation.apply_never_unit_automation(tokens) - try: - if unit is not None: - # a unit is already found, no need to try the second argument for a fraction - # probably not the best method to do it, but I didn't want to make an if check and paste the exact same thing in the else as already is in the except - raise ValueError - # try to parse second argument as amount and add that, in case of '2 1/2' or '2 ½' - amount += self.parse_fraction(tokens[1]) - # assume that units can't end with a comma - if len(tokens) > 3 and not tokens[2].endswith(','): - # try to use third argument as unit and everything else as food, use everything as food if it fails - try: - food, note = self.parse_food(tokens[3:]) - unit = tokens[2] - except ValueError: - food, note = self.parse_food(tokens[2:]) - else: + tokens, never_unit_applied = self.automation.apply_never_unit_automation(tokens) + if never_unit_applied: + unit = tokens[1] food, note = self.parse_food(tokens[2:]) - except ValueError: - # assume that units can't end with a comma - if not tokens[1].endswith(','): - # try to use second argument as unit and everything else as food, use everything as food if it fails - try: - food, note = self.parse_food(tokens[2:]) - if unit is None: - unit = tokens[1] - else: - note = tokens[1] - except ValueError: - food, note = self.parse_food(tokens[1:]) else: - food, note = self.parse_food(tokens[1:]) + try: + if unit is not None: + # a unit is already found, no need to try the second argument for a fraction + # probably not the best method to do it, but I didn't want to make an if check and paste the exact same thing in the else as already is in the except + raise ValueError + # try to parse second argument as amount and add that, in case of '2 1/2' or '2 ½' + if tokens[1]: + amount += self.parse_fraction(tokens[1]) + # assume that units can't end with a comma + if len(tokens) > 3 and not tokens[2].endswith(','): + # try to use third argument as unit and everything else as food, use everything as food if it fails + try: + food, note = self.parse_food(tokens[3:]) + unit = tokens[2] + except ValueError: + food, note = self.parse_food(tokens[2:]) + else: + food, note = self.parse_food(tokens[2:]) + except ValueError: + # assume that units can't end with a comma + if not tokens[1].endswith(','): + # try to use second argument as unit and everything else as food, use everything as food if it fails + try: + food, note = self.parse_food(tokens[2:]) + if unit is None: + unit = tokens[1] + else: + note = tokens[1] + except ValueError: + food, note = self.parse_food(tokens[1:]) + else: + food, note = self.parse_food(tokens[1:]) else: # only two arguments, first one is the amount # which means this is the food @@ -276,4 +281,6 @@ class IngredientParser: if len(food.strip()) == 0: raise ValueError(f'Error parsing string {ingredient}, food cannot be empty') + print(f'parsed {ingredient} to {amount} - {unit} - {food} - {note}') + return amount, unit, food, note[:Ingredient._meta.get_field('note').max_length].strip() diff --git a/cookbook/tests/other/docs/reports/tests/pytest.xml b/cookbook/tests/other/docs/reports/tests/pytest.xml index e75cbd73e..692255ba3 100644 --- a/cookbook/tests/other/docs/reports/tests/pytest.xml +++ b/cookbook/tests/other/docs/reports/tests/pytest.xml @@ -1 +1,157 @@ - \ No newline at end of file +args = () +kwargs = {'request': <SubRequest 'space_1' for <Function test_never_unit_automation[arg0]>>} +k = 'space_1__name' + + @functools.wraps(fixture_function) + def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: + for k in set(kwargs.keys()) - function_args: + del kwargs[k] +> return fixture_function(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixturegen.py:88: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixturegen.py:49: in fn + return function(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^ +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +request = <SubRequest 'space_1' for <Function test_never_unit_automation[arg0]>> +factory_name = 'space_factory' + + def model_fixture(request: SubRequest, factory_name: str) -> object: + """Model fixture implementation.""" + factoryboy_request: FactoryboyRequest = request.getfixturevalue("factoryboy_request") + + # Try to evaluate as much post-generation dependencies as possible + factoryboy_request.evaluate(request) + + assert request.fixturename # NOTE: satisfy mypy + fixture_name = request.fixturename + prefix = "".join((fixture_name, SEPARATOR)) + + factory_class: type[Factory[object]] = request.getfixturevalue(factory_name) + + # Create model fixture instance +> NewFactory: type[Factory[object]] = cast(type[Factory[object]], type("Factory", (factory_class,), {})) + ^^^^^^^^^^^^^^^ +E TypeError: type 'Factory' is not subscriptable + +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixture.py:360: TypeErrorargs = () +kwargs = {'request': <SubRequest 'space_1' for <Function test_never_unit_automation[arg2]>>} +k = 'space_1__name' + + @functools.wraps(fixture_function) + def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: + for k in set(kwargs.keys()) - function_args: + del kwargs[k] +> return fixture_function(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixturegen.py:88: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixturegen.py:49: in fn + return function(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^ +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +request = <SubRequest 'space_1' for <Function test_never_unit_automation[arg2]>> +factory_name = 'space_factory' + + def model_fixture(request: SubRequest, factory_name: str) -> object: + """Model fixture implementation.""" + factoryboy_request: FactoryboyRequest = request.getfixturevalue("factoryboy_request") + + # Try to evaluate as much post-generation dependencies as possible + factoryboy_request.evaluate(request) + + assert request.fixturename # NOTE: satisfy mypy + fixture_name = request.fixturename + prefix = "".join((fixture_name, SEPARATOR)) + + factory_class: type[Factory[object]] = request.getfixturevalue(factory_name) + + # Create model fixture instance +> NewFactory: type[Factory[object]] = cast(type[Factory[object]], type("Factory", (factory_class,), {})) + ^^^^^^^^^^^^^^^ +E TypeError: type 'Factory' is not subscriptable + +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixture.py:360: TypeErrorargs = () +kwargs = {'request': <SubRequest 'space_1' for <Function test_never_unit_automation[arg3]>>} +k = 'space_1__name' + + @functools.wraps(fixture_function) + def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: + for k in set(kwargs.keys()) - function_args: + del kwargs[k] +> return fixture_function(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixturegen.py:88: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixturegen.py:49: in fn + return function(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^ +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +request = <SubRequest 'space_1' for <Function test_never_unit_automation[arg3]>> +factory_name = 'space_factory' + + def model_fixture(request: SubRequest, factory_name: str) -> object: + """Model fixture implementation.""" + factoryboy_request: FactoryboyRequest = request.getfixturevalue("factoryboy_request") + + # Try to evaluate as much post-generation dependencies as possible + factoryboy_request.evaluate(request) + + assert request.fixturename # NOTE: satisfy mypy + fixture_name = request.fixturename + prefix = "".join((fixture_name, SEPARATOR)) + + factory_class: type[Factory[object]] = request.getfixturevalue(factory_name) + + # Create model fixture instance +> NewFactory: type[Factory[object]] = cast(type[Factory[object]], type("Factory", (factory_class,), {})) + ^^^^^^^^^^^^^^^ +E TypeError: type 'Factory' is not subscriptable + +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixture.py:360: TypeErrorargs = () +kwargs = {'request': <SubRequest 'space_1' for <Function test_never_unit_automation[arg1]>>} +k = 'space_1__name' + + @functools.wraps(fixture_function) + def wrapper(*args: P.args, **kwargs: P.kwargs) -> T: + for k in set(kwargs.keys()) - function_args: + del kwargs[k] +> return fixture_function(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixturegen.py:88: +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixturegen.py:49: in fn + return function(*args, **kwargs) + ^^^^^^^^^^^^^^^^^^^^^^^^^ +_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ + +request = <SubRequest 'space_1' for <Function test_never_unit_automation[arg1]>> +factory_name = 'space_factory' + + def model_fixture(request: SubRequest, factory_name: str) -> object: + """Model fixture implementation.""" + factoryboy_request: FactoryboyRequest = request.getfixturevalue("factoryboy_request") + + # Try to evaluate as much post-generation dependencies as possible + factoryboy_request.evaluate(request) + + assert request.fixturename # NOTE: satisfy mypy + fixture_name = request.fixturename + prefix = "".join((fixture_name, SEPARATOR)) + + factory_class: type[Factory[object]] = request.getfixturevalue(factory_name) + + # Create model fixture instance +> NewFactory: type[Factory[object]] = cast(type[Factory[object]], type("Factory", (factory_class,), {})) + ^^^^^^^^^^^^^^^ +E TypeError: type 'Factory' is not subscriptable + +..\..\..\venv\Lib\site-packages\pytest_factoryboy\fixture.py:360: TypeError \ No newline at end of file diff --git a/cookbook/tests/other/docs/reports/tests/tests.html b/cookbook/tests/other/docs/reports/tests/tests.html index 9d06d9af3..8da3718d1 100644 --- a/cookbook/tests/other/docs/reports/tests/tests.html +++ b/cookbook/tests/other/docs/reports/tests/tests.html @@ -7,7 +7,7 @@

tests.html

-

Report generated on 31-Mar-2025 at 09:45:35 by pytest-html +

Report generated on 17-Jul-2025 at 12:15:50 by pytest-html v4.1.1

Environment

@@ -61,7 +61,7 @@

Summary

-

2 tests took 00:00:59.

+

0 test took 00:01:28.

(Un)check the boxes to filter the results.