-# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+# This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
#
import hashlib
import os.path
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
# @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
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()
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 ''