summaryrefslogtreecommitdiff
path: root/yaksh/file_utils.py
diff options
context:
space:
mode:
authoradityacp2018-07-10 15:47:46 +0530
committeradityacp2018-07-10 15:47:46 +0530
commitc075bc00bc57507f2af4d47f7f2e5e063df6921a (patch)
tree79cbae95ddcaa6bbfa7cd47944e249f9b242464d /yaksh/file_utils.py
parent5bd270e21bfdf08bd73940bf471ebcf566fb9de6 (diff)
downloadonline_test-c075bc00bc57507f2af4d47f7f2e5e063df6921a.tar.gz
online_test-c075bc00bc57507f2af4d47f7f2e5e063df6921a.tar.bz2
online_test-c075bc00bc57507f2af4d47f7f2e5e063df6921a.zip
Change in file_utils, forms, models, lesson.css, add_lesson.html, views
- Add new function in the file_utils to render template - Add webm as supported video format in forms - Add help text in video_file field - Add lesson.css file for adding custom styling for lessons - Add static_files dict in download_course views function
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r--yaksh/file_utils.py54
1 files changed, 46 insertions, 8 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py
index 8a94260..88fc46d 100644
--- a/yaksh/file_utils.py
+++ b/yaksh/file_utils.py
@@ -69,12 +69,25 @@ def is_csv(document):
return True, dialect
-def write_static_files_to_zip(zipfile, course_name, current_dir):
- 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"]}
+def write_static_files_to_zip(zipfile, course_name, current_dir, static_files):
+ """ Write static files to zip
+
+ Parameters
+ ----------
+
+ zipfile : Zipfile object
+ zip file in which the static files need to be added
+
+ course_name : str
+ Create a folder with course name
+
+ current_dir: str
+ Path from which the static files will be taken
+
+ static_files: dict
+ Dictionary containing static folders as keys and static files as
+ values
+ """
for folder in static_files.keys():
folder_path = os.sep.join((current_dir, "static", "yaksh", folder))
for file in static_files[folder]:
@@ -87,10 +100,35 @@ def write_static_files_to_zip(zipfile, course_name, current_dir):
def write_templates_to_zip(zipfile, template_path, data, filename, filepath):
+ """ Write template files to zip
+
+ Parameters
+ ----------
+
+ zipfile : Zipfile object
+ zip file in which the template files need to be added
+
+ template_path : str
+ Path from which the template file will be loaded
+
+ data: dict
+ Dictionary containing context data required for template
+
+ filename: str
+ Filename with which the template file should be named
+
+ filepath: str
+ File path in zip where the template will be added
+ """
+ rendered_template = render_template(template_path, data)
+ zipfile.writestr(os.sep.join((filepath, "{0}.html".format(filename))),
+ str(rendered_template))
+
+
+def render_template(template_path, data):
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))),
- str(render))
+ return render