diff --git a/api/__pycache__/__init__.cpython-311.pyc b/api/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 00000000..7f1d8409 Binary files /dev/null and b/api/__pycache__/__init__.cpython-311.pyc differ diff --git a/api/__pycache__/admin.cpython-311.pyc b/api/__pycache__/admin.cpython-311.pyc index 09a05a6c..b4323d43 100644 Binary files a/api/__pycache__/admin.cpython-311.pyc and b/api/__pycache__/admin.cpython-311.pyc differ diff --git a/api/__pycache__/middleware.cpython-311.pyc b/api/__pycache__/middleware.cpython-311.pyc index 56f3857c..53923d49 100644 Binary files a/api/__pycache__/middleware.cpython-311.pyc and b/api/__pycache__/middleware.cpython-311.pyc differ diff --git a/api/__pycache__/models.cpython-311.pyc b/api/__pycache__/models.cpython-311.pyc new file mode 100644 index 00000000..663de4ff Binary files /dev/null and b/api/__pycache__/models.cpython-311.pyc differ diff --git a/api/__pycache__/serializers.cpython-311.pyc b/api/__pycache__/serializers.cpython-311.pyc index 474a1a00..e192a5eb 100644 Binary files a/api/__pycache__/serializers.cpython-311.pyc and b/api/__pycache__/serializers.cpython-311.pyc differ diff --git a/api/__pycache__/settings.cpython-311.pyc b/api/__pycache__/settings.cpython-311.pyc new file mode 100644 index 00000000..4c1538f6 Binary files /dev/null and b/api/__pycache__/settings.cpython-311.pyc differ diff --git a/api/__pycache__/urls.cpython-311.pyc b/api/__pycache__/urls.cpython-311.pyc new file mode 100644 index 00000000..063efeba Binary files /dev/null and b/api/__pycache__/urls.cpython-311.pyc differ diff --git a/api/__pycache__/utils.cpython-311.pyc b/api/__pycache__/utils.cpython-311.pyc new file mode 100644 index 00000000..fc862db6 Binary files /dev/null and b/api/__pycache__/utils.cpython-311.pyc differ diff --git a/api/__pycache__/wsgi.cpython-311.pyc b/api/__pycache__/wsgi.cpython-311.pyc new file mode 100644 index 00000000..6a0459c7 Binary files /dev/null and b/api/__pycache__/wsgi.cpython-311.pyc differ diff --git a/api/migrations/__pycache__/0001_initial.cpython-311.pyc b/api/migrations/__pycache__/0001_initial.cpython-311.pyc index 54bc248d..ed1272db 100644 Binary files a/api/migrations/__pycache__/0001_initial.cpython-311.pyc and b/api/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/api/migrations/__pycache__/0002_remove_student_id_remove_student_name_and_more.cpython-311.pyc b/api/migrations/__pycache__/0002_remove_student_id_remove_student_name_and_more.cpython-311.pyc index 63bf54d7..52dfba93 100644 Binary files a/api/migrations/__pycache__/0002_remove_student_id_remove_student_name_and_more.cpython-311.pyc and b/api/migrations/__pycache__/0002_remove_student_id_remove_student_name_and_more.cpython-311.pyc differ diff --git a/api/migrations/__pycache__/0003_alter_student_subjects.cpython-311.pyc b/api/migrations/__pycache__/0003_alter_student_subjects.cpython-311.pyc index b1655e08..ead4b8af 100644 Binary files a/api/migrations/__pycache__/0003_alter_student_subjects.cpython-311.pyc and b/api/migrations/__pycache__/0003_alter_student_subjects.cpython-311.pyc differ diff --git a/api/migrations/__pycache__/0004_alter_student_subjects.cpython-311.pyc b/api/migrations/__pycache__/0004_alter_student_subjects.cpython-311.pyc index 808e7a49..0522acb5 100644 Binary files a/api/migrations/__pycache__/0004_alter_student_subjects.cpython-311.pyc and b/api/migrations/__pycache__/0004_alter_student_subjects.cpython-311.pyc differ diff --git a/api/migrations/__pycache__/0005_alter_vak_teachers.cpython-311.pyc b/api/migrations/__pycache__/0005_alter_vak_teachers.cpython-311.pyc index c9e72964..44e54ac0 100644 Binary files a/api/migrations/__pycache__/0005_alter_vak_teachers.cpython-311.pyc and b/api/migrations/__pycache__/0005_alter_vak_teachers.cpython-311.pyc differ diff --git a/api/migrations/__pycache__/0006_remove_lesgever_id_alter_lesgever_lesgever_id.cpython-311.pyc b/api/migrations/__pycache__/0006_remove_lesgever_id_alter_lesgever_lesgever_id.cpython-311.pyc index 83b31ae0..24246888 100644 Binary files a/api/migrations/__pycache__/0006_remove_lesgever_id_alter_lesgever_lesgever_id.cpython-311.pyc and b/api/migrations/__pycache__/0006_remove_lesgever_id_alter_lesgever_lesgever_id.cpython-311.pyc differ diff --git a/api/migrations/__pycache__/0007_alter_lesgever_subjects_alter_vak_teachers.cpython-311.pyc b/api/migrations/__pycache__/0007_alter_lesgever_subjects_alter_vak_teachers.cpython-311.pyc index 656b5d5d..2f9ae735 100644 Binary files a/api/migrations/__pycache__/0007_alter_lesgever_subjects_alter_vak_teachers.cpython-311.pyc and b/api/migrations/__pycache__/0007_alter_lesgever_subjects_alter_vak_teachers.cpython-311.pyc differ diff --git a/api/migrations/__pycache__/__init__.cpython-311.pyc b/api/migrations/__pycache__/__init__.cpython-311.pyc index 4b354942..c48f5d71 100644 Binary files a/api/migrations/__pycache__/__init__.cpython-311.pyc and b/api/migrations/__pycache__/__init__.cpython-311.pyc differ diff --git a/api/models.py b/api/models.py index 8032c84b..94479ebc 100644 --- a/api/models.py +++ b/api/models.py @@ -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) diff --git a/api/serializers.py b/api/serializers.py index 62c2db83..b349b04a 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -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: diff --git a/api/settings.py b/api/settings.py index 5960c2f8..344fee43 100644 --- a/api/settings.py +++ b/api/settings.py @@ -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' diff --git a/api/urls.py b/api/urls.py index 1eea2062..9b939fbe 100644 --- a/api/urls.py +++ b/api/urls.py @@ -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/', student_detail) ] diff --git a/api/utils.py b/api/utils.py index 7504ceac..93852bbb 100644 --- a/api/utils.py +++ b/api/utils.py @@ -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(): """ @@ -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'])}}) \ No newline at end of file + return None \ No newline at end of file diff --git a/api/views/__pycache__/student.cpython-311.pyc b/api/views/__pycache__/student.cpython-311.pyc index 8903957e..cbc59453 100644 Binary files a/api/views/__pycache__/student.cpython-311.pyc and b/api/views/__pycache__/student.cpython-311.pyc differ diff --git a/api/views/__pycache__/views.cpython-311.pyc b/api/views/__pycache__/views.cpython-311.pyc index fc09eed2..bd0b3605 100644 Binary files a/api/views/__pycache__/views.cpython-311.pyc and b/api/views/__pycache__/views.cpython-311.pyc differ diff --git a/api/views/student.py b/api/views/student.py index 7ced2f1d..cf38cb3b 100644 --- a/api/views/student.py +++ b/api/views/student.py @@ -5,8 +5,7 @@ from ..models import Student -from ..serializers import StudentSerializer -from ..utils import json_error +from ..serializers.student import StudentSerializer @api_view(['GET', 'POST']) @@ -14,18 +13,28 @@ 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': 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')""" \ No newline at end of file +@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)