diff --git a/api/base_templates/file_name.sh b/api/base_templates/file_name.sh new file mode 100755 index 00000000..1fc87ab5 --- /dev/null +++ b/api/base_templates/file_name.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +#@param +# Vul hieronder de namen van de bestanden in die je in de gezipte folder wilt vinden. +file_name="verslag.pdf" + + +if [ -e "$file_name" ]; then + echo "$file_name present: OK" +else + echo "$file_name not present: FAIL" +fi \ No newline at end of file diff --git a/api/base_templates/zip_contains_files.sh b/api/base_templates/zip_contains_files.sh new file mode 100755 index 00000000..99180ea9 --- /dev/null +++ b/api/base_templates/zip_contains_files.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +#@param +# Vul hieronder de namen van de bestanden in die je in de gezipte folder wilt vinden. +file_names=( "testfile1.txt" "testfile2.txt" ) + +#@param +# Vul hieronder de naam van het zip bestand waarin je de files wil vinden +zip_file_name="file.zip" + + +for file_name in "${file_names[@]}"; do + unzip -l $zip_file_name | grep -q $file_name; + if [ "$?" == "0" ] + then + echo "$file_name present: OK" + else + echo "$file_name not present: FAIL" + fi; +done \ No newline at end of file diff --git a/api/middleware.py b/api/middleware.py index 3e3e2962..50e31c9f 100644 --- a/api/middleware.py +++ b/api/middleware.py @@ -3,7 +3,10 @@ from django.contrib.auth.models import User from api.models.gebruiker import Gebruiker from api.serializers.gebruiker import GebruikerSerializer +from api.serializers.template import TemplateSerializer +from django.core.files import File import requests +import os URL = "https://graph.microsoft.com/v1.0/me" @@ -59,6 +62,19 @@ def __call__(self, request): try: Gebruiker.objects.get(pk=request.user.id) except Gebruiker.DoesNotExist: + directory_path = 'api/base_templates' + for filename in os.listdir(directory_path): + file_path = os.path.join(directory_path, filename) + with open(file_path, 'rb') as f: + django_file = File(f) + template_data = { + "user": request.user.id, + "bestand": django_file + } + serializer = TemplateSerializer(data=template_data) + if serializer.is_valid(): + serializer.save() + gebruiker_post_data = { "user": request.user.id, "subjects": [],