pre series form update
This commit is contained in:
@@ -16,6 +16,7 @@ from django.shortcuts import get_object_or_404
|
||||
from atlas.models import (
|
||||
Case,
|
||||
CaseCollection,
|
||||
CaseDetail,
|
||||
CidReportAnswer,
|
||||
Differential,
|
||||
Finding,
|
||||
@@ -39,6 +40,7 @@ from tinymce.widgets import TinyMCE
|
||||
|
||||
from dal import autocomplete
|
||||
|
||||
import logging
|
||||
|
||||
class ConditionForm(ModelForm):
|
||||
class Meta:
|
||||
@@ -240,9 +242,20 @@ class CaseForm(ModelForm):
|
||||
js = ["jsi18n.js", "tesseract.min.js"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
logging.info("LOG")
|
||||
logging.debug(kwargs)
|
||||
self.user = kwargs.pop(
|
||||
"user"
|
||||
) # To get request.user. Do not use kwargs.pop('user', None) due to potential security hole
|
||||
|
||||
# This is populated if we create the case from an exam/collection
|
||||
self.collection = None
|
||||
if "exams" in kwargs["initial"]:
|
||||
collections = kwargs["initial"].pop("exams")
|
||||
logging.debug(collections)
|
||||
|
||||
self.collection = get_object_or_404(CaseCollection, pk=collections[0])
|
||||
|
||||
if kwargs.get("instance"):
|
||||
# We get the 'initial' keyword argument or initialize it
|
||||
# as a dict if it didn't exist.
|
||||
@@ -251,6 +264,7 @@ class CaseForm(ModelForm):
|
||||
# a list of primary key for the selected data.
|
||||
# initial["exams"] = [t.pk for t in kwargs["instance"].exams.all()]
|
||||
|
||||
|
||||
ModelForm.__init__(self, *args, **kwargs)
|
||||
|
||||
super(CaseForm, self).__init__(*args, **kwargs)
|
||||
@@ -307,6 +321,9 @@ class CaseForm(ModelForm):
|
||||
# Get the unsaved Case instance
|
||||
instance = ModelForm.save(self, False)
|
||||
|
||||
|
||||
|
||||
|
||||
# Prepare a 'save_m2m' method for the form,
|
||||
old_save_m2m = self.save_m2m
|
||||
|
||||
@@ -324,6 +341,18 @@ class CaseForm(ModelForm):
|
||||
instance.save()
|
||||
self.save_m2m()
|
||||
|
||||
logging.debug(f"{self.collection=}")
|
||||
|
||||
if self.collection is not None:
|
||||
logging.debug(f"{self.collection=}")
|
||||
case_no = self.collection.cases.count() + 1
|
||||
logging.debug(f"{case_no=}")
|
||||
logging.debug(f"{instance=}")
|
||||
|
||||
# Create through model
|
||||
#cd = CaseDetail(case=instance, collection=exam, sort_order=case_no)
|
||||
self.collection.cases.add(instance, through_defaults={"sort_order": case_no})
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
|
||||
@@ -117,8 +117,8 @@
|
||||
Add collection</button>
|
||||
<div id="collection-form"></div>
|
||||
<ul>
|
||||
{% for p in case.casecollection_set.all %}
|
||||
<li>{{p.name}}</li>
|
||||
{% for collection in case.casecollection_set.all %}
|
||||
<li><a href="{% url 'atlas:collection_detail' pk=collection.pk %}">{{collection.name}}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
@@ -51,6 +51,10 @@
|
||||
{% block content %}
|
||||
<h2>Submit Case</h2>
|
||||
Use this form to create a atlas case. Existing associated image sets can be added using this form.
|
||||
|
||||
{% if form.collection %}
|
||||
<div class="alert alert-info" role="alert">Creating a case in the collection: <a href="{% url 'atlas:collection_detail' pk=form.collection.pk %}">{{form.collection.name}}</a></div>
|
||||
{% endif %}
|
||||
<form action="" method="post" enctype="multipart/form-data" id="atlas-form">
|
||||
{% csrf_token %}
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
<br/>Collection: {{collection.name}}-> <a href="{% url 'atlas:collection_detail' pk=collection.pk %}">Overview</a> /
|
||||
<a href="{% url 'atlas:collection_mark_overview' collection.pk %}">Mark</a> /
|
||||
<a href="{% url 'atlas:collection_scores_cid' collection.pk %}">Scores</a> /
|
||||
<a href="{% url 'atlas:exam_cids' collection.pk %}">Candidates</a>
|
||||
<a href="{% url 'atlas:exam_cids' collection.pk %}">Candidates</a> /
|
||||
<a href="{% url 'atlas:atlas_create_exam' pk=collection.pk %}">Add New Case</a>
|
||||
<div class="floating-header">
|
||||
<a href="{% url 'atlas:collection_update' collection.id %}" title="Edit the Collection">Edit</a>
|
||||
\ <a href="{% url 'atlas:collection_delete' collection.id %}" title="Delete the Collection">Delete</a>
|
||||
|
||||
@@ -486,8 +486,8 @@
|
||||
</table>
|
||||
|
||||
<h3>Images:</h3>
|
||||
<input type="button" value="Add More Images" id="add_more_images">
|
||||
<div id="drop-container" class="">Drop images here (or use the buttons below). Dropping images here will overwrite
|
||||
<input type="button" value="Add More Images (manually)" id="add_more_images">
|
||||
<div id="drop-container" class="series-drop">Drop images here (or use the buttons below). Dropping images here will overwrite
|
||||
existing images in the series. When drag and dropping make sure to drag the first image or the order will not be
|
||||
maintained. Note: dicom images are often not exported in order (although their order can be automatically
|
||||
detected once uploaded)
|
||||
|
||||
@@ -127,6 +127,7 @@ urlpatterns = [
|
||||
path("case/<int:pk>/scrap", views.atlas_scrap, name="case_scrap"),
|
||||
path("case/<int:pk>/delete", views.CaseDelete.as_view(), name="case_delete"),
|
||||
path("case/create/", views.AtlasCreate.as_view(), name="case_create"),
|
||||
path("case/collection/<int:pk>/create", views.AtlasCreate.as_view(), name="atlas_create_exam"),
|
||||
path("series/create", views.SeriesCreate.as_view(), name="series_create"),
|
||||
path(
|
||||
"series/<int:pk>/create",
|
||||
|
||||
+14
-7
@@ -645,13 +645,20 @@ class AtlasCreateBase(RevisionMixin, LoginRequiredMixin):
|
||||
# @login_required
|
||||
class AtlasCreate(AtlasCreateBase, CreateView):
|
||||
def get_initial(self):
|
||||
# There has to be a better way...
|
||||
try:
|
||||
s = (i.pk for i in self.request.user.atlas_default.site.all())
|
||||
self.initial.update({"site": s})
|
||||
except AttributeError:
|
||||
pass
|
||||
return self.initial
|
||||
if "pk" in self.kwargs:
|
||||
initial = super().get_initial()
|
||||
exam = get_object_or_404(CaseCollection, pk=self.kwargs["pk"])
|
||||
|
||||
initial["exams"] = [exam.id]
|
||||
|
||||
return initial
|
||||
## There has to be a better way...
|
||||
#try:
|
||||
# s = (i.pk for i in self.request.user.atlas_default.site.all())
|
||||
# self.initial.update({"site": s})
|
||||
#except AttributeError:
|
||||
# pass
|
||||
#return self.initial
|
||||
|
||||
|
||||
class AtlasUpdate(
|
||||
|
||||
Reference in New Issue
Block a user