diff --git a/calendar_backend/methods/image.py b/calendar_backend/methods/image.py index a0504bff..d0e416e7 100644 --- a/calendar_backend/methods/image.py +++ b/calendar_backend/methods/image.py @@ -19,6 +19,9 @@ 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] @@ -44,6 +47,9 @@ async def upload_lecturer_photo(lecturer_id: int, session: Session, file: Upload def process_image(image_bytes: bytes) -> None: + """ + Checks the integrity of the image + """ with Image.open(BytesIO(image_bytes)) as image: try: image.verify() @@ -55,11 +61,17 @@ def process_image(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): + """ + 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}" 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