Skip to content

Commit

Permalink
Add changes discussed in CR
Browse files Browse the repository at this point in the history
  • Loading branch information
scottx611x committed Apr 28, 2016
1 parent 8409550 commit 561ef26
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
26 changes: 3 additions & 23 deletions refinery/file_store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from django.db.models.signals import pre_delete
from django_extensions.db.fields import UUIDField
from django.core.files.storage import FileSystemStorage
from django.contrib.sites.models import Site

logger = logging.getLogger('file_store')

Expand Down Expand Up @@ -496,31 +495,12 @@ def symlink_datafile(self):
logger.error("Symlinking failed: source is not a file")
return False

def get_datafile_url(self, full_url=False):
"""Return the full URL (including hostname) for the datafile if
full_url param is True. Otherwise we only want the relative url to
the datafile.
:param full_url: if set to True, the full_url to the datafile will
be fetched
def get_datafile_url(self):
"""Return the relative URL for a datafile.
:returns: str -- local URL or source if it's a remote file
"""
if self.is_local():
if full_url:
try:
current_site = Site.objects.get_current()
except Site.DoesNotExist:
logger.error(
"Cannot provide a full URL: no sites configured or "
"SITE_ID is not set correctly")
return None
# FIXME: provide a URL without the domain portion
# visualization_manager.views may be expecting a full URL
return 'http://{}{}'.format(current_site.domain,
self.datafile.url)
else:
return self.datafile.url
return self.datafile.url
else:
# data file doesn't exist on disk
if os.path.isabs(self.source):
Expand Down
25 changes: 21 additions & 4 deletions refinery/visualization_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tempfile
from xml.dom.minidom import Document

from django.contrib.sites.models import Site
from django.shortcuts import redirect

from annotation_server.models import taxon_id_to_genome_build, \
Expand Down Expand Up @@ -54,6 +55,22 @@ def profile_viewer_session(request):
end_location=200000000, sequence_name="chr1")


def get_full_url(filestore_item):
""" return the full url (including hostname) of a FileStoreItem
:param filestore_item: FileStoreItem to get url for
:type filestore_item: FileStoreItem instance.
"""
try:
current_site = Site.objects.get_current()
except Site.DoesNotExist:
logger.error(
"Cannot provide a full URL: no sites configured or "
"SITE_ID is not set correctly")
return None
return 'http://{}{}'.format(current_site.domain,
filestore_item.datafile.url)


def createIGVsession(genome, uuids, is_file_uuid=False):
""" Creates session file for selected file uuids, returns newly created
filestore uuid
Expand Down Expand Up @@ -122,7 +139,7 @@ def createIGVsession(genome, uuids, is_file_uuid=False):
# delete temp file
os.unlink(tempfilename.name)
# Url for session file
fs_url = filestore_item.get_datafile_url(full_url=True)
fs_url = get_full_url(filestore_item)
# IGV url for automatic launch of Java Webstart
igv_url = "http://www.broadinstitute.org/igv/projects/current/igv.php" \
"?sessionURL=" + fs_url
Expand Down Expand Up @@ -371,7 +388,7 @@ def createIGVsessionAnnot(genome, uuids, annot_uuids=None, samp_file=None):
os.unlink(tempfilename.name)

# Url for session file
sessionfile_url = filestore_item.get_datafile_url(full_url=True)
sessionfile_url = get_full_url(filestore_item)

# IGV url for automatic launch of Java Webstart
igv_url = "http://www.broadinstitute.org/igv/projects/current/igv.php" \
Expand Down Expand Up @@ -462,7 +479,7 @@ def addIGVSamples(fields, results_samp, annot_samples=None):
curr_fs = FileStoreItem.objects.get(uuid=filestore_uuid)

# full path to selected UUID File
curr_url = curr_fs.get_datafile_url(full_url=True)
curr_url = get_full_url(curr_fs)

# delete temp file
os.unlink(tempsampname.name)
Expand Down Expand Up @@ -494,7 +511,7 @@ def get_file_name(nodeuuid, sampFile=None, is_file_uuid=False):
temp_name = temp_name[len(temp_name) - 1]

# full path to selected UUID File
temp_url = temp_fs.get_datafile_url(full_url=True)
temp_url = get_full_url(temp_fs)

# IGV SEG FILE HACK
if sampFile:
Expand Down

0 comments on commit 561ef26

Please sign in to comment.