summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py50
1 files changed, 46 insertions, 4 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 9116026..c6b1184 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -1434,12 +1434,15 @@ def show_all_questions(request):
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
questions_file = request.FILES['file']
- file_name = questions_file.name.split('.')
- if file_name[-1] == "zip":
- ques = Question()
+ file_extension = questions_file.name.split('.')[-1]
+ ques = Question()
+ if file_extension == "zip":
files, extract_path = extract_files(questions_file)
context['message'] = ques.read_yaml(extract_path, user,
files)
+ elif file_extension in ["yaml", "yml"]:
+ questions = questions_file.read()
+ context['message'] = ques.load_questions(questions, user)
else:
message = "Please Upload a ZIP file"
context['message'] = message
@@ -2314,9 +2317,16 @@ def edit_lesson(request, lesson_id=None, course_id=None):
context = {}
if request.method == "POST":
if "Save" in request.POST:
- lesson_form = LessonForm(request.POST, instance=lesson)
+ lesson_form = LessonForm(request.POST, request.FILES,
+ instance=lesson)
lesson_file_form = LessonFileForm(request.POST, request.FILES)
lessonfiles = request.FILES.getlist('Lesson_files')
+ clear = request.POST.get("video_file-clear")
+ video_file = request.FILES.get("video_file")
+ if (clear or video_file) and lesson:
+ # Remove previous video file if new file is uploaded or
+ # if clear is selected
+ lesson.remove_file()
if lesson_form.is_valid():
if lesson is None:
lesson_form.instance.creator = user
@@ -2331,6 +2341,7 @@ def edit_lesson(request, lesson_id=None, course_id=None):
return my_redirect(redirect_url)
else:
context['lesson_form'] = lesson_form
+ context['error'] = lesson_form["video_file"].errors
context['lesson_file_form'] = lesson_file_form
if 'Delete' in request.POST:
@@ -2825,3 +2836,34 @@ def get_user_data(request, course_id, student_id):
context = Context(data)
data = template.render(context)
return HttpResponse(json.dumps({"user_data": data}), **response_kwargs)
+
+
+@login_required
+@email_verified
+def download_course(request, course_id):
+ user = request.user
+ course = get_object_or_404(Course, pk=course_id)
+ if (not course.is_creator(user) and not course.is_teacher(user) and not
+ course.is_student(user)):
+ raise Http404("You are not allowed to download {0} course".format(
+ course.name))
+ if not course.has_lessons():
+ raise Http404("{0} course does not have any lessons".format(
+ course.name))
+ current_dir = os.path.dirname(__file__)
+ course_name = course.name.replace(" ", "_")
+
+ # Static files required for styling in html template
+ static_files = {"js": ["bootstrap.js", "bootstrap.min.js",
+ "jquery-1.9.1.min.js", "video.js"],
+ "css": ["bootstrap.css", "bootstrap.min.css",
+ "video-js.css", "offline.css"],
+ "images": ["yaksh_banner.png"]}
+ zip_file = course.create_zip(current_dir, static_files)
+ zip_file.seek(0)
+ response = HttpResponse(content_type='application/zip')
+ response['Content-Disposition'] = 'attachment; filename={0}.zip'.format(
+ course_name
+ )
+ response.write(zip_file.read())
+ return response