diff --git a/isatemplates/plugins.py b/isatemplates/plugins.py index 0f012cd4..a0cc4eb4 100644 --- a/isatemplates/plugins.py +++ b/isatemplates/plugins.py @@ -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 @@ -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): """ diff --git a/landingzones/plugins.py b/landingzones/plugins.py index 1c0e5e01..482a2e5e 100644 --- a/landingzones/plugins.py +++ b/landingzones/plugins.py @@ -11,6 +11,7 @@ from projectroles.plugins import ( ProjectAppPluginPoint, ProjectModifyPluginMixin, + PluginObjectLink, get_backend_api, ) @@ -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): """ diff --git a/samplesheets/plugins.py b/samplesheets/plugins.py index 52baed0f..4f55f177 100644 --- a/samplesheets/plugins.py +++ b/samplesheets/plugins.py @@ -20,6 +20,7 @@ from projectroles.plugins import ( ProjectAppPluginPoint, ProjectModifyPluginMixin, + PluginObjectLink, get_backend_api, ) from projectroles.utils import build_secret @@ -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):