diff --git a/viewer/serializers.py b/viewer/serializers.py index d37d5ca2..19fd2930 100644 --- a/viewer/serializers.py +++ b/viewer/serializers.py @@ -53,20 +53,27 @@ def get_template_protein(self, obj): def get_zip_archive(self, obj): request = self.context["request"] # This is to map links to HTTPS to avoid Mixed Content warnings from Chrome browsers - # SECURE_PROXY_SSL_HEADER is referenced because it is used in redirecting URLs - if it is changed - # it make affect this code. - # Using relative links will probably also work, but This workaround allows both the 'download structures' - # button and the DRF API call to work. + # SECURE_PROXY_SSL_HEADER is referenced because it is used in redirecting URLs - if + # it is changed it may affect this code. + # Using relative links will probably also work, but This workaround allows both the + # 'download structures' button and the DRF API call to work. + # The if-check is because the filefield in target has null=True. # Note that this link will not work on local - https_host = settings.SECURE_PROXY_SSL_HEADER[1]+'://'+request.get_host() - return urljoin(https_host, obj.zip_archive.url) + https_host = settings.SECURE_PROXY_SSL_HEADER[1] + '://' + request.get_host() + if hasattr(obj, 'zip_archive') and obj.zip_archive.name: + return urljoin(https_host, obj.zip_archive.url) + else: + return def get_metadata(self, obj): request = self.context["request"] # This is to map links to HTTPS to avoid Mixed Content warnings from Chrome browsers - # Note that this link will not work on local - see above. - https_host = settings.SECURE_PROXY_SSL_HEADER[1]+'://'+request.get_host() - return urljoin(https_host, obj.metadata.url) + # See above for details. + https_host = settings.SECURE_PROXY_SSL_HEADER[1] + '://' + request.get_host() + if hasattr(obj, 'metadata') and obj.metadata.name: + return urljoin(https_host, obj.metadata.url) + else: + return class Meta: model = Target @@ -458,4 +465,4 @@ def get_text_scores(self, obj): # desc_dict = {} # for desc in descriptions: # desc_dict[desc.name] = desc.description - # return desc_dict \ No newline at end of file + # return desc_dict