Skip to content

Commit

Permalink
Fix media update (#1000) (#1003)
Browse files Browse the repository at this point in the history
* Fix media update

* Try to restore the correct media path

---------

Co-authored-by: wlorenzetti <[email protected]>
(cherry picked from commit 4af4f36)

Co-authored-by: Walter Lorenzetti <[email protected]>
  • Loading branch information
github-actions[bot] and wlorenzetti authored Dec 23, 2024
1 parent d7c4904 commit 5c0de56
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions g3w-admin/core/utils/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ def get_domain(self):
else:
return '{}://{}'.format(schema, self.request.get_host())

def _new_path(self, file_name):
""" Build new path to save media file """

return reverse('user-media', kwargs={
'project_type': self.type,
'layer_id': self.layer.pk,
'file_name': file_name
})

def new_value(self, change=False):
""" Build and save media value from client """

Expand Down Expand Up @@ -162,11 +171,17 @@ def new_value(self, change=False):
# build new value

self.feature_properties[field] = '{}{}'.format(self.get_domain(),
reverse('user-media', kwargs={
'project_type': self.type,
'layer_id': self.layer.pk,
'file_name': file_name
}))
self._new_path(file_name))
else:
if is_media_view:

value = current_field_value
# Try to fix old record saved with temp_uploads path
if os.path.exists(path_file_to_save):
value = self._new_path(file_name)

# Restore to current_feature value
self.feature_properties[field] = value

if delete_old:
to_delete = '{}/{}'.format(path_to_save, current_file_name)
Expand Down

0 comments on commit 5c0de56

Please sign in to comment.