Skip to content

Commit

Permalink
omics/tables: Fix missing links for Globus-downloadable files for som…
Browse files Browse the repository at this point in the history
…e deployment configurations

The link display wrongly depended on the PUBLIC_DATA_ROOT setting being
set.  But it should only matter whether File.public is non-empty.  This
patch changes the File.relpublic property (and also File.relpath to
match) making those independent of any settings.  The somewhat
complicating factor is that the DB only stores the relative paths but if
OMICS_DATA_ROOT / PUBLIC_DATA_ROOT are set then mibios.umrad.PathField
will always prepend the root dir and we have to conditionally run
relative_to() to get the relative path back.

Leaving the default settings as-is even if OMICS_DATA_ROOT as ./ is not
a good choice.  The production deployment should leave both default
settings; in both cases getting back the relative paths works.

This closes #60.
  • Loading branch information
robert102 committed Dec 12, 2024
1 parent e63d40d commit 29f2c22
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions mibios/glamr/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ def order_storage_size(self, qs, is_descending):


class FileTable(OmicsFileTable):
""" List files belonging to a sample """
class Meta:
model = omics_models.File
fields = ['download_url', 'filetype', 'size', 'modtime']
Expand Down
20 changes: 14 additions & 6 deletions mibios/omics/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,12 @@ def public_root(self):
@property
def relpath(self):
""" The path relative to the common path prefix """
return self.path.relative_to(self.root)
if self.root:
return self.path.relative_to(self.root)
elif self.path.is_absolute():
raise ValueError('path is absolute abnd no root configured')
else:
return self.path

@property
def relpublic(self):
Expand All @@ -1042,12 +1047,15 @@ def relpublic(self):
This property may be exposed on a public page.
Returns None if no public path is set or if the common prefix is not
configured.
Returns None if no public path is set.
"""
if self.public_root is None or self.public is None:
return None
return self.public.relative_to(self.public_root)
if self.public_root:
return self.public.relative_to(self.public_root)
elif self.public and self.public.is_absolute():
raise ValueError('public path is absolute and no root configured')
else:
# is a rel path or None
return self.public

def compute_public_path(self):
"""
Expand Down
5 changes: 2 additions & 3 deletions mibios/omics/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,8 @@ def get_db_settings(db_dir='.', db_infix=''):
""" root Globus url for file app, publicly shared directory """

PUBLIC_DATA_ROOT = None
""" path to publicly accessible directory on staging server, this needs to be
set even on other deployments so that relative paths to the public files can be
computed """
""" path to root of publicly accessible directory tree on staging server, leave
at None on other deployments """

OMICS_CHECKOUT_FILE = None
""" path to the file checkout listing """
14 changes: 7 additions & 7 deletions mibios/omics/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class Meta:

def render_download_url(self, value, record):
if record.public:
path = record.public.relative_to(File.get_public_prefix())
if value:
return format_html('<a href="{}">{}</a>', value, path)
else:
return f'{path} (unavailable)'
path = record.relpublic
else:
path = record.path.relative_to(File.get_path_prefix())
return str(path)
path = record.relpath

if value:
return format_html('<a href="{}">{}</a>', value, path)
else:
return f'{"" if record.public else "*"}{path}'

def order_download_url(self, queryset, is_descending):
qs = queryset.annotate(path0=Coalesce('public', 'path'))
Expand Down

0 comments on commit 29f2c22

Please sign in to comment.