X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/f324dab1ea7d6b9fa6a0f7a70369a0e5bcfa34e2..a9925ebffe713307d6bedecd670df1490aa206c8:/src/catalogue/utils.py?ds=sidebyside diff --git a/src/catalogue/utils.py b/src/catalogue/utils.py index 916fd7090..ee3631c76 100644 --- a/src/catalogue/utils.py +++ b/src/catalogue/utils.py @@ -19,7 +19,7 @@ from django.conf import settings from django.core.files.storage import DefaultStorage from django.core.files.uploadedfile import UploadedFile from django.http import HttpResponse -from django.utils.encoding import force_text +from django.utils.encoding import force_str from reporting.utils import read_chunks @@ -97,7 +97,7 @@ class LockFile(object): # @task -def create_zip(paths, zip_slug): +def create_zip(paths, zip_slug, file_contents=None): """ Creates a zip in MEDIA_ROOT/zip directory containing files from path. Resulting archive filename is ${zip_slug}.zip @@ -121,6 +121,9 @@ def create_zip(paths, zip_slug): if arcname is None: arcname = path.basename(p) zipf.write(p, arcname) + if file_contents: + for arcname, content in file_contents.items(): + zipf.writestr(arcname, content) finally: zipf.close() @@ -197,7 +200,7 @@ def truncate_html_words(s, num, end_text='...'): This is just a version of django.utils.text.truncate_html_words with no space before the end_text. """ - s = force_text(s) + s = force_str(s) length = int(num) if length <= 0: return ''