From 495af3e0cff7aa7c31878accacfc82eba6be7926 Mon Sep 17 00:00:00 2001 From: iskomir <151797312+iskomir@users.noreply.github.com> Date: Sun, 4 Feb 2024 15:18:26 +0300 Subject: [PATCH 1/4] Update image.py --- calendar_backend/methods/image.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/calendar_backend/methods/image.py b/calendar_backend/methods/image.py index a0504bff..72b06c08 100644 --- a/calendar_backend/methods/image.py +++ b/calendar_backend/methods/image.py @@ -18,7 +18,10 @@ settings = get_settings() -async def upload_lecturer_photo(lecturer_id: int, session: Session, file: UploadFile = File(...)) -> Photo: +async def upload_lecturer_photo(lecturer_id: int, session: Session, file: UploadFile = File(...)) -> Photo: + """ + Uploads the lecturer's photo to the database + """ lecturer = Lecturer.get(lecturer_id, session=session) random_string = ''.join(random.choice(string.ascii_letters) for _ in range(32)) ext = file.filename.split('.')[-1] @@ -43,7 +46,10 @@ async def upload_lecturer_photo(lecturer_id: int, session: Session, file: Upload return photo -def process_image(image_bytes: bytes) -> None: +def process_image(image_bytes: bytes) -> None: + """ + Checks the integrity of the image + """ with Image.open(BytesIO(image_bytes)) as image: try: image.verify() @@ -54,12 +60,18 @@ def process_image(image_bytes: bytes) -> None: thread_pool = ThreadPoolExecutor() -async def async_image_process(image_bytes: bytes) -> None: +async def async_image_process(image_bytes: bytes) -> None: + """ + Asynchronous image processing + """ loop = asyncio.get_event_loop() await loop.run_in_executor(thread_pool, partial(process_image, image_bytes)) -def get_photo_webpath(file_path: str): +def get_photo_webpath(file_path: str): + """ +Returns the webpath of the file + """ file_path = file_path.removeprefix('/') root_path = settings.ROOT_PATH.removesuffix('/') return f"{root_path}/static/photo/lecturer/{file_path}" From 5cb741c4e20bfb59b00134c27dbbc4d7032d2696 Mon Sep 17 00:00:00 2001 From: iskomir <151797312+iskomir@users.noreply.github.com> Date: Sun, 4 Feb 2024 15:41:40 +0300 Subject: [PATCH 2/4] Update image.py --- calendar_backend/methods/image.py | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/calendar_backend/methods/image.py b/calendar_backend/methods/image.py index 72b06c08..8b7c56ec 100644 --- a/calendar_backend/methods/image.py +++ b/calendar_backend/methods/image.py @@ -18,10 +18,10 @@ settings = get_settings() -async def upload_lecturer_photo(lecturer_id: int, session: Session, file: UploadFile = File(...)) -> Photo: - """ - Uploads the lecturer's photo to the database - """ +async def upload_lecturer_photo(lecturer_id: int, session: Session, file: UploadFile = File(...)) -> Photo: + """ + Uploads the lecturer's photo to the database + """ lecturer = Lecturer.get(lecturer_id, session=session) random_string = ''.join(random.choice(string.ascii_letters) for _ in range(32)) ext = file.filename.split('.')[-1] @@ -46,10 +46,10 @@ async def upload_lecturer_photo(lecturer_id: int, session: Session, file: Upload return photo -def process_image(image_bytes: bytes) -> None: - """ - Checks the integrity of the image - """ +def process_image(image_bytes: bytes) -> None: + """ + Checks the integrity of the image + """ with Image.open(BytesIO(image_bytes)) as image: try: image.verify() @@ -60,18 +60,18 @@ def process_image(image_bytes: bytes) -> None: thread_pool = ThreadPoolExecutor() -async def async_image_process(image_bytes: bytes) -> None: - """ - Asynchronous image processing - """ +async def async_image_process(image_bytes: bytes) -> None: + """ + Asynchronous image processing + """ loop = asyncio.get_event_loop() await loop.run_in_executor(thread_pool, partial(process_image, image_bytes)) -def get_photo_webpath(file_path: str): - """ -Returns the webpath of the file - """ +def get_photo_webpath(file_path: str): + """ +Returns the webpath of the file + """ file_path = file_path.removeprefix('/') root_path = settings.ROOT_PATH.removesuffix('/') return f"{root_path}/static/photo/lecturer/{file_path}" From 3cbeca38cddf459504f1b7c9e666001bbdf7e8a3 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 4 Feb 2024 16:17:21 +0300 Subject: [PATCH 3/4] Update image.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Задокументировал методы. --- calendar_backend/methods/image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/calendar_backend/methods/image.py b/calendar_backend/methods/image.py index 8b7c56ec..d0e416e7 100644 --- a/calendar_backend/methods/image.py +++ b/calendar_backend/methods/image.py @@ -70,7 +70,7 @@ async def async_image_process(image_bytes: bytes) -> None: def get_photo_webpath(file_path: str): """ -Returns the webpath of the file + Returns the webpath of the file """ file_path = file_path.removeprefix('/') root_path = settings.ROOT_PATH.removesuffix('/') From 9cab01f755f2d62e5f4843a8ae32ced5fb49b688 Mon Sep 17 00:00:00 2001 From: iskomir Date: Sun, 4 Feb 2024 16:19:18 +0300 Subject: [PATCH 4/4] Update image.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Задокументировал методы. --- calendar_backend/models/db.py | 1 + migrations/versions/0929a0a9586e_del_link.py | 1 + migrations/versions/3948c45f9977_building_url.py | 1 + .../versions/55a049fde8f4_many_to_many_events_to_groups.py | 1 + migrations/versions/63263ee9e08e_fix_photo_paths.py | 1 + migrations/versions/6d57978a236e_room_building.py | 1 + migrations/versions/8bae03e22feb_many_to_many.py | 1 + migrations/versions/93612883178c_init.py | 1 + .../versions/c66359fe2d1e_photo_comment_is_deleted_flag.py | 1 + migrations/versions/d6f98271bc6b_no_datatype_directions.py | 1 + migrations/versions/e111af54f4bb_refactoring.py | 1 + migrations/versions/fe04c8baa5ab_fix_sa20.py | 1 + 12 files changed, 12 insertions(+) diff --git a/calendar_backend/models/db.py b/calendar_backend/models/db.py index 105a52db..e9ec42c7 100644 --- a/calendar_backend/models/db.py +++ b/calendar_backend/models/db.py @@ -1,5 +1,6 @@ """Database common classes and methods """ + from __future__ import annotations from datetime import datetime diff --git a/migrations/versions/0929a0a9586e_del_link.py b/migrations/versions/0929a0a9586e_del_link.py index d975a53d..cd5eec83 100644 --- a/migrations/versions/0929a0a9586e_del_link.py +++ b/migrations/versions/0929a0a9586e_del_link.py @@ -5,6 +5,7 @@ Create Date: 2022-08-26 22:06:12.799690 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/3948c45f9977_building_url.py b/migrations/versions/3948c45f9977_building_url.py index 95b4e68b..4ae8a80b 100644 --- a/migrations/versions/3948c45f9977_building_url.py +++ b/migrations/versions/3948c45f9977_building_url.py @@ -5,6 +5,7 @@ Create Date: 2023-03-20 16:42:54.345727 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/55a049fde8f4_many_to_many_events_to_groups.py b/migrations/versions/55a049fde8f4_many_to_many_events_to_groups.py index 11877d1d..9a9912ed 100644 --- a/migrations/versions/55a049fde8f4_many_to_many_events_to_groups.py +++ b/migrations/versions/55a049fde8f4_many_to_many_events_to_groups.py @@ -5,6 +5,7 @@ Create Date: 2023-07-02 22:58:17.045433 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/63263ee9e08e_fix_photo_paths.py b/migrations/versions/63263ee9e08e_fix_photo_paths.py index 0e9558e4..4841162d 100644 --- a/migrations/versions/63263ee9e08e_fix_photo_paths.py +++ b/migrations/versions/63263ee9e08e_fix_photo_paths.py @@ -5,6 +5,7 @@ Create Date: 2023-03-20 15:15:20.345969 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/6d57978a236e_room_building.py b/migrations/versions/6d57978a236e_room_building.py index 72363b0e..05076119 100644 --- a/migrations/versions/6d57978a236e_room_building.py +++ b/migrations/versions/6d57978a236e_room_building.py @@ -5,6 +5,7 @@ Create Date: 2022-11-15 14:28:24.824017 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/8bae03e22feb_many_to_many.py b/migrations/versions/8bae03e22feb_many_to_many.py index 2c78e367..f80130d3 100644 --- a/migrations/versions/8bae03e22feb_many_to_many.py +++ b/migrations/versions/8bae03e22feb_many_to_many.py @@ -5,6 +5,7 @@ Create Date: 2022-08-19 03:29:18.184129 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/93612883178c_init.py b/migrations/versions/93612883178c_init.py index eacb08b3..060ffe30 100644 --- a/migrations/versions/93612883178c_init.py +++ b/migrations/versions/93612883178c_init.py @@ -5,6 +5,7 @@ Create Date: 2022-08-17 15:40:32.047879 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/c66359fe2d1e_photo_comment_is_deleted_flag.py b/migrations/versions/c66359fe2d1e_photo_comment_is_deleted_flag.py index b2c95821..a86dce63 100644 --- a/migrations/versions/c66359fe2d1e_photo_comment_is_deleted_flag.py +++ b/migrations/versions/c66359fe2d1e_photo_comment_is_deleted_flag.py @@ -5,6 +5,7 @@ Create Date: 2022-08-25 21:14:35.470992 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/d6f98271bc6b_no_datatype_directions.py b/migrations/versions/d6f98271bc6b_no_datatype_directions.py index c41c2b4c..cd26f282 100644 --- a/migrations/versions/d6f98271bc6b_no_datatype_directions.py +++ b/migrations/versions/d6f98271bc6b_no_datatype_directions.py @@ -5,6 +5,7 @@ Create Date: 2022-08-20 02:44:28.203133 """ + import sqlalchemy as sa from alembic import op diff --git a/migrations/versions/e111af54f4bb_refactoring.py b/migrations/versions/e111af54f4bb_refactoring.py index fb15ef99..c599837a 100644 --- a/migrations/versions/e111af54f4bb_refactoring.py +++ b/migrations/versions/e111af54f4bb_refactoring.py @@ -5,6 +5,7 @@ Create Date: 2022-08-27 06:15:13.630661 """ + from alembic import op diff --git a/migrations/versions/fe04c8baa5ab_fix_sa20.py b/migrations/versions/fe04c8baa5ab_fix_sa20.py index b00b3fcd..225879f7 100644 --- a/migrations/versions/fe04c8baa5ab_fix_sa20.py +++ b/migrations/versions/fe04c8baa5ab_fix_sa20.py @@ -5,6 +5,7 @@ Create Date: 2023-03-20 18:10:29.098467 """ + import sqlalchemy as sa from alembic import op from sqlalchemy.dialects import postgresql