Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend Extras #305

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions api/views/restrictie.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,38 @@ def restrictie_list(request, format=None):
Returns:
Response: Een http-respons met de opgevraagde of gemaakte restricties.
"""

if request.method == "GET":
restricties = Restrictie.objects.all()

if "project" in request.GET:
try:
project = eval(request.GET.get("project"))
restricties = restricties.filter(project=project)
except NameError:
return Response(status=status.HTTP_400_BAD_REQUEST)

if "moet_slagen" in request.GET and request.GET.get(
"moet_slagen"
).lower() in [
"true",
"false",
]:
restricties = restricties.filter(
moet_slagen=(request.GET.get("moet_slagen").lower() == "true")
)

serializer = RestrictieSerializer(restricties, many=True)
return Response(serializer.data)

if has_permissions(request.user):
if request.method == "GET":
restricties = Restrictie.objects.all()

if "project" in request.GET:
try:
project = eval(request.GET.get("project"))
restricties = restricties.filter(project=project)
except NameError:
return Response(status=status.HTTP_400_BAD_REQUEST)

if "moet_slagen" in request.GET and request.GET.get(
"moet_slagen"
).lower() in [
"true",
"false",
]:
restricties = restricties.filter(
moet_slagen=(request.GET.get("moet_slagen").lower() == "true")
)

serializer = RestrictieSerializer(restricties, many=True)
return Response(serializer.data)

elif request.method == "POST":
if request.method == "POST":
serializer = RestrictieSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

return Response(status=status.HTTP_403_FORBIDDEN)


Expand Down
Loading