diff --git a/vre-panel/pages/assignments/[slug].tsx b/vre-panel/pages/assignments/[slug].tsx index 52474bc..9a335a2 100644 --- a/vre-panel/pages/assignments/[slug].tsx +++ b/vre-panel/pages/assignments/[slug].tsx @@ -64,20 +64,15 @@ const AssDetails: React.FC = ({ token }) => { .then((res) => res.json()) .then((data) => { setAss(data) - const url = new URL("http://localhost:8000/api/vlabs/"); - fetch(`${url}`) - .then((res) => res.json()) - .then((data) => { - console.log(data[Ass.vlab]) - setVlab(data[Ass.vlab]) + console.log(data); + setVlab(data.vlab); }) .catch((error) => { console.log('Featching error:'+error) - }); }) - .catch((error) => { - console.log('Featching error:'+error) - }); + .catch((error) => { + console.log('Featching error:'+error) + }); const url2 = new URL("http://localhost:8000/api/students/"); if (userName != "none"){ diff --git a/vreapis/assignments/admin.py b/vreapis/assignments/admin.py index 7074caa..83cfab8 100644 --- a/vreapis/assignments/admin.py +++ b/vreapis/assignments/admin.py @@ -1,5 +1,5 @@ from django.contrib import admin -from assignments.models import Assignment +from assignments.models import Assignment, File from django.forms import TextInput, Textarea from django.db import models @@ -11,4 +11,4 @@ def get_form(self, request, obj=None, **kwargs): return form admin.site.register(Assignment,MyAssignmentAdmin) -# admin.site.register(KeyCloakAuth) \ No newline at end of file +admin.site.register(File) \ No newline at end of file diff --git a/vreapis/assignments/migrations/0010_assignment_enrolled_studebts.py b/vreapis/assignments/migrations/0010_assignment_enrolled_studebts.py new file mode 100644 index 0000000..b2fe572 --- /dev/null +++ b/vreapis/assignments/migrations/0010_assignment_enrolled_studebts.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.10 on 2023-09-09 18:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('students', '0005_alter_student_keycloak_id'), + ('assignments', '0009_remove_assignment_vlab_slug'), + ] + + operations = [ + migrations.AddField( + model_name='assignment', + name='enrolled_studebts', + field=models.ManyToManyField(null=True, to='students.student'), + ), + ] diff --git a/vreapis/assignments/migrations/0011_alter_assignment_enrolled_studebts.py b/vreapis/assignments/migrations/0011_alter_assignment_enrolled_studebts.py new file mode 100644 index 0000000..ab0346f --- /dev/null +++ b/vreapis/assignments/migrations/0011_alter_assignment_enrolled_studebts.py @@ -0,0 +1,19 @@ +# Generated by Django 4.0.10 on 2023-09-09 18:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('students', '0005_alter_student_keycloak_id'), + ('assignments', '0010_assignment_enrolled_studebts'), + ] + + operations = [ + migrations.AlterField( + model_name='assignment', + name='enrolled_studebts', + field=models.ManyToManyField(blank=True, null=True, to='students.student'), + ), + ] diff --git a/vreapis/assignments/migrations/0012_rename_enrolled_studebts_assignment_enrolled_students.py b/vreapis/assignments/migrations/0012_rename_enrolled_studebts_assignment_enrolled_students.py new file mode 100644 index 0000000..3a96ea8 --- /dev/null +++ b/vreapis/assignments/migrations/0012_rename_enrolled_studebts_assignment_enrolled_students.py @@ -0,0 +1,18 @@ +# Generated by Django 4.0.10 on 2023-09-09 18:51 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('assignments', '0011_alter_assignment_enrolled_studebts'), + ] + + operations = [ + migrations.RenameField( + model_name='assignment', + old_name='enrolled_studebts', + new_name='enrolled_students', + ), + ] diff --git a/vreapis/assignments/migrations/0013_file_assignment_files.py b/vreapis/assignments/migrations/0013_file_assignment_files.py new file mode 100644 index 0000000..9e70053 --- /dev/null +++ b/vreapis/assignments/migrations/0013_file_assignment_files.py @@ -0,0 +1,26 @@ +# Generated by Django 4.0.10 on 2023-09-09 19:32 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('assignments', '0012_rename_enrolled_studebts_assignment_enrolled_students'), + ] + + operations = [ + migrations.CreateModel( + name='File', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('file', models.FileField(upload_to='files/%Y/%m/%d')), + ], + ), + migrations.AddField( + model_name='assignment', + name='files', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='files', to='assignments.file'), + ), + ] diff --git a/vreapis/assignments/migrations/0014_remove_assignment_files_assignment_files.py b/vreapis/assignments/migrations/0014_remove_assignment_files_assignment_files.py new file mode 100644 index 0000000..e898ebd --- /dev/null +++ b/vreapis/assignments/migrations/0014_remove_assignment_files_assignment_files.py @@ -0,0 +1,22 @@ +# Generated by Django 4.0.10 on 2023-09-09 19:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('assignments', '0013_file_assignment_files'), + ] + + operations = [ + migrations.RemoveField( + model_name='assignment', + name='files', + ), + migrations.AddField( + model_name='assignment', + name='files', + field=models.ManyToManyField(blank=True, null=True, to='assignments.file'), + ), + ] diff --git a/vreapis/assignments/models.py b/vreapis/assignments/models.py index 0c11a3f..9b59e71 100644 --- a/vreapis/assignments/models.py +++ b/vreapis/assignments/models.py @@ -16,7 +16,8 @@ class Meta: verbose_name = "Asg Profile" verbose_name_plural = "Asg Profiles" - +class File(models.Model): + file = models.FileField(upload_to="files") class Assignment(models.Model): created = models.DateTimeField(auto_now_add=True, null=True) @@ -25,8 +26,8 @@ class Assignment(models.Model): short_description = models.CharField(max_length=1000) long_description = models.CharField(max_length=10000, null=True) vlab = models.ForeignKey('virtual_labs.VirtualLab', on_delete=models.CASCADE, null=True) - - + enrolled_students = models.ManyToManyField('students.Student',null=True,blank=True) + files=models.ManyToManyField(File,null=True,blank=True) def __str__(self): return self.title diff --git a/vreapis/assignments/serializers.py b/vreapis/assignments/serializers.py index e4875d5..2c4fffa 100644 --- a/vreapis/assignments/serializers.py +++ b/vreapis/assignments/serializers.py @@ -2,11 +2,11 @@ from pyexpat import model from rest_framework import serializers from django.contrib.auth.models import User -from assignments.models import AsgProfile, Assignment +from assignments.models import AsgProfile, Assignment, File from workflows.models import Workflow from workflows.serializers import WorkflowSerializer - - +from virtual_labs.models import VirtualLab +from students.models import Student class AsgProfileSerializer(serializers.ModelSerializer): @@ -27,8 +27,27 @@ class Meta: 'username' ] +class VirtualLabSerializer(serializers.ModelSerializer): + + endpoint = serializers.SerializerMethodField() + + def get_endpoint(self, vlab): + return f"https://{vlab.fqdn}:{vlab.ingress_ssl_port}/{vlab.base_url}/" + + class Meta: + model = VirtualLab + fields = ( + 'title', + 'slug', + 'description', + 'endpoint' + ) + + + class AssignmentSerializer(serializers.ModelSerializer): + vlab = VirtualLabSerializer(many=False) class Meta: model = Assignment @@ -40,9 +59,36 @@ class Meta: ) +class StudentSerializer(serializers.ModelSerializer): + + + class Meta: + model = Student + fields = ( + 'created', + 'keycloak_ID', + 'name', + 'slug', + 'assignments_enrolled', + + ) + +class FileSerializer(serializers.ModelSerializer): + + + class Meta: + model = File + fields = ( + 'file', + ) + + class AssignmentDetailSerializer(serializers.ModelSerializer): + vlab = VirtualLabSerializer(many=False) + enrolled_students = StudentSerializer(many=True) + files = FileSerializer(many=True) class Meta: model = Assignment fields = ( @@ -50,7 +96,9 @@ class Meta: 'slug', 'short_description', 'long_description', - 'vlab' + 'vlab', + 'enrolled_students', + 'files' ) diff --git a/vreapis/assignments/views.py b/vreapis/assignments/views.py index fb0be93..e527639 100644 --- a/vreapis/assignments/views.py +++ b/vreapis/assignments/views.py @@ -7,7 +7,7 @@ from workflows.serializers import WorkflowSerializer import requests from vreapis.views import GetSerializerMixin - +from rest_framework.response import Response class AssignmentViewSet(GetSerializerMixin, viewsets.ModelViewSet): @@ -18,4 +18,8 @@ class AssignmentViewSet(GetSerializerMixin, viewsets.ModelViewSet): 'list': serializers.AssignmentSerializer } +class UploadViewSet(GetSerializerMixin, viewsets.ModelViewSet): + serializer_class = serializers.FileSerializer + queryset = models.File.objects.all() + serializer_class = serializers.FileSerializer diff --git a/vreapis/files/2023/09/09/test_file.txt b/vreapis/files/2023/09/09/test_file.txt new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/vreapis/files/2023/09/09/test_file.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/vreapis/files/test_file.txt b/vreapis/files/test_file.txt new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/vreapis/files/test_file.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/vreapis/files/test_file_tDXS6rU.txt b/vreapis/files/test_file_tDXS6rU.txt new file mode 100644 index 0000000..30d74d2 --- /dev/null +++ b/vreapis/files/test_file_tDXS6rU.txt @@ -0,0 +1 @@ +test \ No newline at end of file diff --git a/vreapis/vreapis/urls.py b/vreapis/vreapis/urls.py index 6e00108..da4293c 100644 --- a/vreapis/vreapis/urls.py +++ b/vreapis/vreapis/urls.py @@ -17,7 +17,7 @@ from django.urls import path, include from rest_framework import routers from virtual_labs.views import VirtualLabViewSet -from assignments.views import AssignmentViewSet +from assignments.views import AssignmentViewSet, UploadViewSet from cells.views import CellsViewSet from students.views import StudentViewSet from workflows.views import WorkflowViewSet @@ -30,6 +30,7 @@ router.register(r'workflows', WorkflowViewSet) router.register(r'cells', CellsViewSet) router.register(r'students', StudentViewSet) +router.register(r'files', UploadViewSet) urlpatterns = [ path('admin/', admin.site.urls),