Skip to content

Commit

Permalink
Store filename returned by storage API
Browse files Browse the repository at this point in the history
According to the Django docs, the storage system can change the filename to get a unique name.
The actual name of the file stored is returned by `storage.save`, and we should use that name
to update our Link object
  • Loading branch information
srto committed Jun 6, 2019
1 parent 488882e commit 0ac6ec3
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions geonode/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import traceback

from pyproj import transform, Proj
from urlparse import urljoin, urlsplit
from urlparse import urlsplit

from django.db import models
from django.core import serializers
Expand Down Expand Up @@ -1133,7 +1133,6 @@ def has_thumbnail(self):
# Note - you should probably broadcast layer#post_save() events to ensure
# that indexing (or other listeners) are notified
def save_thumbnail(self, filename, image):
upload_to = 'thumbs/'
upload_path = os.path.join('thumbs/', filename)

try:
Expand All @@ -1143,9 +1142,8 @@ def save_thumbnail(self, filename, image):
# will create a new file with a unique name
storage.delete(os.path.join(upload_path))

storage.save(upload_path, ContentFile(image))

url = storage.url(upload_path)
actual_name = storage.save(upload_path, ContentFile(image))
url = storage.url(actual_name)

# should only have one 'Thumbnail' link
obj, created = Link.objects.get_or_create(resource=self,
Expand Down

0 comments on commit 0ac6ec3

Please sign in to comment.