Self hosted FLOSS fitness/workout, nutrition and weight tracker
ruff format and isort for issue 1956
Bonicki Wojciech2446631948e8
diff --git a/wger/nutrition/dataclasses.py b/wger/nutrition/dataclasses.pyindex 390947fc7..ffefbbdf7 100644--- a/wger/nutrition/dataclasses.py+++ b/wger/nutrition/dataclasses.py@@ -19,7 +19,11 @@ from dataclasses import ()from typing import Optional-from wger.nutrition.helpers import change_html_entities_to_human_readable, remove_problematic_characters+# wger+from wger.nutrition.helpers import (+ change_html_entities_to_human_readable,+ remove_problematic_characters,+)@dataclass@@ -74,4 +78,4 @@ class IngredientData:def clean_name(self):self.name = remove_problematic_characters(self.name)- self.name = change_html_entities_to_human_readable(self.name)\ No newline at end of file+ self.name = change_html_entities_to_human_readable(self.name)diff --git a/wger/nutrition/helpers.py b/wger/nutrition/helpers.pyindex 28101b0e7..5b504eb21 100644--- a/wger/nutrition/helpers.py+++ b/wger/nutrition/helpers.py@@ -15,26 +15,27 @@# along with this program. If not, see <http://www.gnu.org/licenses/>.# Standard Library+import refrom dataclasses import (asdict,dataclass,)from decimal import Decimalfrom typing import Union-import re+# wgerfrom wger.nutrition.consts import (KJ_PER_KCAL,MEALITEM_WEIGHT_GRAM,MEALITEM_WEIGHT_UNIT,)-from wger.utils.constants import (CHARACTERS_TO_REMOVE_FROM_INGREDIENT_NAME,- HTML_ENTITY_TO_HUMAN_READABLE_MAP,HTML_ENTITY_PATTERN,+ HTML_ENTITY_TO_HUMAN_READABLE_MAP,)+class BaseMealItem:"""Base class for an item (component) of a meal or log@@ -150,11 +151,10 @@ class NutritionalValues:return asdict(self)-def remove_problematic_characters(string: str, characters_to_be_removed: set[str] = CHARACTERS_TO_REMOVE_FROM_INGREDIENT_NAME) -> str:- string = "".join(c for c in string if c not in characters_to_be_removed)+ string = ''.join(c for c in string if c not in characters_to_be_removed)return string@@ -163,4 +163,4 @@ def change_html_entities_to_human_readable() -> str:pattern = re.compile(HTML_ENTITY_PATTERN)string = pattern.sub(lambda m: html_entity_map.get(m.group(0), m.group(0)), string)- return string\ No newline at end of file+ return stringdiff --git a/wger/nutrition/tests/test_helpers.py b/wger/nutrition/tests/test_helpers.pyindex 6053ec3dd..59c59ec2d 100644--- a/wger/nutrition/tests/test_helpers.py+++ b/wger/nutrition/tests/test_helpers.py@@ -18,38 +18,38 @@ from django.test import SimpleTestCase# wgerfrom wger.nutrition.dataclasses import IngredientData-from wger.nutrition.helpers import remove_problematic_characters, change_html_entities_to_human_readable--class HelperFunctionsTestCase(SimpleTestCase):+from wger.nutrition.helpers import (+ change_html_entities_to_human_readable,+ remove_problematic_characters,+)+class HelperFunctionsTestCase(SimpleTestCase):def test_change_html_entities_to_human_readable(self):-- string = "Proper Corn Sweet & Salty"+ string = 'Proper Corn Sweet & Salty'result = change_html_entities_to_human_readable(string)- correct_result = "Proper Corn Sweet & Salty"+ correct_result = 'Proper Corn Sweet & Salty'self.assertEqual(result, correct_result)- string = "Stonebaked Pizza "the american pepperoni""+ string = 'Stonebaked Pizza "the american pepperoni"'result = change_html_entities_to_human_readable(string)correct_result = 'Stonebaked Pizza "the american pepperoni"'self.assertEqual(result, correct_result)- string = "Van Houten VH10 Kakao (12,1%) 1KG"+ string = 'Van Houten VH10 Kakao (12,1%) 1KG'result = change_html_entities_to_human_readable(string)- correct_result = "Van Houten VH10 Kakao (12,1%) 1KG"+ correct_result = 'Van Houten VH10 Kakao (12,1%) 1KG'self.assertEqual(result, correct_result)- string = "String with not existing html entitiy ϧ"+ string = 'String with not existing html entitiy ϧ'result = change_html_entities_to_human_readable(string)- correct_result = "String with not existing html entitiy ϧ"+ correct_result = 'String with not existing html entitiy ϧ'self.assertEqual(result, correct_result)def test_remove_problematic_characters(self):-- string = "Danone Danette Mousse Liégeoise Schokolade 2x(2x80g) 320g"+ string = 'Danone Danette Mousse Liégeoise Schokolade 2x(2x80g) 320g'result = remove_problematic_characters(string)- correct_result = "Danone Danette Mousse Liégeoise Schokolade 2x(2x80g) 320g"+ correct_result = 'Danone Danette Mousse Liégeoise Schokolade 2x(2x80g) 320g'self.assertEqual(result, correct_result)string = "POM'POTES Compotes Gourdes BIO Pomme Framboise 4x90g"@@ -57,7 +57,7 @@ class HelperFunctionsTestCase(SimpleTestCase):correct_result = "POM'POTES Compotes Gourdes BIO Pomme Framboise 4x90g"self.assertEqual(result, correct_result)- string = "String with \x9a control characters \t \x85"+ string = 'String with \x9a control characters \t \x85'result = remove_problematic_characters(string)- correct_result = "String with control characters "- self.assertEqual(result, correct_result)\ No newline at end of file+ correct_result = 'String with control characters '+ self.assertEqual(result, correct_result)diff --git a/wger/nutrition/tests/test_off.py b/wger/nutrition/tests/test_off.pyindex 8894d1a38..5000cb0da 100644--- a/wger/nutrition/tests/test_off.py+++ b/wger/nutrition/tests/test_off.py@@ -113,7 +113,6 @@ class ExtractInfoFromOffTestCase(SimpleTestCase):self.assertEqual(result.fat_saturated, None)def test_ingredient_clean_name(self):-data = IngredientData(name='Stonebaked Pizza "the amer\x96ican \x99pepperoni"',remote_id='1234',@@ -137,4 +136,4 @@ class ExtractInfoFromOffTestCase(SimpleTestCase):license_object_url='https://world.openfoodfacts.org/product/1234/',)data.clean_name()- self.assertEqual(data.name, 'Stonebaked Pizza "the american pepperoni"')\ No newline at end of file+ self.assertEqual(data.name, 'Stonebaked Pizza "the american pepperoni"')diff --git a/wger/utils/constants.py b/wger/utils/constants.pyindex 0d1f7c8e5..a88428b02 100644--- a/wger/utils/constants.py+++ b/wger/utils/constants.py@@ -79,34 +79,34 @@ UUID_CRUNCHES = 'b186f1f8-4957-44dc-bf30-d0b00064ce6f'UUID_LEG_RAISES = 'c2078aac-e4e2-4103-a845-6252a3eb795e'CHARACTERS_GROUPS_TO_REMOVE: dict = {- "control_characters": [- "\x8a",- "\x83",- "\x8f",- "\x8d",- "\x82",- "\x9a",- "\x89",- "\x99",- "\x87",- "\x9c",- "\x80",- "\x96",- "\t",- "\x92",- "\x8c",- "\x90",- "\x9f",- "\x84",- "\x97",- "\x93",- "\x98",- "\x85",+ 'control_characters': [+ '\x8a',+ '\x83',+ '\x8f',+ '\x8d',+ '\x82',+ '\x9a',+ '\x89',+ '\x99',+ '\x87',+ '\x9c',+ '\x80',+ '\x96',+ '\t',+ '\x92',+ '\x8c',+ '\x90',+ '\x9f',+ '\x84',+ '\x97',+ '\x93',+ '\x98',+ '\x85',],- "format_characters": [],- "space_separators": [],- "quotation_or_parenthesis": [],- "symbols_and_emoji": [],+ 'format_characters': [],+ 'space_separators': [],+ 'quotation_or_parenthesis': [],+ 'symbols_and_emoji': [],}CHARACTERS_TO_REMOVE_FROM_INGREDIENT_NAME: set[str] = {@@ -114,31 +114,40 @@ CHARACTERS_TO_REMOVE_FROM_INGREDIENT_NAME: set[str] = {}HTML_ENTITY_TO_HUMAN_READABLE_MAP = {- """: '"',- ">": ">",- "<": "<",- "&": "&",- "°": "°",- "€": "€",- "œ": "œ",- "‘": "‘",- "(": "(", "(": "(",- ")": ")", ")": ")",- """: '"', """: '"',- "'": "'", "'": "'",- "/": "/", "/": "/",- "%": "%", "%": "%",- "&": "&", "&": "&",- "ł": "ł",- "ś": "ś",- "ń": "ń",- "ą": "ą",- "ę": "ę",- "ç": "ç",- "´": "´",- "[": "[", "[": "[",- "]": "]", "]": "]",- "'": "'"+ '"': '"',+ '>': '>',+ '<': '<',+ '&': '&',+ '°': '°',+ '€': '€',+ 'œ': 'œ',+ '‘': '‘',+ '(': '(',+ '(': '(',+ ')': ')',+ ')': ')',+ '"': '"',+ '"': '"',+ ''': "'",+ ''': "'",+ '/': '/',+ '/': '/',+ '%': '%',+ '%': '%',+ '&': '&',+ '&': '&',+ 'ł': 'ł',+ 'ś': 'ś',+ 'ń': 'ń',+ 'ą': 'ą',+ 'ę': 'ę',+ 'ç': 'ç',+ '´': '´',+ '[': '[',+ '[': '[',+ ']': ']',+ ']': ']',+ ''': "'",}-HTML_ENTITY_PATTERN = r"&[a-zA-Z0-9#x]+;"\ No newline at end of file+HTML_ENTITY_PATTERN = r'&[a-zA-Z0-9#x]+;'