Skip to content

Commit

Permalink
Update image.py (#106)
Browse files Browse the repository at this point in the history
* Update image.py

* Update image.py

* Update image.py

Задокументировал методы.

* Update image.py

Задокументировал методы.
  • Loading branch information
iskomir authored Mar 25, 2024
1 parent b8d23ff commit c49c3a8
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions calendar_backend/methods/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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()
Expand All @@ -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}"
1 change: 1 addition & 0 deletions calendar_backend/models/db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Database common classes and methods
"""

from __future__ import annotations

from datetime import datetime
Expand Down
1 change: 1 addition & 0 deletions migrations/versions/0929a0a9586e_del_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-08-26 22:06:12.799690
"""

import sqlalchemy as sa
from alembic import op

Expand Down
1 change: 1 addition & 0 deletions migrations/versions/3948c45f9977_building_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-03-20 16:42:54.345727
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-07-02 22:58:17.045433
"""

import sqlalchemy as sa
from alembic import op

Expand Down
1 change: 1 addition & 0 deletions migrations/versions/63263ee9e08e_fix_photo_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2023-03-20 15:15:20.345969
"""

import sqlalchemy as sa
from alembic import op

Expand Down
1 change: 1 addition & 0 deletions migrations/versions/6d57978a236e_room_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-11-15 14:28:24.824017
"""

import sqlalchemy as sa
from alembic import op

Expand Down
1 change: 1 addition & 0 deletions migrations/versions/8bae03e22feb_many_to_many.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-08-19 03:29:18.184129
"""

import sqlalchemy as sa
from alembic import op

Expand Down
1 change: 1 addition & 0 deletions migrations/versions/93612883178c_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-08-17 15:40:32.047879
"""

import sqlalchemy as sa
from alembic import op

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-08-25 21:14:35.470992
"""

import sqlalchemy as sa
from alembic import op

Expand Down
1 change: 1 addition & 0 deletions migrations/versions/d6f98271bc6b_no_datatype_directions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-08-20 02:44:28.203133
"""

import sqlalchemy as sa
from alembic import op

Expand Down
1 change: 1 addition & 0 deletions migrations/versions/e111af54f4bb_refactoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Create Date: 2022-08-27 06:15:13.630661
"""

from alembic import op


Expand Down
1 change: 1 addition & 0 deletions migrations/versions/fe04c8baa5ab_fix_sa20.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c49c3a8

Please sign in to comment.