Compare commits

..

No commits in common. "21217b067fd17cd0b3c78791904e93b9f943dd19" and "b0e775d299c55ed820745f0b486eae255f9155a8" have entirely different histories.

3 changed files with 6 additions and 17 deletions

View File

@ -131,15 +131,9 @@ USE_TZ = True
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
# Upload directory
MEDIA_URL = '/uploads/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'uploads')
# Thumbnails
THUMBNAIL_MEDIA_ROOT = os.path.join(MEDIA_ROOT, 'thumbs/')
THUMBNAIL_MEDIA_URL = os.path.join(MEDIA_URL, 'thumbs/')
THUMBNAIL_QUALITY = 75
# Templates to use for authentication
LOGIN_URL = reverse_lazy('login')
LOGIN_REDIRECT_URL = reverse_lazy('lostplaces_home')

View File

@ -4,8 +4,8 @@ from django.conf import settings
settings.THUMBNAIL_ALIASES = {
'': {
'thumbnail': {'size': (300, 200), 'sharpen': True, 'crop': True},
'hero': {'size': (700, 466), 'sharpen': True, 'crop': True},
'large': {'size': (1920, 1920), 'sharpen': True, 'crop': False},
'thumbnail': {'size': (300, 200), 'crop': True},
'hero': {'size': (700, 466), 'crop': True},
'large': {'size': (1920, 1920), 'crop': False},
},
}

View File

@ -144,25 +144,20 @@ class Place(Submittable, Taggable, Mapable):
def generate_image_upload_path(instance, filename):
"""
Callback for generating path for uploaded images.
Returns filename as: placepk-placename{-rndstring}.jpg
"""
return 'places/' + str(instance.place.pk) + '-' + str(instance.place.name) + '.' + filename.split('.')[-1]
return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1]
class PlaceImage (Submittable):
"""
PlaceImage defines an image file object that points to a file in uploads/.
Intermediate image sizes are generated as defined in THUMBNAIL_ALIASES.
Intermediate image sizes are generated as defined in SIZES.
PlaceImage references a Place to which it belongs.
"""
description = models.TextField(blank=True)
filename = ThumbnailerImageField(
upload_to=generate_image_upload_path,
resize_source=dict(size=(2560, 2560),
sharpen=True)
)
filename = ThumbnailerImageField(upload_to=generate_image_upload_path)
place = models.ForeignKey(
Place,
on_delete=models.CASCADE,