Skip to content

Commit

Permalink
update get_object_link() return data (#1922)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Sep 5, 2024
1 parent fd30429 commit 5b22616
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 42 deletions.
20 changes: 12 additions & 8 deletions isatemplates/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from django.urls import reverse

# Projectroles dependency
from projectroles.plugins import SiteAppPluginPoint, BackendPluginPoint
from projectroles.plugins import (
SiteAppPluginPoint,
BackendPluginPoint,
PluginObjectLink,
)

from isatemplates.api import ISATemplateAPI
from isatemplates.models import CookiecutterISATemplate
Expand Down Expand Up @@ -43,24 +47,24 @@ class SiteAppPlugin(SiteAppPluginPoint):

def get_object_link(self, model_str, uuid):
"""
Return URL for referring to a object used by the app, along with a
label to be shown to the user for linking.
Return URL referring to an object used by the app, along with a name to
be shown to the user for linking.
:param model_str: Object class (string)
:param uuid: sodar_uuid of the referred object
:return: Dict or None if not found
:return: PluginObjectLink or None if not found
"""
obj = self.get_object(eval(model_str), uuid)
if not obj:
return None
if obj.__class__ == CookiecutterISATemplate:
return {
'url': reverse(
return PluginObjectLink(
url=reverse(
'isatemplates:detail',
kwargs={'cookiecutterisatemplate': obj.sodar_uuid},
),
'label': obj.description,
}
name=obj.description,
)

def get_statistics(self):
"""
Expand Down
24 changes: 12 additions & 12 deletions landingzones/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from projectroles.plugins import (
ProjectAppPluginPoint,
ProjectModifyPluginMixin,
PluginObjectLink,
get_backend_api,
)

Expand Down Expand Up @@ -123,31 +124,30 @@ class ProjectAppPlugin(

def get_object_link(self, model_str, uuid):
"""
Return URL for referring to a object used by the app, along with a
label to be shown to the user for linking.
Return URL referring to an object used by the app, along with a name to
be shown to the user for linking.
:param model_str: Object class (string)
:param uuid: sodar_uuid of the referred object
:return: Dict or None if not found
:return: PluginObjectLink or None if not found
"""
obj = self.get_object(eval(model_str), uuid)
if not obj:
return None
if obj.__class__ == LandingZone and obj.status != ZONE_STATUS_MOVED:
return {
'url': reverse(
return PluginObjectLink(
url=reverse(
'landingzones:list',
kwargs={'project': obj.project.sodar_uuid},
)
+ '#'
+ str(obj.sodar_uuid),
'label': obj.title,
}
elif obj.__class__ == Assay:
return {
'url': obj.get_url(),
'label': obj.get_display_name(),
}
name=obj.title,
)
if obj.__class__ == Assay:
return PluginObjectLink(
url=obj.get_url(), name=obj.get_display_name()
)

def get_statistics(self):
"""
Expand Down
43 changes: 21 additions & 22 deletions samplesheets/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from projectroles.plugins import (
ProjectAppPluginPoint,
ProjectModifyPluginMixin,
PluginObjectLink,
get_backend_api,
)
from projectroles.utils import build_secret
Expand Down Expand Up @@ -300,46 +301,44 @@ class ProjectAppPlugin(

def get_object_link(self, model_str, uuid):
"""
Return URL for referring to a object used by the app, along with a
label to be shown to the user for linking.
Return URL referring to an object used by the app, along with a name to
be shown to the user for linking.
:param model_str: Object class (string)
:param uuid: sodar_uuid of the referred object
:return: Dict or None if not found
:return: PluginObjectLink or None if not found
"""
obj = self.get_object(eval(model_str), uuid)
if not obj:
return None
if obj.__class__ == IrodsAccessTicket:
return {
'url': reverse(
return PluginObjectLink(
url=reverse(
'samplesheets:irods_tickets',
kwargs={'project': obj.get_project().sodar_uuid},
),
'label': obj.get_display_name(),
}
name=obj.get_display_name(),
)
if obj.__class__ in [Investigation, Study, Assay]:
return {
'url': obj.get_url(),
'label': (
return PluginObjectLink(
url=obj.get_url(),
name=(
obj.title
if obj.__class__ == Investigation
else obj.get_display_name()
),
}
)
url_kwargs = {'project': obj.project.sodar_uuid}
if obj.__class__ == ISATab:
return {
'url': reverse('samplesheets:versions', kwargs=url_kwargs),
'label': obj.get_full_name(),
}
elif obj.__class__ == IrodsDataRequest:
return {
'url': reverse(
'samplesheets:irods_requests', kwargs=url_kwargs
),
'label': obj.get_display_name(),
}
return PluginObjectLink(
url=reverse('samplesheets:versions', kwargs=url_kwargs),
name=obj.get_full_name(),
)
if obj.__class__ == IrodsDataRequest:
return PluginObjectLink(
url=reverse('samplesheets:versions', kwargs=url_kwargs),
name=obj.get_full_name(),
)

@classmethod
def _get_search_materials(cls, search_terms, user, keywords, item_types):
Expand Down

0 comments on commit 5b22616

Please sign in to comment.