summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authoradityacp2020-09-30 17:02:19 +0530
committeradityacp2020-09-30 17:02:19 +0530
commit86be5fd441b92a7679eb2b8673bfba2c188ba0ba (patch)
treedf989862240f7027b017a44d6a46c0bfe9443cd7 /yaksh/views.py
parent2dcaa3847c4faefd14ee88b9a2370e1d83e747f0 (diff)
downloadonline_test-86be5fd441b92a7679eb2b8673bfba2c188ba0ba.tar.gz
online_test-86be5fd441b92a7679eb2b8673bfba2c188ba0ba.tar.bz2
online_test-86be5fd441b92a7679eb2b8673bfba2c188ba0ba.zip
Add table of contents for lesson with yaml upload
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index a3d7def..9cca425 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -24,6 +24,7 @@ import json
from textwrap import dedent
import zipfile
import markdown
+import ruamel
try:
from StringIO import StringIO as string_io
except ImportError:
@@ -2710,6 +2711,26 @@ def edit_lesson(request, course_id=None, module_id=None, lesson_id=None):
request, "Please select atleast one file to delete"
)
+ if 'upload_toc' in request.POST:
+ toc_file = request.FILES.get('toc')
+ file_extension = os.path.splitext(toc_file.name)[1][1:]
+ if file_extension not in ['yaml', 'yml']:
+ messages.warning(
+ request, "Please upload yaml or yml type file"
+ )
+ else:
+ try:
+ toc_data = ruamel.yaml.safe_load_all(toc_file.read())
+ results = TableOfContents.objects.add_contents(
+ course_id, lesson_id, user, toc_data)
+ for status, msg in results:
+ if status == True:
+ messages.success(request, msg)
+ else:
+ messages.warning(request, msg)
+ except Exception as e:
+ messages.warning(request, f"Error parsing yaml: {e}")
+
contents = TableOfContents.objects.filter(
course_id=course_id, lesson_id=lesson_id
).order_by("time")