Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PB-1210: Set default file path for assets - #patch #476

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/stac_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,19 @@ def filename(self):
def __str__(self):
return self.name

def get_asset_path(self):
# Method must be implemented by Asset and CollectionAsset separately.
raise NotImplementedError("get_asset_path() not implemented")

def save(self, *args, **kwargs):
# Default file value to the asset path.
#
# This is the behaviour when creating an asset via PUT API endpoint.
# But we need to set this here so it also applies in the admin UI.
if not bool(self.file):
self.file = self.get_asset_path()
super().save(*args, **kwargs)

def delete(self, *args, **kwargs): # pylint: disable=signature-differs
try:
super().delete(*args, **kwargs)
Expand Down
3 changes: 3 additions & 0 deletions app/tests/test_admin_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ def _create_asset(self, item, extra=None):
Asset.objects.filter(item=item, name=data["name"]).exists(),
msg="Admin page asset added not found in DB"
)
asset = Asset.objects.get(item=item, name=data["name"])
# Assert that the filename is set to the value in name
self.assertEqual(asset.filename, data['name'])

data = {
"item": item.id,
Expand Down