Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions FusionIIIT/applications/online_cms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from .models import (Assignment, CourseDocuments, CourseVideo, Forum,
ForumReply, Quiz, QuizQuestion, QuizResult, StudentAnswer,
StudentAssignment, Topics,CourseSlide)
StudentAssignment1, Topics,CourseSlide,CourseAssignment
)

class QuizResultAdmin(admin.ModelAdmin):
model = QuizResult
Expand All @@ -11,7 +12,7 @@ class QuizResultAdmin(admin.ModelAdmin):
admin.site.register(CourseDocuments)
admin.site.register(CourseSlide)
admin.site.register(CourseVideo)

admin.site.register(CourseAssignment)
admin.site.register(Quiz)

admin.site.register(Topics)
Expand All @@ -22,7 +23,7 @@ class QuizResultAdmin(admin.ModelAdmin):

admin.site.register(Assignment)

admin.site.register(StudentAssignment)
admin.site.register(StudentAssignment1)

admin.site.register(QuizResult, QuizResultAdmin)

Expand Down
6 changes: 5 additions & 1 deletion FusionIIIT/applications/online_cms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,8 @@ class Meta:
fields=['couse_id','doc']

# title = forms.CharField(max_length=50)
file = forms.FileField()
file = forms.FileField()

class AssignmentMarks(forms.Form):
marks=forms.IntegerField()
feedback=forms.CharField(max_length=255)
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Generated by Django 3.1.5 on 2023-04-06 16:25

import applications.online_cms.models
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('academic_information', '0002_student_hall_id'),
('online_cms', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='CourseAssignment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('upload_time', models.DateTimeField(auto_now=True)),
('submit_date', models.DateTimeField()),
('assignment_name', models.CharField(max_length=100)),
('doc', models.FileField(blank=True, null=True, upload_to=applications.online_cms.models.assignment_file_name)),
('course_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='academic_information.course')),
],
),
migrations.CreateModel(
name='CourseSlide',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('upload_time', models.DateTimeField(auto_now=True)),
('document_name', models.CharField(max_length=40)),
('description', models.CharField(max_length=100)),
('doc', models.FileField(blank=True, null=True, upload_to=applications.online_cms.models.content_file_name)),
('course_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='academic_information.course')),
],
),
migrations.CreateModel(
name='StudentAssignment1',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('upload_time', models.DateTimeField(auto_now=True)),
('course_code', models.CharField(max_length=100)),
('doc', models.FileField(blank=True, null=True, upload_to=applications.online_cms.models.assignment_submit_name)),
('score', models.IntegerField(null=True)),
('feedback', models.CharField(max_length=100, null=True)),
('assign_name', models.CharField(max_length=100)),
('assignment_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='online_cms.courseassignment')),
('student_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='academic_information.student')),
],
),
migrations.AlterField(
model_name='coursedocuments',
name='document_url',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.DeleteModel(
name='StudentAssignment',
),
]
21 changes: 14 additions & 7 deletions FusionIIIT/applications/online_cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class CourseDocuments(models.Model):
upload_time = models.DateTimeField(auto_now=True)
description = models.CharField(max_length=100)
document_name = models.CharField(max_length=40)
document_url = models.CharField(max_length=500, null=True,blank=True)
# media = models.FileField(upload_to=content_file_name, null=True, blank=True)
document_url = models.CharField(max_length=100, null=True,blank=True)

def __str__(self):
return '{} - {}'.format(self.course_id, self.document_name)
Expand Down Expand Up @@ -186,16 +185,24 @@ class CourseAssignment(models.Model):
def __str__(self):
return '{} - {} - {}'.format(self.pk, self.course_id, self.assignment_name)

#details of the solution uploaded by the student
class StudentAssignment(models.Model):

def assignment_submit_name(instance, filename):
name, ext = filename.split('.')
course_code=instance.course_code
assignmentName=instance.assignment_id.assignment_name
file_path = 'online_cms/{course_id}/assi/{assignmentName}/{fileName}.{ext}'.format(
course_id=course_code,assignmentName=assignmentName, fileName=name, ext=ext)
return file_path
class StudentAssignment1(models.Model):
student_id = models.ForeignKey(Student, on_delete=models.CASCADE)
assignment_id = models.ForeignKey(Assignment, on_delete=models.CASCADE)
assignment_id = models.ForeignKey(CourseAssignment, on_delete=models.CASCADE)
upload_time = models.DateTimeField(auto_now=True)
upload_url = models.TextField(max_length=200)
# upload_url = models.TextField(max_length=200)
course_code=models.CharField(max_length=100)
doc = models.FileField(upload_to=assignment_submit_name, null=True, blank=True)
score = models.IntegerField(null=True) #score is submitted by faculty
feedback = models.CharField(max_length=100, null=True) #feedback by the faculty for the solution of the assignment submitted
assign_name = models.CharField(max_length=100)

def __str__(self):
return '{} - {} - {} - {} - {}'.format(
self.pk, self.student_id,
Expand Down
4 changes: 3 additions & 1 deletion FusionIIIT/applications/online_cms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
url(r'^(?P<course_code>[A-z]+[0-9]+[A-z]?)/edit_bank/(?P<qb_code>[0-9]+)$',
views.edit_bank, name='edit_bank'),
url(r'^(?P<course_code>[A-z]+[0-9]+[A-z]?)/attendance$', views.submit_attendance,
name='submit_attendance'),]
name='submit_attendance'),
url(r'^(?P<course_code>[A-z]+[0-9]+[A-z]?)/edit-assignment-marks$', views.edit_assignment_marks,
name='assignment_marks'), ]

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
96 changes: 43 additions & 53 deletions FusionIIIT/applications/online_cms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from django.http import HttpResponse, HttpResponseBadRequest
from django.shortcuts import redirect, render
from django.utils import timezone
from django.contrib import messages

from applications.academic_information.models import (Course, Curriculum_Instructor,Curriculum,
Student,Student_attendance)
Expand All @@ -25,6 +26,8 @@
# from .helpers import create_thumbnail, semester
from .models import *
from .helpers import create_thumbnail, semester
from django.shortcuts import HttpResponseRedirect
from django.urls import reverse


@login_required
Expand Down Expand Up @@ -171,15 +174,13 @@ def course(request, course_code):
# 'title': res['snippet']['title'],
# }

# videos.append(video_data)
# print(videos)

slides = CourseDocuments.objects.select_related().filter(course_id=course)
slides = CourseSlide.objects.select_related().filter(course_id=course)
quiz = Quiz.objects.select_related().filter(course_id=course)
assignment = Assignment.objects.select_related().filter(course_id=course)
assignment = CourseAssignment.objects.select_related().filter(course_id=course)
student_assignment = []
for assi in assignment:
sa = StudentAssignment.objects.select_related().filter(assignment_id=assi, student_id=student)
sa = StudentAssignment1.objects.select_related().filter(assignment_id=assi, student_id=student)
student_assignment.append(sa)
'''
marks to store the marks of quizes of student
Expand Down Expand Up @@ -309,16 +310,16 @@ def course(request, course_code):
# tempform.course_id=course
# tempform.save()
videos=[]
slides1=CourseSlide.objects.select_related().filter(course_id=course)
slides = CourseDocuments.objects.select_related().filter(course_id=course)
slides1 = CourseSlide.objects.select_related().filter(course_id=course)
slides=None
quiz = Quiz.objects.select_related().filter(course_id=course)
marks = []
quizs = []
assignment = Assignment.objects.select_related().filter(course_id=course)
assignment1 = CourseAssignment.objects.select_related().filter(course_id=course)
student_assignment = []
for assi in assignment:
sa = StudentAssignment.objects.select_related().filter(assignment_id=assi)
for assi in assignment1:
sa = StudentAssignment1.objects.select_related().filter(assignment_id=assi)
student_assignment.append(sa)
for q in quiz:
qs = QuizResult.objects.select_related().filter(quiz_id=q)
Expand Down Expand Up @@ -370,28 +371,21 @@ def upload_assignment(request, course_code):
doc = request.FILES.get('img') #the images in the assignment
assi_name = request.POST.get('assignment_topic')
name = request.POST.get('name')
assign = Assignment.objects.get(pk=assi_name)
assign = CourseAssignment.objects.get(pk=assi_name)
filename, file_extenstion = os.path.splitext(request.FILES.get('img').name)
except:
return HttpResponse("Please fill each and every field correctly!")
filename = name
full_path = settings.MEDIA_ROOT + "/online_cms/" + course_code + "/assi/" #storing the media files
full_path = full_path + assign.assignment_name + "/" + student.id.id + "/"
url = settings.MEDIA_URL + filename
if not os.path.isdir(full_path):
cmd = "mkdir " + full_path
subprocess.call(cmd, shell=True)
fs = FileSystemStorage(full_path, url)
fs.save(name + file_extenstion, doc) #saving the media files
uploaded_file_url = full_path+ "/" + name + file_extenstion

# to save the solution of assignment the database
sa = StudentAssignment(
student_id=student,
assignment_id=assign,
upload_url=uploaded_file_url,
assign_name=name+file_extenstion
StudentAssignment1.objects.create(
student_id=student,
doc=doc,
assignment_id=assign,
course_code=course_code,
assign_name=name+file_extenstion

)
sa.save()
return HttpResponse("Upload successful.")
else:
return HttpResponse("not found")
Expand Down Expand Up @@ -435,13 +429,7 @@ def add_document(request, course_code):
document_name=name,
doc=doc
)
# CourseDocuments.objects.create(
# course_id=course,
# upload_time=datetime.datetime.now(),
# description=description,
# document_url=uploaded_file_url,
# document_name=name+file_extenstion
# )

return HttpResponse("Upload successful.")
else:

Expand Down Expand Up @@ -479,12 +467,12 @@ def delete(request, course_code):
slide.delete()
#to delete the submitted assignment
elif data_type == 'stuassignment':
stu_assi = StudentAssignment.objects.select_related().get(pk=pk)
stu_assi = StudentAssignment1.objects.select_related().get(pk=pk)
path = stu_assi.upload_url
stu_assi.delete()
#to delete the assignment uploaded by faculty
elif data_type == 'lecassignment':
lec_assi = Assignment.objects.select_related().get(pk=pk)
lec_assi = CourseAssignment.objects.select_related().get(pk=pk)
path = lec_assi.assignment_url
lec_assi.delete()
cmd = "rm "+path
Expand Down Expand Up @@ -607,8 +595,7 @@ def ajax_new(request, course_code):
roll = student.id.id[:4]
#course = Course.objects.get(course_id=course_code, sem=semester(roll))
curriculum_details = Curriculum.objects.select_related('course_id').filter(course_code=course_code) #curriculum id
#print(curriculum_details[0].course_id)
#print(Curriculum.objects.values_list('curriculum_id'))

course = curriculum_details[0].course_id
else:

Expand Down Expand Up @@ -670,33 +657,36 @@ def add_assignment(request, course_code): #from faculty side
except:
return HttpResponse("Please Enter The Form Properly")
filename = name
full_path = settings.MEDIA_ROOT + "/online_cms/" + course_code + "/assi/" + name + "/"
print(full_path)
url = settings.MEDIA_URL + filename
if not os.path.isdir(full_path):
cmd = "mkdir " + full_path
subprocess.call(cmd, shell=True)
fs = FileSystemStorage(full_path, url)
fs.save(filename+file_extenstion, assi)
uploaded_file_url = full_path + filename + file_extenstion
print(uploaded_file_url)

CourseAssignment.objects.create(
course_id=course,
submit_date=request.POST.get('myDate'),
doc=assi,
assignment_name=name
)
# assign = Assignment(
# course_id=course,
# submit_date=request.POST.get('myDate'),
# assignment_url=uploaded_file_url,
# assignment_name=name
# )
# assign.save()

return HttpResponse("Upload successful.")
else:
return HttpResponse("not found")

@login_required
def edit_assignment_marks(request,*args, **kwargs):
if request.method=='POST':
print("hiii")
form=AssignmentMarks(request.POST)
if form.is_valid():
sa=StudentAssignment1.objects.get(pk=int(request.POST['assignmentid'][0]))
# print()
sa.score=form.cleaned_data['marks']
sa.feedback=form.cleaned_data['feedback']
sa.save()
# print(sa.course_code)
course_code = sa.course_code
# url = reverse('course', args=[course_code])
messages.success(request, 'Marks updated successfullt')
return HttpResponseRedirect('/ocms/'+course_code)
# return redirect(course,course_code='CS416e')
return HttpResponse("Error Occured!")

@login_required
def edit_bank(request, course_code, qb_code):
Expand Down
Loading