diff --git a/backend/dataset/migrations/0046_merge_20240403_1156.py b/backend/dataset/migrations/0046_merge_20240403_1156.py new file mode 100644 index 000000000..db21599f4 --- /dev/null +++ b/backend/dataset/migrations/0046_merge_20240403_1156.py @@ -0,0 +1,12 @@ +# Generated by Django 3.2.23 on 2024-04-03 11:56 + +from django.db import migrations + + +class Migration(migrations.Migration): + dependencies = [ + ("dataset", "0045_alter_ocrdocument_ocr_domain"), + ("dataset", "0045_auto_20240321_0949"), + ] + + operations = [] diff --git a/backend/tasks/migrations/0049_annotation_version_updated_at.py b/backend/tasks/migrations/0049_annotation_version_updated_at.py new file mode 100644 index 000000000..d5a680b7e --- /dev/null +++ b/backend/tasks/migrations/0049_annotation_version_updated_at.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.23 on 2024-04-16 09:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("tasks", "0048_alter_annotation_unique_together"), + ] + + operations = [ + migrations.AddField( + model_name="annotation", + name="version_updated_at", + field=models.DateTimeField( + default="2000-01-01T00:00:00Z", + verbose_name="annotation_version_updated_at", + ), + ), + ] diff --git a/backend/tasks/models.py b/backend/tasks/models.py index 7fac09c7a..fcd8437b9 100644 --- a/backend/tasks/models.py +++ b/backend/tasks/models.py @@ -232,6 +232,10 @@ class Annotation(models.Model): updated_at = models.DateTimeField( auto_now=True, verbose_name="annotation_updated_at" ) + version_updated_at = models.DateTimeField( + default="2000-01-01T00:00:00Z", + verbose_name="annotation_version_updated_at", + ) lead_time = models.FloatField(default=0.0, verbose_name="annotation_lead_time") parent_annotation = models.ForeignKey( "self", diff --git a/backend/tasks/views.py b/backend/tasks/views.py index 43517ac06..1e613dc5c 100644 --- a/backend/tasks/views.py +++ b/backend/tasks/views.py @@ -1776,6 +1776,26 @@ def partial_update(self, request, pk=None): self.populate_task_data_language_and_domain( annotation_obj.task, language, ocr_domain ) + + if "last_updated_at" in request.data: + try: + dt_object = datetime.strptime( + request.data["last_updated_at"], "%Y-%m-%dT%H:%M:%S.%fZ" + ) + output_datetime = dt_object.strftime("%Y-%m-%d %H:%M:%S.%f+00:00") + except: + dt_object = datetime.strptime( + request.data["last_updated_at"], "%Y-%m-%dT%H:%M:%SZ" + ) + output_datetime = dt_object.strftime("%Y-%m-%d %H:%M:%S+00:00") + if str(output_datetime) != str(annotation_obj.version_updated_at): + return Response( + { + "message": "Annotation got updated, please refresh and try again." + }, + status=status.HTTP_400_BAD_REQUEST, + ) + # Base annotation update if annotation_obj.annotation_type == ANNOTATOR_ANNOTATION: if request.user not in task.annotation_users.all(): @@ -1785,7 +1805,16 @@ def partial_update(self, request, pk=None): # need to add few filters here if auto_save: - update_fields_list = ["result", "lead_time", "updated_at"] + update_fields_list = [ + "result", + "lead_time", + "updated_at", + "version_updated_at", + ] + annotation_obj.version_updated_at = ( + request.data["version_updated_at"] + or annotation_obj.version_updated_at + ) if "cl_format" in request.query_params: ( annotation_obj.result, @@ -1914,7 +1943,16 @@ def partial_update(self, request, pk=None): return Response(ret_dict, status=ret_status) if auto_save: - update_fields_list = ["result", "lead_time", "updated_at"] + update_fields_list = [ + "result", + "lead_time", + "updated_at", + "version_updated_at", + ] + annotation_obj.version_updated_at = ( + request.data["version_updated_at"] + or annotation_obj.version_updated_at + ) if "cl_format" in request.query_params: ( annotation_obj.result, @@ -2109,7 +2147,16 @@ def partial_update(self, request, pk=None): return Response(ret_dict, status=ret_status) if auto_save: - update_fields_list = ["result", "lead_time", "updated_at"] + update_fields_list = [ + "result", + "lead_time", + "updated_at", + "version_updated_at", + ] + annotation_obj.version_updated_at = ( + request.data["version_updated_at"] + or annotation_obj.version_updated_at + ) if "cl_format" in request.query_params: ( annotation_obj.result,