Skip to content

Commit

Permalink
Section added for materials in the assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
latifedag committed Sep 11, 2023
1 parent a7da5c9 commit 7182c2d
Showing 14 changed files with 177 additions and 21 deletions.
15 changes: 5 additions & 10 deletions vre-panel/pages/assignments/[slug].tsx
Original file line number Diff line number Diff line change
@@ -64,20 +64,15 @@ const AssDetails: React.FC<AssDetailsProps> = ({ 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"){
4 changes: 2 additions & 2 deletions vreapis/assignments/admin.py
Original file line number Diff line number Diff line change
@@ -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)
admin.site.register(File)
Original file line number Diff line number Diff line change
@@ -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'),
),
]
Original file line number Diff line number Diff line change
@@ -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'),
),
]
Original file line number Diff line number Diff line change
@@ -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',
),
]
26 changes: 26 additions & 0 deletions vreapis/assignments/migrations/0013_file_assignment_files.py
Original file line number Diff line number Diff line change
@@ -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'),
),
]
Original file line number Diff line number Diff line change
@@ -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'),
),
]
7 changes: 4 additions & 3 deletions vreapis/assignments/models.py
Original file line number Diff line number Diff line change
@@ -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
56 changes: 52 additions & 4 deletions vreapis/assignments/serializers.py
Original file line number Diff line number Diff line change
@@ -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,17 +59,46 @@ 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 = (
'title',
'slug',
'short_description',
'long_description',
'vlab'
'vlab',
'enrolled_students',
'files'
)


6 changes: 5 additions & 1 deletion vreapis/assignments/views.py
Original file line number Diff line number Diff line change
@@ -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

1 change: 1 addition & 0 deletions vreapis/files/2023/09/09/test_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
1 change: 1 addition & 0 deletions vreapis/files/test_file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
1 change: 1 addition & 0 deletions vreapis/files/test_file_tDXS6rU.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test
3 changes: 2 additions & 1 deletion vreapis/vreapis/urls.py
Original file line number Diff line number Diff line change
@@ -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),

0 comments on commit 7182c2d

Please sign in to comment.