fnp
/
wolnelektury.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add basic login.
[wolnelektury.git]
/
src
/
catalogue
/
utils.py
diff --git
a/src/catalogue/utils.py
b/src/catalogue/utils.py
index
ca8ec0d
..
267d6be
100644
(file)
--- a/
src/catalogue/utils.py
+++ b/
src/catalogue/utils.py
@@
-1,5
+1,5
@@
-# This file is part of Wolne
l
ektury, licensed under GNU Affero GPLv3 or later.
-# Copyright © Fundacja
Nowoczesna Polska
. See NOTICE for more information.
+# This file is part of Wolne
L
ektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja
Wolne Lektury
. See NOTICE for more information.
#
import hashlib
import os.path
#
import hashlib
import os.path
@@
-11,13
+11,15
@@
from collections import defaultdict
from errno import EEXIST, ENOENT
from fcntl import flock, LOCK_EX
from os import mkdir, path, unlink
from errno import EEXIST, ENOENT
from fcntl import flock, LOCK_EX
from os import mkdir, path, unlink
+from urllib.parse import urljoin
from zipfile import ZipFile
from zipfile import ZipFile
+from django.apps import apps
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.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
from reporting.utils import read_chunks
@@
-95,7
+97,7
@@
class LockFile(object):
# @task
# @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
"""
Creates a zip in MEDIA_ROOT/zip directory containing files from path.
Resulting archive filename is ${zip_slug}.zip
@@
-119,6
+121,9
@@
def create_zip(paths, zip_slug):
if arcname is None:
arcname = path.basename(p)
zipf.write(p, arcname)
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()
finally:
zipf.close()
@@
-195,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.
"""
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 ''
length = int(num)
if length <= 0:
return ''
@@
-310,6
+315,16
@@
def gallery_url(slug):
return '%s%s%s/' % (settings.MEDIA_URL, settings.IMAGE_DIR, slug)
return '%s%s%s/' % (settings.MEDIA_URL, settings.IMAGE_DIR, slug)
+def absolute_url(url):
+ Site = apps.get_model('sites', 'Site')
+ site = Site.objects.get_current()
+ base_url = '%s://%s' % (
+ 'https' if settings.SESSION_COOKIE_SECURE else 'http',
+ site.domain
+ )
+ return urljoin(base_url, url)
+
+
def get_mp3_length(path):
from mutagen.mp3 import MP3
return int(MP3(path).info.length)
def get_mp3_length(path):
from mutagen.mp3 import MP3
return int(MP3(path).info.length)