diff --git a/portal/views/secure/datafile.py b/portal/views/secure/datafile.py index 2130f27954b0dd8fbfbe6920b84ee417c9f71f31..bb6738283c524f90112206a17bc344c7e621deed 100644 --- a/portal/views/secure/datafile.py +++ b/portal/views/secure/datafile.py @@ -102,8 +102,18 @@ class DataFilesJSONListView(LoginRequiredMixin, JSONListView): def get_rows(self): rows = [] - objs = self.get_queryset().annotate(ds_count=Count('datasets'), ds_names=ArrayAgg('datasets__name')) + current_timezone = timezone.get_current_timezone() ds_token = ugettext('DataSets') + dwnl_token = ugettext('Download File') + annot_token = ugettext('Download Annotation') + view_token = ugettext('View details') + edit_token = ugettext('Edit') + delete_token = ugettext('Delete') + + pi_or_manager = False + if self.request.user.profile.is_pi_or_data_manager: + pi_or_manager = True + objs = self.get_queryset().annotate( ds_count=Count('datasets'), @@ -115,33 +125,30 @@ class DataFilesJSONListView(LoginRequiredMixin, JSONListView): ) ).values( 'id', 'filename', 'filesize', 'iric_data_id', 'upload_timestamp', - 'file', 'lab__name', 'ds_count', 'ds_names' ,'uploaded_by_fullname' + 'file', 'lab__name', 'ds_count', 'ds_names', 'uploaded_by_fullname' ) - ds_token = ugettext('DataSets') - dwnl_token = ugettext('Download File') - annot_token = ugettext('Download Annotation') - view_token = ugettext('View details') - edit_token = ugettext('Edit') - delete_token = ugettext('Delete') for o in objs: ds_str = '' - if o['ds_count'] > 0 : - ds_str = ', '.join(o['ds_names']) + if o['ds_count']: if o['ds_count'] > 1: ds_str = '<span title="{0}">{1} {2}</span>'.format(ds_str, o['ds_count'], ds_token) + else: + ds_str = ', '.join(o['ds_names']) row = { 'id': o['id'], 'sel': '', 'name': '<a href="{0}" class="details" title="{2}">{1}</a>'.format( reverse('user.datafile-details-iric-data-id', args=[o['iric_data_id']]), - o['filename'], view_token), + o['filename'], + view_token + ), 'ext': os.path.splitext(o['filename'])[-1][1:].upper(), 'iric_data_id': '<span class="text-monospace">{}</span>'.format(o['iric_data_id']), 'hash': '<span class="text-monospace">{}</span>'.format(o['file'][4:12]), 'size': '' if o['filesize'] is None else filters.filesizeformat(o['filesize']), - 'upload_date': timezone.localtime(o['upload_timestamp']).strftime('%Y-%m-%d %H:%M:%S %Z'), + 'upload_date': o['upload_timestamp'].astimezone(current_timezone).strftime('%Y-%m-%d %H:%M:%S %Z'), 'lab': '' if o['lab__name'] is None else o['lab__name'], 'datasets': ds_str, 'action_buttons': render_to_string( @@ -154,11 +161,10 @@ class DataFilesJSONListView(LoginRequiredMixin, JSONListView): ]}) } - if self.request.user.profile.is_pi_or_data_manager: + if pi_or_manager: row.update({'uploaded_by': o['uploaded_by_fullname']}) rows.append(row) - return rows @@ -174,7 +180,12 @@ class SharedWithMeDataFilesJSONListView(LoginRequiredMixin, JSONListView): def get_rows(self): rows = [] - + current_timezone = timezone.get_current_timezone() + ds_token = ugettext('DataSets') + dwnl_token = ugettext('Download File') + annot_token = ugettext('Download Annotation') + view_token = ugettext('View details') + objs = self.get_queryset().annotate( ds_count=Count('datasets'), ds_names=ArrayAgg('datasets__name'), @@ -188,17 +199,13 @@ class SharedWithMeDataFilesJSONListView(LoginRequiredMixin, JSONListView): 'file', 'lab__name', 'ds_count', 'ds_names', 'uploaded_by_fullname' ) - ds_token = ugettext('DataSets') - dwnl_token = ugettext('Download File') - annot_token = ugettext('Download Annotation') - view_token = ugettext('View details') - for o in objs: ds_str = '' - if o['ds_count'] > 0 : - ds_str = ', '.join(o['ds_names']) + if o['ds_count']: if o['ds_count'] > 1: ds_str = '<span title="{0}">{1} {2}</span>'.format(ds_str, o['ds_count'], ds_token) + else: + ds_str = ', '.join(o['ds_names']) row = { 'id': o['id'], @@ -210,7 +217,7 @@ class SharedWithMeDataFilesJSONListView(LoginRequiredMixin, JSONListView): 'hash': '<span class="text-monospace">{}</span>'.format(o['file'][4:12]), 'ext': os.path.splitext(o['filename'])[-1][1:].upper(), 'size': '' if o['filesize'] is None else filters.filesizeformat(o['filesize']), - 'upload_date': timezone.localtime(o['upload_timestamp']).strftime('%Y-%m-%d %H:%M:%S %Z'), + 'upload_date': o['upload_timestamp'].astimezone(current_timezone).strftime('%Y-%m-%d %H:%M:%S %Z'), 'datasets': ds_str, 'uploaded_by': o['uploaded_by_fullname'], 'lab': '' if o['lab__name'] is None else o['lab__name'],