Better to use os.path.join for paths

This commit is contained in:
2017-03-30 19:13:47 +02:00
parent 1f844da005
commit 60e2e0d4f9
4 changed files with 16 additions and 11 deletions

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)