-
Notifications
You must be signed in to change notification settings - Fork 4
Print-pages limit. #50
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
82cae76
Print-pages limit.
Temmmmmo a890013
Print-pages limit.
Temmmmmo b0532b8
Print-pages limit. Exc handlers was added.
Temmmmmo 766fceb
Print-pages limit. Exc handlers was added.
Temmmmmo 51346a1
Print-pages limit. Exc handlers was added.
Temmmmmo 8ccb6aa
Print-pages limit. Exc handlers was added.
Temmmmmo 1361b3a
Print-pages limit. Workflow update.
Temmmmmo d37c248
Print-pages limit. Workflow update.
Temmmmmo 1c64e00
Print-pages limit. Workflow update.
Temmmmmo 74f2ff4
Print-pages limit. Fixes.
Temmmmmo 5a987ee
Print-pages limit. Fixes.
Temmmmmo 30287c5
Print-pages limit. Fixes.
Temmmmmo 950e9ef
Print-pages limit. Fixes.
Temmmmmo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| """page_count | ||
|
|
||
| Revision ID: d63e9f7661dd | ||
| Revises: f6fb6304fb74 | ||
| Create Date: 2023-05-15 18:38:40.964981 | ||
|
|
||
| """ | ||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = 'd63e9f7661dd' | ||
| down_revision = 'f6fb6304fb74' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.add_column('print_fact', sa.Column('sheets_used', sa.Integer(), nullable=True)) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.drop_column('print_fact', 'sheets_used') |
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| from pydantic import BaseModel | ||
|
|
||
|
|
||
| class Base(BaseModel): | ||
| def __repr__(self) -> str: | ||
| attrs = [] | ||
| for k, v in self.__class__.schema().items(): | ||
| attrs.append(f"{k}={v}") | ||
| return "{}({})".format(self.__class__.__name__, ', '.join(attrs)) | ||
|
|
||
| class Config: | ||
| orm_mode = True | ||
|
|
||
|
|
||
| class StatusResponseModel(Base): | ||
| status: str | ||
| message: str |
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 |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| from print_service.settings import get_settings | ||
|
|
||
|
|
||
| settings = get_settings() | ||
|
|
||
|
|
||
| class ObjectNotFound(Exception): | ||
| pass | ||
|
|
||
|
|
||
| class TerminalTokenNotFound(ObjectNotFound): | ||
| pass | ||
|
|
||
|
|
||
| class TerminalQRNotFound(ObjectNotFound): | ||
| pass | ||
|
|
||
|
|
||
| class PINNotFound(ObjectNotFound): | ||
| def __init__(self, pin: str): | ||
| self.pin = pin | ||
|
|
||
|
|
||
| class UserNotFound(ObjectNotFound): | ||
| pass | ||
|
|
||
|
|
||
| class FileNotFound(ObjectNotFound): | ||
| def __init__(self, count: int): | ||
| self.count = count | ||
|
|
||
|
|
||
| class TooManyPages(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'Content too large, count of page: {settings.MAX_PAGE_COUNT} is allowed') | ||
|
|
||
|
|
||
| class TooLargeSize(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'Content too large, {settings.MAX_SIZE} bytes allowed') | ||
|
|
||
|
|
||
| class InvalidPageRequest(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'Invalid format') | ||
|
|
||
|
|
||
| class UnionStudentDuplicate(Exception): | ||
| def __init__(self): | ||
| super().__init__('Duplicates by union_numbers or student_numbers') | ||
|
|
||
|
|
||
| class NotInUnion(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'User is not found in trade union list') | ||
|
|
||
|
|
||
| class PINGenerateError(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'Can not generate PIN. Too many users?') | ||
|
|
||
|
|
||
| class FileIsNotReceived(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'No file was recieved') | ||
|
|
||
|
|
||
| class InvalidType(Exception): | ||
| def __init__(self, content_type: str): | ||
| super().__init__( | ||
| f'Only {", ".join(settings.CONTENT_TYPES)} files allowed, but {content_type} was recieved' | ||
| ) | ||
|
|
||
|
|
||
| class AlreadyUploaded(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'File has been already uploaded') | ||
|
|
||
|
|
||
| class IsCorrupted(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'File is corrupted') | ||
|
|
||
|
|
||
| class IsNotUploaded(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'File has not been uploaded yet') | ||
|
|
||
|
|
||
| class UnprocessableFileInstance(Exception): | ||
| def __init__(self): | ||
| super().__init__(f'Unprocessable file instance') |
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 |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| from . import exc_handlers | ||
| from .base import app | ||
|
|
||
|
|
||
| __all__ = ["app", "exc_handlers"] |
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 |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| import starlette.requests | ||
| from starlette.responses import JSONResponse | ||
|
|
||
| from print_service.base import StatusResponseModel | ||
| from print_service.exceptions import ( | ||
| AlreadyUploaded, | ||
| FileIsNotReceived, | ||
| FileNotFound, | ||
| InvalidPageRequest, | ||
| InvalidType, | ||
| IsCorrupted, | ||
| IsNotUploaded, | ||
| NotInUnion, | ||
| PINGenerateError, | ||
| PINNotFound, | ||
| TerminalQRNotFound, | ||
| TerminalTokenNotFound, | ||
| TooLargeSize, | ||
| TooManyPages, | ||
| UnionStudentDuplicate, | ||
| UnprocessableFileInstance, | ||
| UserNotFound, | ||
| ) | ||
| from print_service.routes.base import app | ||
|
|
||
|
|
||
| @app.exception_handler(TooLargeSize) | ||
| async def too_large_size(req: starlette.requests.Request, exc: TooLargeSize): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=413 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(TooManyPages) | ||
| async def too_many_pages(req: starlette.requests.Request, exc: TooManyPages): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=413 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(InvalidPageRequest) | ||
| async def invalid_format(req: starlette.requests.Request, exc: TooManyPages): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=416 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(TerminalQRNotFound) | ||
| async def terminal_not_found_by_qr(req: starlette.requests.Request, exc: TerminalQRNotFound): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"Terminal not found by QR").dict(), | ||
| status_code=400, | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(TerminalTokenNotFound) | ||
| async def terminal_not_found_by_token(req: starlette.requests.Request, exc: TerminalTokenNotFound): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"Terminal not found by token").dict(), | ||
| status_code=400, | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(UserNotFound) | ||
| async def user_not_found(req: starlette.requests.Request, exc: UserNotFound): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"User not found").dict(), status_code=404 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(UnionStudentDuplicate) | ||
| async def student_duplicate(req: starlette.requests.Request, exc: UnionStudentDuplicate): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=400 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(NotInUnion) | ||
| async def not_in_union(req: starlette.requests.Request, exc: NotInUnion): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=403 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(PINGenerateError) | ||
| async def generate_error(req: starlette.requests.Request, exc: PINGenerateError): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=500 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(FileIsNotReceived) | ||
| async def file_not_received(req: starlette.requests.Request, exc: FileIsNotReceived): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=400 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(PINNotFound) | ||
| async def pin_not_found(req: starlette.requests.Request, exc: PINNotFound): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"Pin {exc.pin} not found").dict(), | ||
| status_code=404, | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(InvalidType) | ||
| async def invalid_type(req: starlette.requests.Request, exc: InvalidType): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=415 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(AlreadyUploaded) | ||
| async def already_upload(req: starlette.requests.Request, exc: AlreadyUploaded): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=415 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(IsCorrupted) | ||
| async def is_corrupted(req: starlette.requests.Request, exc: IsCorrupted): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=415 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(UnprocessableFileInstance) | ||
| async def unprocessable_file_instance(req: starlette.requests.Request, exc: UnprocessableFileInstance): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=422 | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(FileNotFound) | ||
| async def file_not_found(req: starlette.requests.Request, exc: FileNotFound): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc.count} file(s) not found").dict(), | ||
| status_code=404, | ||
| ) | ||
|
|
||
|
|
||
| @app.exception_handler(IsNotUploaded) | ||
| async def not_uploaded(req: starlette.requests.Request, exc: IsNotUploaded): | ||
| return JSONResponse( | ||
| content=StatusResponseModel(status="Error", message=f"{exc}").dict(), status_code=415 | ||
| ) |
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.
Uh oh!
There was an error while loading. Please reload this page.