Skip to content

Commit

Permalink
fix: DEV-2687: Display source filename for S3 objects (HumanSignal#2555)
Browse files Browse the repository at this point in the history
* fix: DEV-2687: Display source filename for S3 objects

* Move storage filename to separate field (DEV-2687)
  • Loading branch information
triklozoid authored Jul 5, 2022
1 parent fb62892 commit 8b693b9
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
8 changes: 8 additions & 0 deletions label_studio/core/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@
USE_ENFORCE_CSRF_CHECKS = get_bool_env('USE_ENFORCE_CSRF_CHECKS', True) # False is for tests
CLOUD_FILE_STORAGE_ENABLED = False

IO_STORAGES_IMPORT_LINK_NAMES = [
'io_storages_s3importstoragelink',
'io_storages_gcsimportstoragelink',
'io_storages_azureblobimportstoragelink',
'io_storages_localfilesimportstoragelink',
'io_storages_redisimportstoragelink',
]

CREATE_ORGANIZATION = 'organizations.functions.create_organization'
GET_OBJECT_WITH_CHECK_AND_LOG = 'core.utils.get_object.get_object_with_check_and_log'
SAVE_USER = 'users.functions.save_user'
Expand Down
15 changes: 13 additions & 2 deletions label_studio/data_manager/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,21 @@ def get_all_columns(project, *_):
},
{
'id': 'file_upload',
'title': "Source filename",
'title': "Upload filename",
'type': "String",
'target': 'tasks',
'help': 'Source filename from import step',
'help': 'Filename of uploaded file',
'visibility_defaults': {
'explore': False,
'labeling': False
}
},
{
'id': 'storage_filename',
'title': "Storage filename",
'type': "String",
'target': 'tasks',
'help': 'Filename from import storage',
'visibility_defaults': {
'explore': False,
'labeling': False
Expand Down
13 changes: 9 additions & 4 deletions label_studio/data_manager/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ class DataManagerTaskSerializer(TaskSerializer):
predictions_results = serializers.SerializerMethodField(required=False)
predictions_score = serializers.FloatField(required=False)
file_upload = serializers.SerializerMethodField(required=False)
storage_filename = serializers.SerializerMethodField(required=False)
annotations_ids = serializers.SerializerMethodField(required=False)
predictions_model_versions = serializers.SerializerMethodField(required=False)
avg_lead_time = serializers.FloatField(required=False)
Expand Down Expand Up @@ -232,10 +233,14 @@ def get_predictions(self, task):

@staticmethod
def get_file_upload(task):
if not hasattr(task, 'file_upload_field'):
return None
file_upload = task.file_upload_field
return os.path.basename(task.file_upload_field) if file_upload else None
if hasattr(task, 'file_upload_field'):
file_upload = task.file_upload_field
return os.path.basename(task.file_upload_field) if file_upload else None
return None

@staticmethod
def get_storage_filename(task):
return task.storage_filename

@staticmethod
def get_updated_by(obj):
Expand Down
6 changes: 6 additions & 0 deletions label_studio/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def has_lock(self, user=None):
def num_locks(self):
return self.locks.filter(expire_at__gt=now()).count()

@property
def storage_filename(self):
for link_name in settings.IO_STORAGES_IMPORT_LINK_NAMES:
if hasattr(self, link_name):
return getattr(self, link_name).key

def get_lock_ttl(self):
if settings.TASK_LOCK_TTL is not None:
return settings.TASK_LOCK_TTL
Expand Down
2 changes: 1 addition & 1 deletion label_studio/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_delete_annotations(business_client, configured_project):
'overlap': 1, 'file_upload': None, 'annotations_ids': '', 'annotations_results': '',
'annotators': [], 'completed_at': None, 'predictions_model_versions': '',
'predictions_results': '', 'predictions_score': None, 'total_annotations': 0, 'total_predictions': 0,
'avg_lead_time': None, 'cancelled_annotations': 0, 'inner_id': 0},
'avg_lead_time': None, 'cancelled_annotations': 0, 'inner_id': 0,'storage_filename': None},
200
)
])
Expand Down

0 comments on commit 8b693b9

Please sign in to comment.