Skip to content

Commit

Permalink
Temp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ticoucke committed Mar 4, 2024
1 parent 4ec903d commit c3bf63d
Show file tree
Hide file tree
Showing 23 changed files with 26 additions and 30 deletions.
Binary file modified api/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file modified api/__pycache__/middleware.cpython-311.pyc
Binary file not shown.
Binary file modified api/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file modified api/__pycache__/serializers.cpython-311.pyc
Binary file not shown.
Binary file modified api/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file modified api/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file modified api/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Binary file modified api/migrations/__pycache__/0001_initial.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified api/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __str__(self):
class Lesgever(models.Model):
lesgever_id = models.AutoField(primary_key=True)
name = models.CharField(max_length=100)
email = models.EmailField()
email = models.EmailField(default=False)
subjects = models.ManyToManyField('Vak', related_name='lesgevers_enrolled', blank=True)
is_admin = models.BooleanField(default=False)

Expand Down
3 changes: 0 additions & 3 deletions api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ def create(self, validated_data):
return Student.objects.create(**validated_data)

def update(self, instance, validated_data):
# Update the regular fields
instance.name = validated_data.get('name', instance.name)
instance.email = validated_data.get('email', instance.email)
# Update the subjects list
subjects_data = validated_data.pop('subjects', None)
if subjects_data is not None:
Expand Down
2 changes: 1 addition & 1 deletion api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'api.middleware.RedirectAnonymousUserMiddleware',
#'api.middleware.RedirectAnonymousUserMiddleware',
]

ROOT_URLCONF = 'api.urls'
Expand Down
5 changes: 3 additions & 2 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
from django.urls import path, include

from .views.views import microsoft_association, login_redirect
from .views.student import student_list
from .views.student import student_list, student_detail

urlpatterns = [
path('.well-known/microsoft-identity-association.json', microsoft_association),
path('admin/', admin.site.urls),
path('oauth2/', include('django_auth_adfs.urls')),
path('login_redirect', login_redirect),
path('api/studenten', student_list)
path('api/studenten', student_list),
path('api/studenten/<int:id>', student_detail)
]
12 changes: 1 addition & 11 deletions api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
from django.http import JsonResponse
import requests

ERRORS = {
'no_perm': 'You do not have permission to view this data',
'generic': 'There was an error'
}


def get_graph_token():
"""
Expand All @@ -27,9 +22,4 @@ def get_graph_token():
response = requests.post(url=url, headers=headers, data=data)
return response.json()
except:
return None



def json_error(error_code):
return JsonResponse({'error': {'message': ERRORS.get(error_code, ERRORS['generic'])}})
return None
Binary file modified api/views/__pycache__/student.cpython-311.pyc
Binary file not shown.
Binary file modified api/views/__pycache__/views.cpython-311.pyc
Binary file not shown.
32 changes: 20 additions & 12 deletions api/views/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,36 @@


from ..models import Student
from ..serializers import StudentSerializer
from ..utils import json_error
from ..serializers.student import StudentSerializer


@api_view(['GET', 'POST'])
def student_list(request):
if request.method == 'GET':
students = Student.objects.all()
serializer = StudentSerializer(students, many=True)
return JsonResponse({'studenten': serializer.data})
return Response(serializer.data)
elif request.method == 'POST':
print(request.data)
serializer = StudentSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)


"""if request.user.is_superuser:
students = Student.objects.all()
serializer = StudentSerializer(students, many=True)
return JsonResponse({'studenten': serializer.data})
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


else:
return json_error('no_perm')"""
@api_view(['GET', 'PUT'])
def student_detail(request, id):
try:
student = Student.objects.get(pk=id)
except Student.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)

if request.method == 'GET':
serializer = StudentSerializer(student)
return Response(serializer.data)
elif request.method == 'PUT':
serializer = StudentSerializer(student, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

0 comments on commit c3bf63d

Please sign in to comment.