summaryrefslogtreecommitdiff
path: root/yaksh/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/views.py')
-rw-r--r--yaksh/views.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/yaksh/views.py b/yaksh/views.py
index 9116026..0aa73b8 100644
--- a/yaksh/views.py
+++ b/yaksh/views.py
@@ -2314,9 +2314,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 +2338,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 +2833,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