Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix annotation target selector start error #725

Merged
merged 1 commit into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project/annotation_project/annotations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Source(models.Model):

class Selector(models.Model):
type = models.CharField(max_length=100, default='TextPositionSelector')
start = models.PositiveIntegerField()
start = models.IntegerField()
end = models.PositiveIntegerField()
source = models.ForeignKey(Source, on_delete=models.CASCADE)

Expand Down
7 changes: 4 additions & 3 deletions project/annotation_project/annotations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def create_annotation(request):
body = json.loads(body)

value = body.get('value')
if not value:
if value is None:
return JsonResponse({'message': 'body value must be given!'}, status=400)

body_type = body.get('type')
Expand All @@ -132,11 +132,11 @@ def create_annotation(request):

selector_type = selector.get('type')
selector_start = selector.get('start')
if not selector_start:
if selector_start is None:
return JsonResponse({'message': 'selector start must be given!'}, status=400)

selector_end = selector.get('end')
if not selector_end:
if selector_end is None:
return JsonResponse({'message': 'selector end must be given!'}, status=400)

creator = request.POST.get('creator')
Expand Down Expand Up @@ -203,6 +203,7 @@ def create_annotation(request):

return JsonResponse(data = serialize_annotation(annotation_object), status=201)
except Exception as e:
print(str(e))
if "duplicate key value violates unique constraint" in str(e):
return JsonResponse({'message': 'Annotation already exists!'}, status=400)
return JsonResponse({'message': "Internal server error"}, status=500)