improved duplicate handling
This commit is contained in:
+13
-4
@@ -1,6 +1,7 @@
|
||||
from collections import defaultdict
|
||||
from typing import List, Tuple
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse
|
||||
from ninja import ModelSchema, Router, Schema, Field
|
||||
|
||||
from django.db import transaction
|
||||
@@ -8,6 +9,7 @@ from django.db import transaction
|
||||
# from .decorators import user_is_author_or_rapid_checker
|
||||
from django.core.exceptions import PermissionDenied
|
||||
import pydicom
|
||||
from pydicom.errors import InvalidDicomError
|
||||
|
||||
from generic.decorators import check_user_in_group
|
||||
from generic.constants import Group
|
||||
@@ -54,6 +56,7 @@ class CaseSchema(ModelSchema):
|
||||
def upload_dicom(request, files: List[UploadedFile] = File(...)):
|
||||
uploaded = []
|
||||
duplicate = []
|
||||
failed = []
|
||||
for file in files:
|
||||
# data = file.read()
|
||||
try:
|
||||
@@ -66,8 +69,10 @@ def upload_dicom(request, files: List[UploadedFile] = File(...)):
|
||||
print(ud.check_for_duplicates(ud.image_blake3_hash))
|
||||
duplicate.append((file.name, ud.image_blake3_hash))
|
||||
pass
|
||||
except InvalidDicomError:
|
||||
failed.append(file.name)
|
||||
|
||||
return {"uploaded": uploaded, "duplicates": duplicate}
|
||||
return {"uploaded": uploaded, "duplicates": duplicate, "failed": failed}
|
||||
|
||||
@router.post("/generate_image_hash", auth=django_auth)
|
||||
def generate_image_hash(request, id:int):
|
||||
@@ -253,14 +258,18 @@ def check_images_hashes(request, hashes: List[str]):
|
||||
for hash in hashes:
|
||||
try:
|
||||
# TOOD also check against uncategorised dicoms?
|
||||
with transaction.atomic():
|
||||
series_image = SeriesImage.objects.get(image_blake3_hash=hash)
|
||||
series_image = SeriesImage.objects.get(image_blake3_hash=hash)
|
||||
data = {
|
||||
"id": series_image.pk,
|
||||
"url": series_image.series.get_absolute_url(),
|
||||
"type": "series"
|
||||
}
|
||||
except SeriesImage.DoesNotExist:
|
||||
data = { "id": False, "url": False}
|
||||
try:
|
||||
uncategorised_dicom = UncategorisedDicom.objects.get(image_blake3_hash=hash)
|
||||
data = { "id":uncategorised_dicom.pk, "url": reverse("atlas:user_uploads"), "type": "uncategorised"}
|
||||
except UncategorisedDicom.DoesNotExist:
|
||||
data = { "id": False, "url": False}
|
||||
|
||||
hash_status[hash] = data
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<a href="{% url 'atlas:categories_list' %}">Categories</a> /
|
||||
<a href="{% url 'atlas:case_create' %}" title="Create a new atlas case">Create Case</a> /
|
||||
<a href="{% url 'atlas:series_create' %}" title="Create a new image series">Create Series</a> /
|
||||
<a href="{% url 'atlas:user_uploads' %}" title="View unimported uploads">Uploads</a> /
|
||||
<a href="{% url 'atlas:help' %}" title="View the atlas help pages">Help</a>
|
||||
{% endif %}
|
||||
{% comment %} </br>
|
||||
|
||||
@@ -452,7 +452,6 @@ def user_uploads(request, case_id: int | None = None, user_only: bool = True, us
|
||||
for series in data:
|
||||
tags, date = data[series][0]
|
||||
series_list.append((series, len(data[series]), tags, date))
|
||||
print(series_list)
|
||||
|
||||
series_list.sort(key=lambda l: l[-1])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user