diff options
author | adityacp | 2021-03-01 11:13:07 +0530 |
---|---|---|
committer | adityacp | 2021-03-01 11:13:07 +0530 |
commit | 542433598aad0efffee7619e1f113425147bcec0 (patch) | |
tree | be5cb438c81f76ad8d9e593b9e33033f0183c9ab /yaksh | |
parent | b2bf7b9fef33d59cd1e55776a51577d66a252322 (diff) | |
download | online_test-542433598aad0efffee7619e1f113425147bcec0.tar.gz online_test-542433598aad0efffee7619e1f113425147bcec0.tar.bz2 online_test-542433598aad0efffee7619e1f113425147bcec0.zip |
Add AWS support for file upload
Diffstat (limited to 'yaksh')
-rw-r--r-- | yaksh/admin.py | 3 | ||||
-rw-r--r-- | yaksh/models.py | 9 | ||||
-rw-r--r-- | yaksh/storage_backends.py | 18 | ||||
-rw-r--r-- | yaksh/templates/yaksh/add_quiz.html | 4 | ||||
-rw-r--r-- | yaksh/views.py | 18 |
5 files changed, 38 insertions, 14 deletions
diff --git a/yaksh/admin.py b/yaksh/admin.py index e98c7c5..011e24f 100644 --- a/yaksh/admin.py +++ b/yaksh/admin.py @@ -2,7 +2,7 @@ from yaksh.models import Question, Quiz, QuestionPaper, Profile from yaksh.models import (TestCase, StandardTestCase, StdIOBasedTestCase, Course, AnswerPaper, CourseStatus, LearningModule, Lesson, Post, Comment, Topic, TableOfContents, - LessonQuizAnswer, Answer + LessonQuizAnswer, Answer, AssignmentUpload ) from django.contrib import admin @@ -64,3 +64,4 @@ admin.site.register(Topic) admin.site.register(TableOfContents) admin.site.register(LessonQuizAnswer) admin.site.register(Answer) +admin.site.register(AssignmentUpload)
\ No newline at end of file diff --git a/yaksh/models.py b/yaksh/models.py index 11ddf8a..dd3838a 100644 --- a/yaksh/models.py +++ b/yaksh/models.py @@ -51,6 +51,8 @@ from yaksh.code_server import ( from yaksh.settings import SERVER_POOL_PORT, SERVER_HOST_NAME from .file_utils import extract_files, delete_files from grades.models import GradingSystem +from yaksh.storage_backends import PublicMediaStorage + languages = ( ("python", "Python"), @@ -1442,8 +1444,9 @@ class Question(models.Model): assignmentQuestion=self, user=user ) if assignment_files: - metadata['assign_files'] = [(file.assignmentFile.path, False) + metadata['assign_files'] = [(file.assignmentFile.url, False) for file in assignment_files] + print(metadata['assign_files']) question_data['metadata'] = metadata return json.dumps(question_data) @@ -2661,7 +2664,9 @@ class AssignmentUploadManager(models.Manager): class AssignmentUpload(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) assignmentQuestion = models.ForeignKey(Question, on_delete=models.CASCADE) - assignmentFile = models.FileField(upload_to=get_assignment_dir, max_length=255) + assignmentFile = models.FileField( + upload_to=get_assignment_dir, max_length=255 + ) question_paper = models.ForeignKey(QuestionPaper, blank=True, null=True, on_delete=models.CASCADE) course = models.ForeignKey(Course, null=True, blank=True, diff --git a/yaksh/storage_backends.py b/yaksh/storage_backends.py new file mode 100644 index 0000000..4d08c8c --- /dev/null +++ b/yaksh/storage_backends.py @@ -0,0 +1,18 @@ +from django.conf import settings +from storages.backends.s3boto3 import S3Boto3Storage + + +class StaticStorage(S3Boto3Storage): + location = settings.AWS_STATIC_LOCATION if settings.USE_AWS else settings.STATIC_URL + + +class PublicMediaStorage(S3Boto3Storage): + location = settings.AWS_PUBLIC_MEDIA_LOCATION if settings.USE_AWS else settings.MEDIA_URL + file_overwrite = False + + +class PrivateMediaStorage(S3Boto3Storage): + location = settings.AWS_PRIVATE_MEDIA_LOCATION if settings.USE_AWS else settings.MEDIA_URL + default_acl = 'private' + file_overwrite = False + custom_domain = False
\ No newline at end of file diff --git a/yaksh/templates/yaksh/add_quiz.html b/yaksh/templates/yaksh/add_quiz.html index 1609639..d43c1c6 100644 --- a/yaksh/templates/yaksh/add_quiz.html +++ b/yaksh/templates/yaksh/add_quiz.html @@ -65,11 +65,11 @@ <br> <br> <h4>You can check the quiz by attempting it in the following modes:</h4> - <a class="btn btn-outline-info" name="button" href="{% url 'yaksh:test_quiz' 'usermode' quiz.id course_id %}" target="blank"> + <a class="btn btn-outline-info" name="button" href="{% url 'yaksh:test_quiz' 'usermode' quiz.id course_id %}" target="_blank"> Try as student </a> - <a class="btn btn-outline-primary" name="button" href="{% url 'yaksh:test_quiz' 'godmode' quiz.id course_id %}" target="blank"> + <a class="btn btn-outline-primary" name="button" href="{% url 'yaksh:test_quiz' 'godmode' quiz.id course_id %}" target="_blank"> Try as teacher </a> <a data-toggle="modal" data-target="#help"> diff --git a/yaksh/views.py b/yaksh/views.py index 1965191..8422110 100644 --- a/yaksh/views.py +++ b/yaksh/views.py @@ -858,15 +858,15 @@ def check(request, q_id, attempt_num=None, questionpaper_id=None, ) for fname in assignment_filename: fname._name = fname._name.replace(" ", "_") - assignment_files = AssignmentUpload.objects.filter( - assignmentQuestion=current_question, course_id=course_id, - assignmentFile__icontains=fname, user=user, - question_paper=questionpaper_id) - if assignment_files.exists(): - assign_file = assignment_files.first() - if os.path.exists(assign_file.assignmentFile.path): - os.remove(assign_file.assignmentFile.path) - assign_file.delete() + # assignment_files = AssignmentUpload.objects.filter( + # assignmentQuestion=current_question, course_id=course_id, + # assignmentFile__icontains=fname, user=user, + # question_paper=questionpaper_id) + # if assignment_files.exists(): + # assign_file = assignment_files.first() + # if os.path.exists(assign_file.assignmentFile.path): + # os.remove(assign_file.assignmentFile.path) + # assign_file.delete() AssignmentUpload.objects.create( user=user, assignmentQuestion=current_question, course_id=course_id, |