Skip to content

Commit

Permalink
update timeline object ref empty name handling (#1341)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Nov 23, 2023
1 parent 2771b43 commit 98e84d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Added
- User login/logout logging signals (#1326)
- ``createdevusers`` management command (#1339)
- **Timeline**
- Empty object reference name handling in ``add_object()`` (#1338)
- Empty object reference name handling in ``add_object()`` (#1338, #1341)

Changed
-------
Expand Down
22 changes: 16 additions & 6 deletions timeline/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ProjectEvent,
ProjectEventObjectRef,
EVENT_STATUS_TYPES,
OBJ_REF_UNNAMED,
)


Expand All @@ -38,8 +39,10 @@ class TimelineAPI:
# Internal Helpers ---------------------------------------------------------

@classmethod
def _get_label(cls, label):
"""Format label to be displayed"""
def _get_ref_label(cls, label):
"""Return reference object name in displayable form"""
if not label:
return OBJ_REF_UNNAMED
if not {' ', '-'}.intersection(label):
return Truncator(label).chars(LABEL_MAX_WIDTH)
return label
Expand Down Expand Up @@ -68,7 +71,7 @@ def _get_history_link(cls, ref_obj):
def _get_not_found_label(cls, ref_obj):
"""Get label for object which is not found in the database"""
return '<span class="text-danger">{}</span> {}'.format(
cls._get_label(ref_obj.name), cls._get_history_link(ref_obj)
cls._get_ref_label(ref_obj.name), cls._get_history_link(ref_obj)
)

@classmethod
Expand All @@ -85,11 +88,11 @@ def _get_project_desc(cls, ref_obj, request=None):
'projectroles:detail',
kwargs={'project': project.sodar_uuid},
),
cls._get_label(project.title),
cls._get_ref_label(project.title),
)
elif project:
return '<span class="text-danger">{}</span>'.format(
cls._get_label(project.title)
cls._get_ref_label(project.title)
)
return ref_obj.name

Expand Down Expand Up @@ -173,14 +176,21 @@ def _get_ref_description(cls, event, ref_label, app_plugin, request):
raise ex
link_data = None
if link_data:
if not link_data['label']:
logger.warning(
'Empty label returned by plugin "{}" for object '
'reference "{}" ({})"'.format(
app_plugin.name, ref_obj, ref_obj.sodar_uuid
)
)
return '<a href="{}" {}>{}</a> {}'.format(
link_data['url'],
(
'target="_blank"'
if 'blank' in link_data and link_data['blank'] is True
else ''
),
cls._get_label(link_data['label']),
cls._get_ref_label(link_data['label']),
cls._get_history_link(ref_obj),
)
else:
Expand Down
4 changes: 2 additions & 2 deletions timeline/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'INFO': 'Info level action',
'CANCEL': 'Action cancelled',
}
OBJ_REF_UNNAMED = '(Unnamed)'
OBJ_REF_UNNAMED = '(unnamed)'


class ProjectEventManager(models.Manager):
Expand Down Expand Up @@ -187,7 +187,7 @@ def add_object(self, obj, label, name, extra_data=None):
ref.label = label
if not name:
logger.warning(
'Adding object reference with no name: {} ({})'.format(
'Adding object reference with no name: "{}" ({})'.format(
obj, getattr(obj, 'sodar_uuid')
)
)
Expand Down

0 comments on commit 98e84d1

Please sign in to comment.