Create dedicated image upload model

This commit is contained in:
2025-02-28 15:06:47 +01:00
parent 7b23196071
commit c236092c4f
9 changed files with 149 additions and 59 deletions

View File

@ -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