-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Abstract File class to make associable not break
- Loading branch information
1 parent
b13f041
commit 14993d5
Showing
10 changed files
with
304 additions
and
149 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,40 @@ | ||
import uuid | ||
from pyramid.authorization import Allow | ||
from pyramid.authorization import Authenticated | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
from sqlalchemy_file import File | ||
|
||
from privatim.orm.associable import Associable | ||
from privatim.orm.meta import UUIDStrPK, AttachedFile | ||
from privatim.orm import Base | ||
|
||
|
||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from privatim.types import ACL | ||
|
||
|
||
class AbstractFile(Base, Associable): | ||
__abstract__ = True | ||
|
||
id: Mapped[UUIDStrPK] = mapped_column(primary_key=True) | ||
file: Mapped[AttachedFile] = mapped_column(nullable=False) | ||
filename: Mapped[str] = mapped_column(nullable=False) | ||
|
||
def __init__(self, filename: str, content: bytes) -> None: | ||
self.id = str(uuid.uuid4()) | ||
self.filename = filename | ||
self.file = File(content=content, filename=filename) | ||
|
||
@property | ||
def content(self) -> bytes: | ||
return self.file.file.read() | ||
|
||
@property | ||
def content_type(self) -> str: | ||
return self.file.content_type | ||
|
||
def __acl__(self) -> list['ACL']: | ||
return [ | ||
(Allow, Authenticated, ['view']), | ||
] |
Oops, something went wrong.