summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
authoradityacp2020-09-30 19:14:38 +0530
committeradityacp2020-09-30 19:35:28 +0530
commitc6c57869fe653d2ea0502017a9fb15f2f745491b (patch)
treee225826a16daf9a9485607457d5d67b568753553 /yaksh/views.py
parent86be5fd441b92a7679eb2b8673bfba2c188ba0ba (diff)
downloadonline_test-c6c57869fe653d2ea0502017a9fb15f2f745491b.tar.gz
online_test-c6c57869fe653d2ea0502017a9fb15f2f745491b.tar.bz2
online_test-c6c57869fe653d2ea0502017a9fb15f2f745491b.zip
Change multiple files
- Add download sample yaml for toc in the lesson - Add validation for upload toc yaml - Add tests for download sample yaml toc
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 9cca425..73979da 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -2583,7 +2583,23 @@ def download_sample_csv(request):
with open(csv_file_path, 'rb') as csv_file:
response = HttpResponse(csv_file.read(), content_type='text/csv')
response['Content-Disposition'] = (
- 'attachment; filename="sample_user_upload"'
+ 'attachment; filename="sample_user_upload.csv"'
+ )
+ return response
+
+
+@login_required
+@email_verified
+def download_sample_toc(request):
+ user = request.user
+ if not is_moderator(user):
+ raise Http404('You are not allowed to view this page!')
+ csv_file_path = os.path.join(FIXTURES_DIR_PATH,
+ "sample_lesson_toc.yaml")
+ with open(csv_file_path, 'rb') as csv_file:
+ response = HttpResponse(csv_file.read(), content_type='text/yaml')
+ response['Content-Disposition'] = (
+ 'attachment; filename="sample_lesson_toc.yaml"'
)
return response
@@ -2731,13 +2747,7 @@ def edit_lesson(request, course_id=None, module_id=None, lesson_id=None):
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")
- data = loader.render_to_string(
- "yaksh/show_toc.html", context={'contents': contents},
- request=request
- )
+ data = get_toc_contents(request, course_id, lesson_id)
context['toc'] = data
lesson_files = LessonFile.objects.filter(lesson=lesson)
context['lesson_form'] = lesson_form
@@ -3591,7 +3601,9 @@ def get_toc_contents(request, course_id, lesson_id):
course_id=course_id, lesson_id=lesson_id
).order_by("time")
data = loader.render_to_string(
- "yaksh/show_toc.html", context={'contents': contents},
+ "yaksh/show_toc.html", context={
+ 'contents': contents, 'lesson_id': lesson_id
+ },
request=request
)
return data