Skip to content

Commit

Permalink
Replace django-sendfile with maintained fork django-sendfile2
Browse files Browse the repository at this point in the history
  • Loading branch information
DeD1rk committed May 14, 2024
1 parent f9f9268 commit 3a9e381
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
25 changes: 10 additions & 15 deletions server/api/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import json
import os
import requests

import requests
from django.conf import settings
from django.db.models import Q
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.urls import reverse
from django_sendfile import sendfile
from rest_framework.decorators import api_view
from rest_framework.response import Response
from sendfile import sendfile
from django.conf import settings

from .models import AnyTimer, AnyTimerProof, AnyTimerRequest, AnytimerStatus

Expand All @@ -24,7 +24,7 @@ def give_any(request, target_id):
headers={"Authorization": request.headers["Authorization"]},
)

#Fetch recipient user
# Fetch recipient user
recipient = requests.get(
f"{settings.THALIA_BASE_URL}/api/v2/members/{request.user_id}",
headers={"Authorization": request.headers["Authorization"]},
Expand Down Expand Up @@ -203,13 +203,9 @@ def revoke_request(request, request_id):
@api_view(["GET"])
def fetch_requests(request, direction):
if direction == "incoming":
anytimerrequests = AnyTimerRequest.objects.filter(
recipient_id=request.user_id
)
anytimerrequests = AnyTimerRequest.objects.filter(recipient_id=request.user_id)
elif direction == "outgoing":
anytimerrequests = AnyTimerRequest.objects.filter(
requester_id=request.user_id
)
anytimerrequests = AnyTimerRequest.objects.filter(requester_id=request.user_id)
else:
return Response(status=400, data={"message": "Invalid direction"})

Expand Down Expand Up @@ -270,8 +266,7 @@ def fetch_proof(request, anytimer_id):
data = {
"anytimer_id": proof.anytimer_id,
"proof_file": request.build_absolute_uri(
settings.BASE_URL +
reverse("proof_sendfile", args=[anytimer_id])
settings.BASE_URL + reverse("proof_sendfile", args=[anytimer_id])
),
"description": proof.description,
"proof_type": proof.proof_type,
Expand All @@ -290,6 +285,6 @@ def proof_sendfile(request, anytimer_id):
),
anytimer=anytimer_id,
)

print(proof.file.path)
return sendfile(request, proof.file.path)
return sendfile(request, proof.file.path)
2 changes: 1 addition & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cryptography==42.0.7
Django==5.0.6
django-cors-headers==4.3.1
django-rest-framework==0.1.0
django-sendfile==0.3.11
django-sendfile2==0.7.1
djangorestframework==3.15.1
gunicorn==22.0.0
idna==3.7
Expand Down

0 comments on commit 3a9e381

Please sign in to comment.