Skip to content

Commit

Permalink
fix: right url to download
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed May 13, 2024
1 parent b9471cd commit 64aecd8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
27 changes: 27 additions & 0 deletions backend/api/serializers/submission_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
StructureCheckResult, Submission)
from django.core.files import File
from django.db.models import Max
from django.http import HttpRequest
from django.urls import reverse
from django.utils.translation import gettext as _
from rest_framework import serializers
from rest_framework.exceptions import ValidationError
Expand All @@ -30,6 +32,17 @@ class Meta:
model = ExtraCheckResult
exclude = ["polymorphic_ctype"]

def to_representation(self, instance: ExtraCheckResult) -> dict | None:
request: HttpRequest | None = self.context.get('request')
if request is not None:
representation: dict = super().to_representation(instance)
representation["log_file"] = request.build_absolute_uri(
reverse("extra-check-result-detail", args=[str(instance.id)]) + "log/"
)
return representation

return None


class CheckResultPolymorphicSerializer(PolymorphicSerializer):
model_serializer_mapping = {
Expand Down Expand Up @@ -57,6 +70,20 @@ class Meta:
}
}

def to_representation(self, instance: Submission) -> dict | None:
request: HttpRequest | None = self.context.get('request')
if request is not None:
representation: dict = super().to_representation(instance)
representation['zip'] = request.build_absolute_uri(reverse("submission-detail", args=[str(instance.id)]) + "zip/")
return representation

return None

def get_zip(self, obj):
return self.context["request"].build_absolute_uri(
reverse("submission-detail", args=[str(obj.id)]) + "zip/"
)

def validate(self, attrs):

group: Group = self.context["group"]
Expand Down
4 changes: 2 additions & 2 deletions backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
router.register(r"file-extensions", FileExtensionViewSet, basename="file-extension")
router.register(r"faculties", FacultyViewSet, basename="faculty")
router.register(r"docker-images", DockerImageViewSet, basename="docker-image")
router.register(r"structure-check-results", StructureCheckResultViewSet, basename="structure-check-results")
router.register(r"extra-check-results", ExtraCheckResultViewSet, basename="extra-check-results")
router.register(r"structure-check-results", StructureCheckResultViewSet, basename="structure-check-result")
router.register(r"extra-check-results", ExtraCheckResultViewSet, basename="extra-check-result")

urlpatterns = [
path("", include(router.urls)),
Expand Down
3 changes: 2 additions & 1 deletion backend/api/views/submission_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.utils.translation import gettext as _
from rest_framework.decorators import action
from rest_framework.mixins import RetrieveModelMixin
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet

Expand Down Expand Up @@ -41,7 +42,7 @@ class ExtraCheckResultViewSet(RetrieveModelMixin, GenericViewSet):
serializer_class = ExtraCheckResultSerializer
permission_classes = [ExtraCheckResultPermission]

@action(detail=True, permission_classes=[ExtraCheckResultLogPermission])
@action(detail=True, permission_classes=[IsAdminUser | ExtraCheckResultLogPermission])
def log(self, request, **__):
extra_check_result: ExtraCheckResult = self.get_object()

Expand Down

0 comments on commit 64aecd8

Please sign in to comment.