Merge branch 'sas' into 'master'

Fixed some issues with filepaths and see the future with some preload

See merge request !59
This commit is contained in:
Skia 2017-03-31 11:34:10 +02:00
commit 231922cbaa
4 changed files with 18 additions and 6 deletions

View File

@ -12,6 +12,8 @@ from django.contrib.staticfiles.storage import staticfiles_storage
from django.utils.html import escape
from django.utils.functional import cached_property
import os
from phonenumber_field.modelfields import PhoneNumberField
from datetime import datetime, timedelta, date
@ -664,10 +666,10 @@ class SithFile(models.Model):
if self.is_folder:
for c in self.children.all():
c.move_to(self)
shutil.rmtree(settings.MEDIA_ROOT + old_file_name)
shutil.rmtree(os.path.join(settings.MEDIA_ROOT, old_file_name))
else:
self.file.save(name=self.name, content=self.file)
os.remove(settings.MEDIA_ROOT + old_file_name)
os.remove(os.path.join(settings.MEDIA_ROOT, old_file_name))
def __getattribute__(self, attr):
if attr == "is_file":

View File

@ -38,10 +38,11 @@ def send_file(request, file_id, file_class=SithFile, file_attr="file"):
):
raise PermissionDenied
name = f.__getattribute__(file_attr).name
with open((settings.MEDIA_ROOT + name).encode('utf-8'), 'rb') as filename:
filepath = os.path.join(settings.MEDIA_ROOT, name)
with open(filepath.encode('utf-8'), 'rb') as filename:
wrapper = FileWrapper(filename)
response = HttpResponse(wrapper, content_type=f.mime_type)
response['Content-Length'] = os.path.getsize((settings.MEDIA_ROOT + name).encode('utf-8'))
response['Content-Length'] = os.path.getsize(filepath.encode('utf-8'))
response['Content-Disposition'] = ('inline; filename="%s"' % f.name).encode('utf-8')
return response

View File

@ -7,6 +7,7 @@ from django.core.files.base import ContentFile
from PIL import Image
from io import BytesIO
import os
from core.models import SithFile, User
from core.utils import resize_image, exif_auto_rotate
@ -17,7 +18,7 @@ class Picture(SithFile):
@property
def is_vertical(self):
with open((settings.MEDIA_ROOT + self.file.name).encode('utf-8'), 'rb') as f:
with open(os.path.join(settings.MEDIA_ROOT, self.file.name).encode('utf-8'), 'rb') as f:
im = Image.open(BytesIO(f.read()))
(w, h) = im.size
return (w / h) < 1
@ -67,7 +68,7 @@ class Picture(SithFile):
def rotate(self, degree):
for attr in ['file', 'compressed', 'thumbnail']:
name = self.__getattribute__(attr).name
with open((settings.MEDIA_ROOT + name).encode('utf-8'), 'r+b') as file:
with open(os.path.join(settings.MEDIA_ROOT, name).encode('utf-8'), 'r+b') as file:
if file:
im = Image.open(BytesIO(file.read()))
file.seek(0)

View File

@ -20,6 +20,14 @@
max-width: 100%;
}
</style>
{% if picture.get_previous() %}
<link rel="preload" as="image" href="{{ url("sas:download_compressed", picture_id=picture.get_previous().id) }}">
{% endif %}
{% if picture.get_next() %}
<link rel="preload" as="image" href="{{ url("sas:download_compressed", picture_id=picture.get_next().id) }}">
{% endif %}
{% endblock %}
{% block title %}