mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
Better to use os.path.join for paths
This commit is contained in:
@ -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)
|
||||
|
@ -21,11 +21,12 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<link rel="prefetch" href="{{ url("sas:picture", picture_id=picture.get_previous().id} }}"> <!-- Firefox -->
|
||||
<link rel="prerender" href="{{ url("sas:picture", picture_id=picture.get_previous().id }}"> <!-- Chrome -->
|
||||
|
||||
<link rel="prefetch" href="{{ url("sas:picture", picture_id=picture.get_next().id} }}"> <!-- Firefox -->
|
||||
<link rel="prerender" href="{{ url("sas:picture", picture_id=picture.get_next().id }}"> <!-- Chrome -->
|
||||
{% 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 %}
|
||||
|
||||
|
Reference in New Issue
Block a user