diff --git a/.gitignore b/.gitignore index b7697ab0..9b92bf8e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ node_modules projectenv /venv/ -__pycache__ +**/__pycache__/ migrations +.env htmlcov diff --git a/api/.env b/api/.env deleted file mode 100644 index 8b478692..00000000 --- a/api/.env +++ /dev/null @@ -1,5 +0,0 @@ -client_id='239ce609-e362-4cf6-919f-97e6935ef5f5' -client_secret='Eyv8Q~PoW8FW_y3Wdprc~HdCQg6whiIz8wi0ddbm' -tenant_id='d7811cde-ecef-496c-8f91-a1786241b99c' - -ad_url='https://login.microsoftonline.com/d7811cde-ecef-496c-8f91-a1786241b99c/oauth2/v2.0/token?' \ No newline at end of file diff --git a/api/__pycache__/__init__.cpython-310.pyc b/api/__pycache__/__init__.cpython-310.pyc deleted file mode 100644 index 403f35ed..00000000 Binary files a/api/__pycache__/__init__.cpython-310.pyc and /dev/null differ diff --git a/api/__pycache__/__init__.cpython-311.pyc b/api/__pycache__/__init__.cpython-311.pyc deleted file mode 100644 index 7f1d8409..00000000 Binary files a/api/__pycache__/__init__.cpython-311.pyc and /dev/null differ diff --git a/api/__pycache__/admin.cpython-311.pyc b/api/__pycache__/admin.cpython-311.pyc deleted file mode 100644 index b4323d43..00000000 Binary files a/api/__pycache__/admin.cpython-311.pyc and /dev/null differ diff --git a/api/__pycache__/middleware.cpython-311.pyc b/api/__pycache__/middleware.cpython-311.pyc deleted file mode 100644 index 53923d49..00000000 Binary files a/api/__pycache__/middleware.cpython-311.pyc and /dev/null differ diff --git a/api/__pycache__/models.cpython-310.pyc b/api/__pycache__/models.cpython-310.pyc deleted file mode 100644 index 11f683b4..00000000 Binary files a/api/__pycache__/models.cpython-310.pyc and /dev/null differ diff --git a/api/__pycache__/models.cpython-311.pyc b/api/__pycache__/models.cpython-311.pyc deleted file mode 100644 index 663de4ff..00000000 Binary files a/api/__pycache__/models.cpython-311.pyc and /dev/null differ diff --git a/api/__pycache__/serializers.cpython-311.pyc b/api/__pycache__/serializers.cpython-311.pyc deleted file mode 100644 index e192a5eb..00000000 Binary files a/api/__pycache__/serializers.cpython-311.pyc and /dev/null differ diff --git a/api/__pycache__/settings.cpython-310.pyc b/api/__pycache__/settings.cpython-310.pyc deleted file mode 100644 index 955f4a9b..00000000 Binary files a/api/__pycache__/settings.cpython-310.pyc and /dev/null differ diff --git a/api/__pycache__/settings.cpython-311.pyc b/api/__pycache__/settings.cpython-311.pyc deleted file mode 100644 index 4c1538f6..00000000 Binary files a/api/__pycache__/settings.cpython-311.pyc and /dev/null differ diff --git a/api/__pycache__/urls.cpython-310.pyc b/api/__pycache__/urls.cpython-310.pyc deleted file mode 100644 index 97f53a2c..00000000 Binary files a/api/__pycache__/urls.cpython-310.pyc and /dev/null differ diff --git a/api/__pycache__/urls.cpython-311.pyc b/api/__pycache__/urls.cpython-311.pyc deleted file mode 100644 index 063efeba..00000000 Binary files a/api/__pycache__/urls.cpython-311.pyc and /dev/null differ diff --git a/api/__pycache__/utils.cpython-310.pyc b/api/__pycache__/utils.cpython-310.pyc deleted file mode 100644 index b137304c..00000000 Binary files a/api/__pycache__/utils.cpython-310.pyc and /dev/null differ diff --git a/api/__pycache__/utils.cpython-311.pyc b/api/__pycache__/utils.cpython-311.pyc deleted file mode 100644 index fc862db6..00000000 Binary files a/api/__pycache__/utils.cpython-311.pyc and /dev/null differ diff --git a/api/__pycache__/views.cpython-310.pyc b/api/__pycache__/views.cpython-310.pyc deleted file mode 100644 index 01685371..00000000 Binary files a/api/__pycache__/views.cpython-310.pyc and /dev/null differ diff --git a/api/__pycache__/wsgi.cpython-310.pyc b/api/__pycache__/wsgi.cpython-310.pyc deleted file mode 100644 index 1c5a27e0..00000000 Binary files a/api/__pycache__/wsgi.cpython-310.pyc and /dev/null differ diff --git a/api/__pycache__/wsgi.cpython-311.pyc b/api/__pycache__/wsgi.cpython-311.pyc deleted file mode 100644 index 6a0459c7..00000000 Binary files a/api/__pycache__/wsgi.cpython-311.pyc and /dev/null differ diff --git a/api/admin.py b/api/admin.py index db5e1238..5e85ceb9 100644 --- a/api/admin.py +++ b/api/admin.py @@ -1,6 +1,11 @@ from django.contrib import admin -from .models import * - +from .models.student import * +from .models.lesgever import * +from .models.vak import * +from .models.groep import * +from .models.project import * +from .models.indiening import * +from .models.score import * admin.site.register(Student) admin.site.register(Lesgever) @@ -8,4 +13,4 @@ admin.site.register(Groep) admin.site.register(Project) admin.site.register(Indiening) -admin.site.register(Score) \ No newline at end of file +admin.site.register(Score) diff --git a/api/models/groep.py b/api/models/groep.py new file mode 100644 index 00000000..f8105613 --- /dev/null +++ b/api/models/groep.py @@ -0,0 +1,10 @@ +from django.db import models + + +class Groep(models.Model): + group_id = models.AutoField(primary_key=True) + students = models.ManyToManyField('Student', related_name='groups_students', blank=True) + project = models.ForeignKey('Project', on_delete=models.CASCADE) + + def __str__(self): + return f"Group {self.group_id}" diff --git a/api/models/indiening.py b/api/models/indiening.py new file mode 100644 index 00000000..da4a7228 --- /dev/null +++ b/api/models/indiening.py @@ -0,0 +1,12 @@ +from django.db import models + + +class Indiening(models.Model): + indiening_id = models.AutoField(primary_key=True) + indiener = models.ForeignKey('Groep', on_delete=models.CASCADE) + indieningsbestanden = models.FileField(upload_to='uploads/') + tijdstip = models.DateTimeField(null=False) + + def __str__(self): + return self.tijdstip + \ No newline at end of file diff --git a/api/models/lesgever.py b/api/models/lesgever.py new file mode 100644 index 00000000..85c70ac4 --- /dev/null +++ b/api/models/lesgever.py @@ -0,0 +1,12 @@ +from django.db import models + + +class Lesgever(models.Model): + lesgever_id = models.AutoField(primary_key=True) + name = models.CharField(max_length=100) + email = models.EmailField(default='email@email.com') + subjects = models.ManyToManyField('Vak', related_name='lesgevers_enrolled', blank=True) + is_admin = models.BooleanField(default=False) + + def __str__(self): + return self.name \ No newline at end of file diff --git a/api/models/project.py b/api/models/project.py new file mode 100644 index 00000000..010e92e6 --- /dev/null +++ b/api/models/project.py @@ -0,0 +1,15 @@ +from django.db import models +from .vak import Vak + + +class Project(models.Model): + project_id = models.AutoField(primary_key=True) + titel = models.CharField(max_length=100) + description = models.TextField() + opgavebestanden = models.FileField(upload_to='opgave/') + vak = models.ForeignKey(Vak, on_delete=models.CASCADE) + deadline = models.DateTimeField(null=True) + # indiening restricties + + def __str__(self): + return self.titel diff --git a/api/models/score.py b/api/models/score.py new file mode 100644 index 00000000..0b6cc20d --- /dev/null +++ b/api/models/score.py @@ -0,0 +1,10 @@ +from django.db import models + + +class Score(models.Model): + score = models.SmallIntegerField() + indiening = models.ForeignKey('Indiening', on_delete=models.CASCADE) + groep = models.ForeignKey('Groep', on_delete=models.CASCADE) + + def __str__(self): + return self.score diff --git a/api/models/student.py b/api/models/student.py new file mode 100644 index 00000000..2771560e --- /dev/null +++ b/api/models/student.py @@ -0,0 +1,10 @@ +from django.db import models +from django.contrib.auth.models import User + + +class Student(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE,primary_key=True,default=None) + subjects = models.ManyToManyField('Vak', related_name='students_enrolled') + + def __str__(self): + return self.user.first_name diff --git a/api/models/vak.py b/api/models/vak.py new file mode 100644 index 00000000..e4a55ade --- /dev/null +++ b/api/models/vak.py @@ -0,0 +1,12 @@ +from django.db import models + + +class Vak(models.Model): + vak_id = models.AutoField(primary_key=True) + name = models.CharField(max_length=100) + students = models.ManyToManyField('Student', related_name='subjects_enrolled', blank=True) + teachers = models.ManyToManyField('Lesgever', related_name='subjects_teachers') + projects = models.ManyToManyField('Project', related_name='subjects_projects', blank=True) + + def __str__(self): + return self.name diff --git a/api/serializers/groep.py b/api/serializers/groep.py new file mode 100644 index 00000000..fa686aa7 --- /dev/null +++ b/api/serializers/groep.py @@ -0,0 +1,15 @@ +from rest_framework import serializers +from api.models.groep import Groep + + +class GroepSerializer(serializers.ModelSerializer): + class Meta: + model = Groep + fields = '__all__' + + def create(self, validated_data): + return Groep.objects.create(**validated_data) + + def update(self, instance, validated_data): + # Implement update method for Groep model + pass diff --git a/api/serializers/indiening.py b/api/serializers/indiening.py new file mode 100644 index 00000000..e33f3f8d --- /dev/null +++ b/api/serializers/indiening.py @@ -0,0 +1,15 @@ +from rest_framework import serializers +from api.models.indiening import Indiening + + +class IndieningSerializer(serializers.ModelSerializer): + class Meta: + model = Indiening + fields = '__all__' + + def create(self, validated_data): + return Indiening.objects.create(**validated_data) + + def update(self, instance, validated_data): + # Implement update method for Indiening model + pass diff --git a/api/serializers/lesgever.py b/api/serializers/lesgever.py new file mode 100644 index 00000000..5b9c3062 --- /dev/null +++ b/api/serializers/lesgever.py @@ -0,0 +1,17 @@ +from rest_framework import serializers +from api.models.lesgever import Lesgever + + +class LesgeverSerializer(serializers.ModelSerializer): + class Meta: + model = Lesgever + fields = '__all__' + + def create(self, validated_data): + return Lesgever.objects.create(**validated_data) + + def update(self, instance, validated_data): + instance.name = validated_data.get('name', instance.name) + # Update other fields similarly + instance.save() + return instance diff --git a/api/serializers/project.py b/api/serializers/project.py new file mode 100644 index 00000000..541bb701 --- /dev/null +++ b/api/serializers/project.py @@ -0,0 +1,15 @@ +from rest_framework import serializers +from api.models.project import Student, Lesgever, Vak, Groep, Project, Indiening, Score + + +class ProjectSerializer(serializers.ModelSerializer): + class Meta: + model = Project + fields = '__all__' + + def create(self, validated_data): + return Project.objects.create(**validated_data) + + def update(self, instance, validated_data): + # Implement update method for Project model + pass diff --git a/api/serializers/score.py b/api/serializers/score.py new file mode 100644 index 00000000..4daacc12 --- /dev/null +++ b/api/serializers/score.py @@ -0,0 +1,15 @@ +from rest_framework import serializers +from api.models.score import Score + + +class ScoreSerializer(serializers.ModelSerializer): + class Meta: + model = Score + fields = '__all__' + + def create(self, validated_data): + return Score.objects.create(**validated_data) + + def update(self, instance, validated_data): + # Implement update method for Score model + pass diff --git a/api/serializers/student.py b/api/serializers/student.py new file mode 100644 index 00000000..d4c8a7bc --- /dev/null +++ b/api/serializers/student.py @@ -0,0 +1,41 @@ +from rest_framework import serializers +from api.models.student import Student + + +class StudentSerializer(serializers.ModelSerializer): + class Meta: + model = Student + fields = '__all__' + + 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: + instance.subjects.clear() # Remove existing subjects + for subject_data in subjects_data: + instance.subjects.add(subject_data) + + instance.save() + return instance + +# gebruiksvoorbeelden + +# serializing objects +#serializer = ProfSerializer(prof) +#serializer.data +#json = JSONRenderer().render(serializer.data) +#json + +#deserializing objects +#stream = io.BytesIO(json) +#data = JSONParser().parse(stream) +#serializer = ProfSerializer(data=data) +#serializer.is_valid() +#serializer.validated_data +#serializer.save() diff --git a/api/serializers/vak.py b/api/serializers/vak.py new file mode 100644 index 00000000..f88a0536 --- /dev/null +++ b/api/serializers/vak.py @@ -0,0 +1,17 @@ +from rest_framework import serializers +from api.models.vak import Vak + + +class VakSerializer(serializers.ModelSerializer): + class Meta: + model = Vak + fields = '__all__' + + def create(self, validated_data): + return Vak.objects.create(**validated_data) + + def update(self, instance, validated_data): + instance.name = validated_data.get('name', instance.name) + # Update other fields similarly + instance.save() + return instance diff --git a/api/views/__pycache__/student.cpython-311.pyc b/api/views/__pycache__/student.cpython-311.pyc deleted file mode 100644 index cbc59453..00000000 Binary files a/api/views/__pycache__/student.cpython-311.pyc and /dev/null differ diff --git a/api/views/__pycache__/views.cpython-311.pyc b/api/views/__pycache__/views.cpython-311.pyc deleted file mode 100644 index 88d01d2d..00000000 Binary files a/api/views/__pycache__/views.cpython-311.pyc and /dev/null differ diff --git a/api/views/lesgever.py b/api/views/lesgever.py new file mode 100644 index 00000000..0830d29c --- /dev/null +++ b/api/views/lesgever.py @@ -0,0 +1,19 @@ +from django.http import JsonResponse +from rest_framework.decorators import api_view +from rest_framework.response import Response +from rest_framework import status +from api.models.lesgever import Lesgever +from api.serializers.lesgever import LesgeverSerializer + + +@api_view(['GET', 'POST']) +def lesgever_list(request): + if request.method == 'GET': + lesgevers = Lesgever.objects.all() + serializer = LesgeverSerializer(lesgevers, many=True) + return JsonResponse({'lesgevers': serializer.data}) + elif request.method == 'POST': + serializer = LesgeverSerializer(data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED) diff --git a/api/views/student.py b/api/views/student.py index cf38cb3b..aa59e299 100644 --- a/api/views/student.py +++ b/api/views/student.py @@ -4,8 +4,14 @@ from rest_framework import status +<<<<<<< HEAD +from api.models.student import Student +from api.serializers.student import StudentSerializer +from ..utils import json_error +======= from ..models import Student from ..serializers.student import StudentSerializer +>>>>>>> develop @api_view(['GET', 'POST']) @@ -19,6 +25,17 @@ def student_list(request): if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) +<<<<<<< HEAD + + + """if request.user.is_superuser: + students = Student.objects.all() + serializer = StudentSerializer(students, many=True) + return JsonResponse({'studenten': serializer.data}) + + else: + return json_error('no_perm')""" +======= return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) @@ -38,3 +55,4 @@ def student_detail(request, id): serializer.save() return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) +>>>>>>> develop diff --git a/api/views/vak.py b/api/views/vak.py new file mode 100644 index 00000000..1bec5a1f --- /dev/null +++ b/api/views/vak.py @@ -0,0 +1,19 @@ +from django.http import JsonResponse +from rest_framework.decorators import api_view +from rest_framework.response import Response +from rest_framework import status +from api.models.vak import Vak +from api.serializers.vak import VakSerializer + + +@api_view(['GET', 'POST']) +def lesgever_list(request): + if request.method == 'GET': + lesgevers = Vak.objects.all() + serializer = VakSerializer(lesgevers, many=True) + return JsonResponse({'lesgevers': serializer.data}) + elif request.method == 'POST': + serializer = VakSerializer(data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data, status=status.HTTP_201_CREATED)