From 23248951f3871d413ef42cefc152bfdb8b07d512 Mon Sep 17 00:00:00 2001 From: Daniel-VM Date: Tue, 17 Dec 2024 19:12:24 +0100 Subject: [PATCH] fix black linting --- core/admin.py | 8 +++++++- core/api/utils/common_functions.py | 7 ++++--- core/api/utils/metadata_values.py | 15 ++++++-------- core/api/views.py | 32 ++++++++++++++++++++---------- core/models.py | 10 ++++------ 5 files changed, 42 insertions(+), 30 deletions(-) diff --git a/core/admin.py b/core/admin.py index b69bb871..b79fb318 100644 --- a/core/admin.py +++ b/core/admin.py @@ -47,7 +47,13 @@ class ConfigSettingAdmin(admin.ModelAdmin): class SampleStateHistoryAdmin(admin.ModelAdmin): - list_display = ["is_current", custom_date_format, "sample_id", "state_id", "error_name_id"] + list_display = [ + "is_current", + custom_date_format, + "sample_id", + "state_id", + "error_name_id", + ] class EffectAdmin(admin.ModelAdmin): diff --git a/core/api/utils/common_functions.py b/core/api/utils/common_functions.py index b8f1d0eb..d624addf 100644 --- a/core/api/utils/common_functions.py +++ b/core/api/utils/common_functions.py @@ -75,12 +75,13 @@ def add_sample_state_history(sample_obj, state_id, error_name=None): # Assign the 'No Error' entry with pk=1 as default error_obj = core.models.ErrorName.objects.filter(pk=1).first() if not error_obj: - raise ValueError("Default error entry with pk=1 does not exist in the database.") + raise ValueError( + "Default error entry with pk=1 does not exist in the database." + ) # Mark previous states as not current core.models.SampleStateHistory.objects.filter( - sample=sample_obj, - is_current=True + sample=sample_obj, is_current=True ).update(is_current=False) # Add the new state history diff --git a/core/api/utils/metadata_values.py b/core/api/utils/metadata_values.py index 233df10a..98e87137 100644 --- a/core/api/utils/metadata_values.py +++ b/core/api/utils/metadata_values.py @@ -28,20 +28,17 @@ def store_metadata_values(s_data, schema_obj, analysis_date): sequencing_sample_id__iexact=s_data["sequencing_sample_id"] ).last() for field, value in s_data.items(): - property_name = ( - core.models.SchemaProperties.objects.filter( - schemaID=schema_obj, property__iexact=field - ) - .last() - ) + property_name = core.models.SchemaProperties.objects.filter( + schemaID=schema_obj, property__iexact=field + ).last() data = { "value": value, "sample": sample_obj.id, "schema_property": property_name.id, - "analysis_date": analysis_date + "analysis_date": analysis_date, } - meta_value_serializer = ( - core.api.serializers.CreateMetadataValueSerializer(data=data) + meta_value_serializer = core.api.serializers.CreateMetadataValueSerializer( + data=data ) if not meta_value_serializer.is_valid(): return { diff --git a/core/api/views.py b/core/api/views.py index e6bff0f8..23ac9ee5 100644 --- a/core/api/views.py +++ b/core/api/views.py @@ -136,14 +136,16 @@ def create_sample_data(request): sample_id = sample_obj.get_sample_id() # Add initial state history (after creating the sample) - is_first_entry = not core.models.SampleStateHistory.objects.filter(sample=sample_obj).exists() + is_first_entry = not core.models.SampleStateHistory.objects.filter( + sample=sample_obj + ).exists() if is_first_entry: error_name_obj = core.models.ErrorName.objects.filter(pk=1).first() try: core.api.utils.common_functions.add_sample_state_history( sample_obj, state_id=split_data["sample"]["state"], - error_name=error_name_obj + error_name=error_name_obj, ) except ValueError as e: return Response({"ERROR": str(e)}, status=status.HTTP_400_BAD_REQUEST) @@ -171,10 +173,12 @@ def create_sample_data(request): core.api.utils.common_functions.add_sample_state_history( sample_obj, state_id=state_id, - error_name=None # TODO: do not know what to do with this at this point + error_name=None, # TODO: do not know what to do with this at this point ) except ValueError as e: - return Response({"ERROR": str(e)}, status=status.HTTP_400_BAD_REQUEST) + return Response( + {"ERROR": str(e)}, status=status.HTTP_400_BAD_REQUEST + ) # Save GISAID info if included if len(split_data["gisaid"]) > 0: @@ -195,10 +199,12 @@ def create_sample_data(request): core.api.utils.common_functions.add_sample_state_history( sample_obj, state_id=state_id, - error_name=None # TODO: do not know what to do with this at this point + error_name=None, # TODO: do not know what to do with this at this point ) except ValueError as e: - return Response({"ERROR": str(e)}, status=status.HTTP_400_BAD_REQUEST) + return Response( + {"ERROR": str(e)}, status=status.HTTP_400_BAD_REQUEST + ) # Save AUTHOR info if included if len(split_data["author"]) > 0: @@ -406,7 +412,7 @@ def create_metadata_value(request): core.api.utils.common_functions.add_sample_state_history( sample_obj, state_id=state_id, - error_name=None # TODO: do not know what to do with this at this point + error_name=None, # TODO: do not know what to do with this at this point ) except ValueError as e: return Response({"ERROR": str(e)}, status=status.HTTP_400_BAD_REQUEST) @@ -657,13 +663,15 @@ def update_state(request): # FIXME: it has been tested with error_code == None --> automatically_assigned value "other" (error_code_pk=21). Further testing is required. e_data = { "error_name": data.get("error_name", None), - "error_code": data.get("error_code", None) + "error_code": data.get("error_code", None), } - error_name_obj = core.api.utils.common_functions.handle_sample_errors(dict_error=e_data) + error_name_obj = core.api.utils.common_functions.handle_sample_errors( + dict_error=e_data + ) # Create changed_at field if not provided try: - current_time = data['changed_at'] + current_time = data["changed_at"] except KeyError: current_time = timezone.now() @@ -682,7 +690,9 @@ def update_state(request): ).update(is_current=False) # Serialize and validate the state update - sample_state_serializer = core.api.serializers.SampleStateHistorySerializer(data=s_data) + sample_state_serializer = core.api.serializers.SampleStateHistorySerializer( + data=s_data + ) if not sample_state_serializer.is_valid(): return Response( sample_state_serializer.errors, status=status.HTTP_400_BAD_REQUEST diff --git a/core/models.py b/core/models.py index dc0e0b7f..3f63cbbd 100644 --- a/core/models.py +++ b/core/models.py @@ -310,7 +310,7 @@ def create_new_value(self, data): value=data["value"], analysis_date=data["analysis_date"], sample=data["sample_id"], - schema_property=data["schema_property_id"] + schema_property=data["schema_property_id"], ) return new_value @@ -320,14 +320,12 @@ class MetadataValues(models.Model): generated_at = models.DateTimeField(auto_now_add=True, null=True, blank=True) analysis_date = models.DateField() sample = models.ForeignKey( - 'core.Sample', - on_delete=models.CASCADE, - related_name="metadata_values" + "core.Sample", on_delete=models.CASCADE, related_name="metadata_values" ) schema_property = models.ForeignKey( - 'core.SchemaProperties', + "core.SchemaProperties", on_delete=models.CASCADE, - related_name="metadata_values" + related_name="metadata_values", ) class Meta: