summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--online_test/settings.py34
-rw-r--r--yaksh/models.py5
-rw-r--r--yaksh/storage_backends.py18
-rw-r--r--yaksh/templates/yaksh/add_quiz.html4
4 files changed, 56 insertions, 5 deletions
diff --git a/online_test/settings.py b/online_test/settings.py
index e7e19a0..bca24d5 100644
--- a/online_test/settings.py
+++ b/online_test/settings.py
@@ -52,7 +52,8 @@ INSTALLED_APPS = (
'rest_framework',
'api',
'corsheaders',
- 'rest_framework.authtoken'
+ 'rest_framework.authtoken',
+ 'storages'
)
MIDDLEWARE = (
@@ -162,7 +163,7 @@ PRODUCTION_URL = 'your_project_url'
IS_DEVELOPMENT = True
# Video File upload size
-MAX_UPLOAD_SIZE = 52428800
+MAX_UPLOAD_SIZE = 524288000
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
@@ -250,3 +251,32 @@ REST_FRAMEWORK = {
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
+
+
+# AWS Credentials
+USE_AWS = False
+if USE_AWS:
+ DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
+ STATICFILES_STORAGE = 'storages.backends.s3boto3.S3StaticStorage'
+
+ AWS_ACCESS_KEY_ID = "access-key"
+ AWS_SECRET_ACCESS_KEY = "secret-key"
+ AWS_S3_REGION_NAME = "ap-south-1"
+ AWS_STORAGE_BUCKET_NAME = "yaksh-django"
+ AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.s3.amazonaws.com'
+ AWS_DEFAULT_ACL = 'public-read'
+ AWS_S3_SIGNATURE_VERSION = 's3v4'
+ AWS_S3_ADDRESSING_STYLE = "virtual"
+
+ # Static Location
+ AWS_STATIC_LOCATION = 'static'
+ STATICFILES_STORAGE = 'yaksh.storage_backends.StaticStorage'
+ STATIC_URL = f"https://{AWS_S3_CUSTOM_DOMAIN}/{AWS_STATIC_LOCATION}/"
+
+ # Media Public
+ AWS_PUBLIC_MEDIA_LOCATION = 'media/public'
+ DEFAULT_FILE_STORAGE = 'yaksh.storage_backends.PublicMediaStorage'
+
+ # Media Private
+ AWS_PRIVATE_MEDIA_LOCATION = 'media/private'
+ PRIVATE_FILE_STORAGE = 'yaksh.storage_backends.PrivateMediaStorage'
diff --git a/yaksh/models.py b/yaksh/models.py
index 4798b23..613bf00 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"),
@@ -1446,8 +1448,9 @@ class Question(models.Model):
assignmentQuestion=self
)
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)
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">