Repository navigation
1. Смолянинов Станислав Александрович. 613 #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BICSSA
wants to merge
10
commits into
python-department:main
Choose a base branch
from
BICSSA:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
43481b7
commit 1
BICSSA 720cb1d
Delete test.py
BICSSA 9154e92
Task 2
BICSSA c102a6b
Merge branch 'python-department:main' into main
BICSSA 20f719b
Task 2
BICSSA d7a662e
Merge branch 'python-department:main' into main
BICSSA 1af7d31
Task Compl
BICSSA c2c9cae
Merge branch 'python-department:main' into main
BICSSA 57398fb
4. Смолянинов Станислав Александрович. 613
BICSSA 0183752
Merge branch 'python-department:main' into main
BICSSA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,13 +14,16 @@ | |
|
|
||
| from decimal import Decimal | ||
|
|
||
| from .storage import ( # noqa: F401 | ||
| from .storage import ( | ||
| FIELDS_NAME_INDEX, | ||
| FIELDS_PRICE_INDEX, | ||
| FIELDS_QUANTITY_INDEX, | ||
| NAME_INDEX, | ||
| PRODUCT_ID_INDEX, | ||
| PRODUCT_ID_MIN, | ||
| Product, | ||
| ) | ||
| from .utils import normalize_price # noqa: F401 | ||
| from .utils import normalize_price | ||
|
|
||
|
|
||
| def generate_product_id(storage: list[Product]) -> int: | ||
|
|
@@ -34,8 +37,10 @@ def generate_product_id(storage: list[Product]) -> int: | |
| :data:`~src.part2.storage.PRODUCT_ID_MIN` when ``storage`` is | ||
| empty. | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return 0 | ||
| if not storage: | ||
| return PRODUCT_ID_MIN | ||
|
|
||
| return max(product[PRODUCT_ID_INDEX] for product in storage) + 1 | ||
|
|
||
|
|
||
| def create_product( | ||
|
|
@@ -56,8 +61,18 @@ def create_product( | |
| ``storage`` is left unchanged and a message naming the clashing | ||
| name is printed. | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return 0 | ||
| if any(fields[FIELDS_NAME_INDEX] == product[NAME_INDEX] for product in storage): | ||
| print(f"product name {fields[FIELDS_NAME_INDEX]} is already taken") | ||
| return None | ||
|
|
||
| new_id = generate_product_id(storage) | ||
| new_price = normalize_price(fields[FIELDS_PRICE_INDEX]) | ||
|
|
||
| storage.append( | ||
| (new_id, fields[FIELDS_NAME_INDEX], new_price, fields[FIELDS_QUANTITY_INDEX]) | ||
| ) | ||
|
|
||
| return new_id | ||
|
|
||
|
|
||
| def read_product(storage: list[Product], product_id: int) -> Product | None: | ||
|
|
@@ -72,8 +87,12 @@ def read_product(storage: list[Product], product_id: int) -> Product | None: | |
| ``None`` when no product carries that identifier (a message is | ||
| printed in that case). | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return (0, "", Decimal(0), 0) | ||
| for product in storage: | ||
| if product[PRODUCT_ID_INDEX] == product_id: | ||
| return product | ||
|
|
||
| print(f"no product with id {product_id}") | ||
| return None | ||
|
|
||
|
|
||
| def update_product( | ||
|
|
@@ -97,10 +116,33 @@ def update_product( | |
| Returns: | ||
| The updated ``(product_id, name, price, quantity)`` record, or | ||
| ``None`` when no product carries that identifier (``storage`` is | ||
| left unchanged and a message is printed). | ||
| left unchanged and a message is printed). Also ``None`` when | ||
| product name is already taken. | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return (0, "", Decimal(0), 0) | ||
| index_modifiable_product = -1 | ||
|
|
||
| for index in range(len(storage)): | ||
| if storage[index][NAME_INDEX] == fields[FIELDS_NAME_INDEX]: | ||
| print(f"product name {fields[FIELDS_NAME_INDEX]} is already taken") | ||
| return None | ||
|
|
||
| if storage[index][PRODUCT_ID_INDEX] == product_id: | ||
| index_modifiable_product = index | ||
|
|
||
| if index_modifiable_product == -1: | ||
| print(f"no product with id {product_id}") | ||
| return None | ||
|
|
||
| new_price = normalize_price(fields[FIELDS_PRICE_INDEX]) | ||
|
|
||
| storage[index_modifiable_product] = ( | ||
| product_id, | ||
| fields[FIELDS_NAME_INDEX], | ||
| new_price, | ||
| fields[FIELDS_QUANTITY_INDEX], | ||
| ) | ||
|
|
||
| return storage[index_modifiable_product] | ||
|
|
||
|
|
||
| def delete_product(storage: list[Product], product_id: int) -> int | None: | ||
|
|
@@ -116,5 +158,10 @@ def delete_product(storage: list[Product], product_id: int) -> int | None: | |
| product carried that identifier (``storage`` is left unchanged and | ||
| a message is printed). | ||
| """ | ||
| # TODO: реализуйте функцию | ||
| return 0 | ||
| for i, product in enumerate(storage): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Цикл: встречается несколько раз, лучше было бы использовать везде одну функцию, которая ищет продукт (похоже на |
||
| if product[PRODUCT_ID_INDEX] == product_id: | ||
| del storage[i] | ||
| return product_id | ||
|
|
||
| print(f"no product with id {product_id}") | ||
| return None | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лишняя ошибочная проверка на совпадение имени. Это же функция, которая применяется к уже существующей строке в базе данных.