diff options
author | adityacp | 2018-06-26 13:13:22 +0530 |
---|---|---|
committer | adityacp | 2018-06-26 13:13:22 +0530 |
commit | 20b692ea468a280e3edb4a9e7f97543b5499025d (patch) | |
tree | aff5b76b2bb3f7b3507e9fe4841762310939273d /yaksh/file_utils.py | |
parent | 4eb754c2e71922819de7390d1b4993a21763de3e (diff) | |
download | online_test-20b692ea468a280e3edb4a9e7f97543b5499025d.tar.gz online_test-20b692ea468a280e3edb4a9e7f97543b5499025d.tar.bz2 online_test-20b692ea468a280e3edb4a9e7f97543b5499025d.zip |
Changes in views, models, forms, urls, file_utils
- Add new view function to download course content
- Add new attribute to Lesson model
- Add new model methods to add course, module and lesson content
- Add validation in forms to check for lesson video file format
- Add functions in file_utils to add static files and templates to the zip file
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r-- | yaksh/file_utils.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py index 6c3fd5d..6b0340f 100644 --- a/yaksh/file_utils.py +++ b/yaksh/file_utils.py @@ -3,6 +3,7 @@ import os import zipfile import tempfile import csv +from django.template import Context, Template def copy_files(file_paths): @@ -66,3 +67,28 @@ def is_csv(document): except (csv.Error, UnicodeDecodeError): return False, None return True, dialect + + +def write_static_files_to_zip(zipfile, course_name, current_dir): + relative_folders = ["css", "js", "images"] + 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"], + "images": ["yaksh_banner.png"]} + for folder in relative_folders: + folder_path = os.sep.join((current_dir, "static", "yaksh", folder)) + for file in static_files[folder]: + file_path = os.sep.join((folder_path, file)) + zipfile.write(file_path, os.sep.join((course_name, "static", + folder, file))) + + +def write_templates_to_zip(zipfile, template_path, data, filename, filepath): + with open(template_path) as f: + template_data = f.read() + template = Template(template_data) + context = Context(data) + render = template.render(context) + zipfile.writestr(os.sep.join((filepath, "{0}.html".format(filename))), + render) |