summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradityacp2020-09-30 19:14:38 +0530
committeradityacp2020-09-30 19:35:28 +0530
commitc6c57869fe653d2ea0502017a9fb15f2f745491b (patch)
treee225826a16daf9a9485607457d5d67b568753553
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
-rw-r--r--yaksh/templates/yaksh/show_toc.html28
-rw-r--r--yaksh/templatetags/custom_filters.py14
-rw-r--r--yaksh/test_views.py9
-rw-r--r--yaksh/urls.py2
-rw-r--r--yaksh/views.py30
5 files changed, 60 insertions, 23 deletions
diff --git a/yaksh/templates/yaksh/show_toc.html b/yaksh/templates/yaksh/show_toc.html
index ddaad74..92ea0cd 100644
--- a/yaksh/templates/yaksh/show_toc.html
+++ b/yaksh/templates/yaksh/show_toc.html
@@ -1,13 +1,21 @@
-<div>
- <form action="" method="POST" enctype="multipart/form-data">
- {% csrf_token %}
- <input type="file" name="toc" required="">
- <button class="btn btn-outline-success" id="upload_toc" name="upload_toc">
- <i class="fa fa-upload"></i>&nbsp;Upload TOC
- </button>
- </form>
-</div>
-<hr>
+{% load custom_filters %}
+{% has_lesson_video lesson_id as has_video %}
+{% if has_video %}
+ <div>
+ <a href="{% url 'yaksh:download_sample_toc' %}">
+ <i class="fa fa-download"></i>&nbsp;Download Sample
+ </a>
+ <br><br>
+ <form action="" method="POST" enctype="multipart/form-data">
+ {% csrf_token %}
+ <input type="file" name="toc" required="">
+ <button class="btn btn-outline-success" id="upload_toc" name="upload_toc">
+ <i class="fa fa-upload"></i>&nbsp;Upload TOC
+ </button>
+ </form>
+ </div>
+ <hr>
+{% endif %}
<table class="table table-responsive-sm">
{% for toc in contents %}
{% with toc.get_toc_text as toc_name %}
diff --git a/yaksh/templatetags/custom_filters.py b/yaksh/templatetags/custom_filters.py
index c3dbba3..57ec7dd 100644
--- a/yaksh/templatetags/custom_filters.py
+++ b/yaksh/templatetags/custom_filters.py
@@ -10,7 +10,7 @@ except ImportError:
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter
-from yaksh.models import User, Course, Quiz, TableOfContents
+from yaksh.models import User, Course, Quiz, TableOfContents, Lesson
register = template.Library()
@@ -182,4 +182,14 @@ def specail_attempt_monitor(user_id, course_id, quiz_id):
@register.simple_tag
def get_answers(toc_id, user_id):
- return TableOfContents.objects.get_answer(toc_id, user_id) \ No newline at end of file
+ return TableOfContents.objects.get_answer(toc_id, user_id)
+
+
+@register.simple_tag
+def has_lesson_video(lesson_id):
+ lesson = Lesson.objects.filter(id=lesson_id)
+ if lesson.exists():
+ status = True if lesson.first().video_path else False
+ else:
+ status = False
+ return status \ No newline at end of file
diff --git a/yaksh/test_views.py b/yaksh/test_views.py
index 9ce3e8b..d80a01e 100644
--- a/yaksh/test_views.py
+++ b/yaksh/test_views.py
@@ -3320,7 +3320,7 @@ class TestCourseDetail(TestCase):
response = self.client.get(reverse('yaksh:download_sample_csv'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.get('Content-Disposition'),
- 'attachment; filename="sample_user_upload"')
+ 'attachment; filename="sample_user_upload.csv"')
def test_view_course_status(self):
""" Test to view course status """
@@ -8484,7 +8484,7 @@ class TestLessonContents(TestCase):
self.assertEqual(response.status_code, 200)
self.assertEqual(student_info.get("student_id"), self.student.id)
- def test_upload_lesson_contents(self):
+ def test_upload_download_lesson_contents(self):
self.client.login(
username=self.user1.username,
password=self.user1_plaintext_pass
@@ -8567,3 +8567,8 @@ class TestLessonContents(TestCase):
)
self.assertIn("Invalid time format", messages[1])
+ # Download yaml sample
+ response = self.client.get(reverse('yaksh:download_sample_toc'))
+ self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.get('Content-Disposition'),
+ 'attachment; filename="sample_lesson_toc.yaml"')
diff --git a/yaksh/urls.py b/yaksh/urls.py
index 7bd3182..b60b5f5 100644
--- a/yaksh/urls.py
+++ b/yaksh/urls.py
@@ -267,4 +267,6 @@ urlpatterns = [
views.lesson_statistics, name='lesson_statistics'),
path('manage/lesson/stats/<int:course_id>/<int:lesson_id>/<int:toc_id>',
views.lesson_statistics, name='lesson_statistics'),
+ path('manage/download/sample/toc',
+ views.download_sample_toc, name='download_sample_toc'),
]
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