mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Create dedicated image upload model
This commit is contained in:
@ -39,7 +39,7 @@ from core.auth.mixins import (
|
||||
CanViewMixin,
|
||||
can_view,
|
||||
)
|
||||
from core.models import Notification, SithFile, User
|
||||
from core.models import Notification, QuickUploadImage, SithFile, User
|
||||
from core.views.mixins import AllowFragment
|
||||
from core.views.widgets.ajax_select import (
|
||||
AutoCompleteSelectMultipleGroup,
|
||||
@ -86,8 +86,8 @@ def send_raw_file(path: Path) -> HttpResponse:
|
||||
|
||||
def send_file(
|
||||
request: HttpRequest,
|
||||
file_id: int,
|
||||
file_class: type[SithFile] = SithFile,
|
||||
file_id: int | str,
|
||||
file_class: type[SithFile | QuickUploadImage] = SithFile,
|
||||
file_attr: str = "file",
|
||||
) -> HttpResponse:
|
||||
"""Send a protected file, if the user can see it.
|
||||
@ -97,7 +97,7 @@ def send_file(
|
||||
deal with it.
|
||||
In debug mode, the server will directly send the file.
|
||||
"""
|
||||
f = get_object_or_404(file_class, id=file_id)
|
||||
f = get_object_or_404(file_class, pk=file_id)
|
||||
if not can_view(f, request.user) and not is_logged_in_counter(request):
|
||||
raise PermissionDenied
|
||||
name = getattr(f, file_attr).name
|
||||
|
Reference in New Issue
Block a user