From 4dcd8ffa32b9c8ae773a3b6e8e47bb9da8299df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=81=D0=B5=D0=BD=20=D0=93=D0=B5=D0=B2=D0=BE?= =?UTF-8?q?=D0=BD=D0=B4=D1=8F=D0=BD?= <GevondynA@yandex.ru> Date: Mon, 24 Mar 2025 13:00:18 +0300 Subject: [PATCH 1/3] Modified Recipe.py (added UUID integration and security enhance) --- Recipe.py | 113 +++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 57 deletions(-) diff --git a/Recipe.py b/Recipe.py index 6c80539..770ef63 100644 --- a/Recipe.py +++ b/Recipe.py @@ -1,45 +1,53 @@ -class Recipe: - _ID = "000-aaa-000-aaa" - name = "dev_recipe" - description = "Lorem Impus" - ingredients = ["Test_ingredient1"] - author = "dev" - - def __init__(self, ID, name, description, ingredients, author): - self._ID = ID - self.name = name - self.description = description - self.ingredients = ingredients - self.author = author +import uu_ID - def _print__(self): - print(f"{self.ID} - {self.name}\n{self.description}\n{', '.join(self.ingredients)}\n{self.author}") +class Recipe: + _ID = "12345678-1234-5678-1234-567812345678" + _name = "dev_recipe" + _description = "Lorem Impus" + _ingredients = ["Test_ingredient1"] + _author = "dev" + _date = "21.12.2005" + + def __init__(self, name, description, ingredients, author, date): + self._ID = uuid.uuid1() + self._name = name + self._description = description + self._ingredients = ingredients + self._author = author + self._date = date + + def __str__(self): + return f'''Рецепт - {self._name}:\n + Описание:\n + {self._description}\n + Рнгредиенты: {', '.join(self._ingredients)}\n + Создан пользователем {self._name}\n + Дата создания - {self._date}\n''' def add_ingredient(self, ingredient): - if ingredient not in self.ingredients: - self.ingredients.append(ingredient) + if ingredient not in self._ingredients: + self._ingredients.append(ingredient) def remove_ingredient(self, ingredient): - if ingredient in self.ingredients: - if ingredient in self.ingredients: - self.ingredients.remove(ingredient) + if ingredient in self._ingredients: + self._ingredients.remove(ingredient) def update_ingredient(self, old_ingredient, new_ingredient): - if old_ingredient in self.ingredients: - index = self.ingredients.index(old_ingredient) - self.ingredients[index] = new_ingredient + if old_ingredient in self._ingredients: + index = self._ingredients.index(old_ingredient) + self._ingredients[index] = new_ingredient @property - def full_recipe(self): - return f"{self.name}\n{self.description}\n{', '.join(self.ingredients)}\n{self.author}" # noqa: E501 - @property - def ID(self): - return self._ID - - @full_recipe.setter - def full_recipe(self, new): - self.name, self.description, self.ingredients, self.author = new.split('\n') + def getID(self): + return str(self._ID) + #def full_recipe(self): + # return f"{self._name}\n{self._description}\n{', '.join(self._ingredients)}\n{self._author}" # noqa: E501 + # + #@full_recipe.setter + #def full_recipe(self, new): + # self._name, self._description, self._ingredients, self.author = new.split('\n') +''' recipes =[ Recipe("000-aaa-000-aaa", "dev_recipe", "Lorem Impus", ["Test_ingredient1"], "dev"), # noqa: E501 Recipe("000-aaa-000-aab", "dev_recipe", "Lorem Impus", ["Test_ingredient1"], "dev"),# noqa: E501 @@ -47,11 +55,11 @@ Recipe("000-aaa-000-aac", "dev_recipe", "Lorem Impus", ["Test_ingredient1"], "de Recipe("000-aaa-000-aad", "dev_recipe", "Lorem Impus", ["Test_ingredient1"], "dev")] # noqa: E501 def add_recipe(): - ID = input("Введите ID: ") - checkID = check_ID(ID) - while checkID == 1: - ID = input("Введите корректный айди для удаления:") - checkID = check_ID(ID) + ID = uuid.uuid1() + check_ID = check_ID(ID) + while check_ID == 1: + _ID = input("Введите корректный айди для удаления:") + check_ID = check_ID(ID) index = find_by_ID(ID) name = input("Введите название рецепта: ") description = input("Введите описание: ") @@ -70,10 +78,10 @@ def show_recipe(): def update_recipe(): show_recipes() ID = input("Введите айди рецепта для обновления: ") - checkID = check_ID(ID) - while checkID == 1: + check_ID = check_ID(ID) + while check_ID == 1: ID = input("Введите корректный айди для удаления:") - checkID = check_ID(ID) + check_ID = check_ID(ID) index = find_by_ID(ID) if 0 <= index < len(recipes): recipes[index].name = input("Введите РЅРѕРІРѕРµ название: ") @@ -101,11 +109,11 @@ def delete_recipe(): def check_ID(ID): check = list(ID.split('-')) if len(check) != 4: - print("Некорректный формат ID") + print("Некорректный формат _ID") return 1 for i in range(4): if len(check[i]) != 4: - print("Некорректный формат ID") + print("Некорректный формат _ID") return 1 return 0 @@ -114,32 +122,23 @@ def find_by_ID(ID): print("Некорректный айди для РїРѕРёСЃРєР°.") return -1 for ind in range(len(recipes)): - if (recipes[i]).ID == ID: + if (recipes[i])._ID == ID: return ind print("РђР№РґРё РЅРµ найден РІ реестре рецептов.") return -2 def delete_recipe(): - checkID = 0; + check_ID = 0; index = 0; ID = input("Введите ID рецепта для удаления: ") - checkID = check_ID(ID) - while checkID == 1: + check_ID = check_ID(ID) + while check_ID == 1: ID = input("Введите корректный айди для удаления:") - checkID = check_ID(ID) + check_ID = check_ID(ID) index = find_by_ID(ID) if index < 0: print("Удаление прошло РЅРµ успешно.") return 1 del recipes[index] return 0 - - - - - - -#recipes[1].add_ingredient("New_ingredient") -#recipes[3].update_ingredient("Test_ingredient1", "Updated_ingredient") -#recipes[0].remove_ingredient("New_ingredient") - +''' -- GitLab From 9c0bfef596f59bf47b3882b1858784f80e2f66b4 Mon Sep 17 00:00:00 2001 From: "nukhimzon.ar" <nukhimzon.ar@dozen.mephi.ru> Date: Mon, 24 Mar 2025 13:05:18 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3=D0=B0=20?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D1=85=20=D0=BA=D0=B0=D1=82=D0=B0=D0=BB=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Favorites_catalogue.py | 41 ++++++++++++++++++++++++++++++++ Main_catalogue.py | 39 +++++++++++++++++++++++++++++++ Panel.py | 34 +++++++++++++++++++++++++++ Popular_catalogue.py | 53 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100644 Favorites_catalogue.py create mode 100644 Main_catalogue.py create mode 100644 Panel.py create mode 100644 Popular_catalogue.py diff --git a/Favorites_catalogue.py b/Favorites_catalogue.py new file mode 100644 index 0000000..46f8c03 --- /dev/null +++ b/Favorites_catalogue.py @@ -0,0 +1,41 @@ +import Recipe +import Main_catalogue + +class Favorites_Catalogue(Main_catalogue): + + recipes = [Recipe("000-aaa-000-aaa", "dev_recipe", "Lorem Impus", ["Test_ingredient1"], "dev")] # noqa: E501 + def __init__(self, recipes=None): + super().__init__(recipes if recipes else []) + self.favorites = [] + + def add_to_favorites(self, recipe): + if recipe in self.recipes and recipe not in self.favorites: + self.favorites.append(recipe) + print("Рецепт добавлен") + return 0 + elif recipe in self.favorites: + print("Рецепт СѓР¶Рµ РІ избранном") + return 1 + else: + print("Рецепт отсутствует РІ каталоге") + return 1 + + def remove_from_favorites(self, recipe): + if recipe in self.favorites: + self.favorites.remove(recipe) + print("Рецепт удален РёР· избранного.") + return 0 + else: + print("Рецепта нет РІ избранном!") + return 1 + + def display_favorites(self): + if not self.favorites: + print("Рзбранных рецептов РїРѕРєР° нет.") + return 1 + else: + print("\n=== Рзбранные рецепты ===") + for recipe in self.favorites: + print(recipe.full_recipe) + print("-" * 50) + return 0 diff --git a/Main_catalogue.py b/Main_catalogue.py new file mode 100644 index 0000000..f449684 --- /dev/null +++ b/Main_catalogue.py @@ -0,0 +1,39 @@ +import Recipe + +class Main_Catalogue: + + recipes = [Recipe("000-aaa-000-aaa", "dev_recipe", "Lorem Impus", ["Test_ingredient1"], "dev")] # noqa: E501 + + def __init__(self,recipes): + self.recipes = recipes + def add_recipe(self, recipe): + if recipe not in self.recipes: + self.recipes.append(recipe) + print("Рецепт добавлен РІ общий каталога.") + return 0 + else: + print("Такой рецепт СѓР¶Рµ существует") + return 0 + def remove(self, recipe): + if recipe in self.recipes: + print("Рецепт удален РёР· общего каталога.") + self.recipes.remove(recipe) + return 0 + else: + print("Такого рецепта нет РІ общем каталоге.") + return 1 + def update_ingredient(self, old_recipe, new_recipe): + if old_recipe in self.recipes: + index = self.recipes.index(old_recipe) + self.recipes[index] = new_recipe + print("Рецепт изменён") + def sort(self): + self.recipes.sort(key=lambda recipe: recipe.name) + def display_recipes(self): + for recipe in self.recipes: + print(recipe.full_recipe) + + #recipe = Recipe("000-aaa-000-aaa", "dev_recipe", "Lorem Impus", ["Test_ingredient1"], "dev") # noqa: E501 + + + diff --git a/Panel.py b/Panel.py new file mode 100644 index 0000000..21d164e --- /dev/null +++ b/Panel.py @@ -0,0 +1,34 @@ +import Recipe + +class Panel(Recipe): + _views = 0; + _stats = 0; + + def __init__(self, name, description, ingredients, author, date, views, stats): + self._ID = uuid.uid1() + self._name = name + self._description = description + self._ingredients = ingredients + self._author = author + self._date = date + self._views = views + self._stats = stats + + def vote(self, score): + self._stats += score + + def view(self): + print(self) + self._views += 1 + + @properties + def getstatistics(self): + return f"РљРѕР»-РІРѕ просмотров {self._views}\nСтатистика ==-{self._statistics}-==\n" + @properties + def getviews(self): + return self._views + @properties + def getstats(self): + return self._stats + + diff --git a/Popular_catalogue.py b/Popular_catalogue.py new file mode 100644 index 0000000..0863d95 --- /dev/null +++ b/Popular_catalogue.py @@ -0,0 +1,53 @@ +import Recipe +import Main_catalogue +import Panel + +class Popular_Catalogue(Main_catalogue): + + recipes = [Recipe("000-aaa-000-aaa", "dev_recipe", "Lorem Impus", ["Test_ingredient1"], "dev")] # noqa: E501 + def __init__(self, recipes=None): + super().__init__(recipes if recipes else []) + self.popular = [] + + def add_to_popular(self, recipe): + if recipe in self.recipes and recipe not in self.popular: + self.popular.append(recipe) + print("Рецепт добавлен") + return 0 + elif recipe in self.popular: + print("Рецепт СѓР¶Рµ РІ популярных") + return 1 + else: + print("Рецепт отсутствует РІ каталоге") + return 1 + + def remove_from_popular(self, recipe): + if recipe in self.popular: + self.popular.remove(recipe) + print("Рецепт удален РёР· популярных") + return 0 + else: + print("Рецепта нет РІ популярных") + return 1 + + def display_popular(self): + if not self.popular: + print("Популярных рецептов РїРѕРєР° нет.") + return 1 + else: + print("\n=== Рзбранные рецепты ===") + for recipe in self.popular: + print(recipe.full_recipe) + print("-" * 50) + return 0 + def sort_by_popularity(self, by="views"): + if not self.popular: + print("Популярных рецептов РїРѕРєР° нет.") + return 1 + if by == "views": + self.popular.sort(key=lambda recipe: recipe.getviews, reverse=True) + print("Сортировка РїРѕ просмотрам завершена") + elif by == "stats": + self.popular.sort(key=lambda recipe: recipe.getstats, reverse=True) + print("Сортировка РїРѕ рейтингу завершена") + return 0 -- GitLab From 977c14edd57db59350667559d8186001e456fd6f Mon Sep 17 00:00:00 2001 From: "nukhimzon.ar" <nukhimzon.ar@dozen.mephi.ru> Date: Sun, 30 Mar 2025 20:35:57 +0300 Subject: [PATCH 3/3] Adding catalogues --- .idea/Python_test.iml | 8 ++ .../inspectionProfiles/profiles_settings.xml | 6 ++ .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 ++ .idea/workspace.xml | 42 ++++++++++ Main_catalogue.py | 78 ++++++++++++++----- 6 files changed, 128 insertions(+), 20 deletions(-) create mode 100644 .idea/Python_test.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml diff --git a/.idea/Python_test.iml b/.idea/Python_test.iml new file mode 100644 index 0000000..d0876a7 --- /dev/null +++ b/.idea/Python_test.iml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<module type="PYTHON_MODULE" version="4"> + <component name="NewModuleRootManager"> + <content url="file://$MODULE_DIR$" /> + <orderEntry type="inheritedJdk" /> + <orderEntry type="sourceFolder" forTests="false" /> + </component> +</module> \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ +<component name="InspectionProjectProfileManager"> + <settings> + <option name="USE_PROJECT_PROFILE" value="false" /> + <version value="1.0" /> + </settings> +</component> \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f39d80a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectModuleManager"> + <modules> + <module fileurl="file://$PROJECT_DIR$/.idea/Python_test.iml" filepath="$PROJECT_DIR$/.idea/Python_test.iml" /> + </modules> + </component> +</project> \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="" vcs="Git" /> + </component> +</project> \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..b43baea --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ChangeListManager"> + <list default="true" id="0dd50545-40b2-4ebc-b5cd-17abc85dea1a" name="Changes" comment="" /> + <option name="SHOW_DIALOG" value="false" /> + <option name="HIGHLIGHT_CONFLICTS" value="true" /> + <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> + <option name="LAST_RESOLUTION" value="IGNORE" /> + </component> + <component name="ProjectColorInfo"><![CDATA[{ + "associatedIndex": 6 +}]]></component> + <component name="ProjectId" id="2ul7SOiITSCg9Q8McN57Ly6HCNx" /> + <component name="ProjectViewState"> + <option name="hideEmptyMiddlePackages" value="true" /> + <option name="showLibraryContents" value="true" /> + </component> + <component name="PropertiesComponent"><![CDATA[{ + "keyToString": { + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true" + } +}]]></component> + <component name="SharedIndexes"> + <attachedChunks> + <set> + <option value="bundled-python-sdk-09665e90c3a7-d3b881c8e49f-com.jetbrains.pycharm.community.sharedIndexes.bundled-PC-233.15026.15" /> + </set> + </attachedChunks> + </component> + <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> + <component name="TaskManager"> + <task active="true" id="Default" summary="Default task"> + <changelist id="0dd50545-40b2-4ebc-b5cd-17abc85dea1a" name="Changes" comment="" /> + <created>1742811306263</created> + <option name="number" value="Default" /> + <option name="presentableId" value="Default" /> + <updated>1742811306263</updated> + </task> + <servers /> + </component> +</project> \ No newline at end of file diff --git a/Main_catalogue.py b/Main_catalogue.py index f449684..534ae2d 100644 --- a/Main_catalogue.py +++ b/Main_catalogue.py @@ -1,4 +1,5 @@ import Recipe +import uu_ID class Main_Catalogue: @@ -6,33 +7,70 @@ class Main_Catalogue: def __init__(self,recipes): self.recipes = recipes - def add_recipe(self, recipe): - if recipe not in self.recipes: - self.recipes.append(recipe) - print("Рецепт добавлен РІ общий каталога.") - return 0 - else: - print("Такой рецепт СѓР¶Рµ существует") - return 0 - def remove(self, recipe): - if recipe in self.recipes: - print("Рецепт удален РёР· общего каталога.") - self.recipes.remove(recipe) + def add_recipe(): + ID = uuid.uuid1() + check_ID = check_ID(ID) + while check_ID == 1: + _ID = input("Введите корректный айди для удаления:") + check_ID = check_ID(ID) + index = find_by_ID(ID) + name = input("Введите название рецепта: ") + description = input("Введите описание: ") + ingredients = input("Введите ингредиенты (через запятую): ").split(", ") + author = input("Введите автора: ") + if find_by_ID(ID) != -2: + print("Рецепт СЃ данным айди СѓР¶Рµ есть РІ реестре.") + return 1 + recipes.append(Recipe(ID, name, description, ingredients, author)) + return 0 + + def show_recipe(): + for i, recipe in enumerate(recipes, start=1): + print(f"\nРецепт {i}:\n{recipe[i]}\n{'-' * 30}") + + def update_recipe(): + show_recipes() + ID = input("Введите айди рецепта для обновления: ") + check_ID = check_ID(ID) + while check_ID == 1: + ID = input("Введите корректный айди для удаления:") + check_ID = check_ID(ID) + index = find_by_ID(ID) + if 0 <= index < len(recipes): + recipes[index].name = input("Введите РЅРѕРІРѕРµ название: ") + recipes[index].description = input("Введите РЅРѕРІРѕРµ описание: ") + recipes[index].ingredients = input("Введите новые ингредиенты (через запятую): ").split(", ") + recipes[index].author = input("Введите РЅРѕРІРѕРіРѕ автора: ") + print("Рецепт обновлен!") return 0 else: - print("Такого рецепта нет РІ общем каталоге.") + print("Некорректный номер.") return 1 - def update_ingredient(self, old_recipe, new_recipe): - if old_recipe in self.recipes: - index = self.recipes.index(old_recipe) - self.recipes[index] = new_recipe - print("Рецепт изменён") + def sort(self): self.recipes.sort(key=lambda recipe: recipe.name) def display_recipes(self): for recipe in self.recipes: - print(recipe.full_recipe) - + print(recipe.full_recipe) + def check_ID(ID): + check = list(ID.split('-')) + if len(check) != 4: + print("Некорректный формат _ID") + return 1 + for i in range(4): + if len(check[i]) != 4: + print("Некорректный формат _ID") + return 1 + return 0 + def find_by_ID(ID): + if check_ID(ID) == 1: + print("Некорректный айди для РїРѕРёСЃРєР°.") + return -1 + for ind in range(len(recipes)): + if (recipes[i])._ID == ID: + return ind + print("РђР№РґРё РЅРµ найден РІ реестре рецептов.") + return -2 #recipe = Recipe("000-aaa-000-aaa", "dev_recipe", "Lorem Impus", ["Test_ingredient1"], "dev") # noqa: E501 -- GitLab