diff --git a/core/models.py b/core/models.py index 44d8a62e..2c6a6f5a 100644 --- a/core/models.py +++ b/core/models.py @@ -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": diff --git a/core/views/files.py b/core/views/files.py index 0d4179bb..f8a49f27 100644 --- a/core/views/files.py +++ b/core/views/files.py @@ -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 diff --git a/sas/models.py b/sas/models.py index 2abcce9f..b12adeb0 100644 --- a/sas/models.py +++ b/sas/models.py @@ -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) diff --git a/sas/templates/sas/picture.jinja b/sas/templates/sas/picture.jinja index f634cae2..68253ea4 100644 --- a/sas/templates/sas/picture.jinja +++ b/sas/templates/sas/picture.jinja @@ -20,6 +20,14 @@ max-width: 100%; } + +{% if picture.get_previous() %} + +{% endif %} +{% if picture.get_next() %} + +{% endif %} + {% endblock %} {% block title %}