Add htmx autocomplete and allow merging of conditions
This commit is contained in:
@@ -36,6 +36,7 @@ from .forms import (
|
||||
CaseForm,
|
||||
CidReportAnswerForm,
|
||||
CidReportAnswerMarkForm,
|
||||
ConditionAutocompleteForm,
|
||||
ConditionForm,
|
||||
FindingForm,
|
||||
SelfReviewForm,
|
||||
@@ -53,6 +54,7 @@ from .models import (
|
||||
CaseDetail,
|
||||
CidReportAnswer,
|
||||
Condition,
|
||||
Differential,
|
||||
PathologicalProcess,
|
||||
Presentation,
|
||||
SelfReview,
|
||||
@@ -92,6 +94,9 @@ from .filters import (
|
||||
from django_tables2 import SingleTableView, SingleTableMixin
|
||||
from django_filters.views import FilterView
|
||||
|
||||
from autocomplete import HTMXAutoComplete
|
||||
|
||||
|
||||
from .decorators import (
|
||||
user_is_author_or_atlas_editor,
|
||||
user_is_author_or_atlas_editor_or_atlas_marker,
|
||||
@@ -186,15 +191,65 @@ def series_detail(request, pk, finding_pk=None):
|
||||
def condition_detail(request, pk):
|
||||
condition = get_object_or_404(Condition, pk=pk)
|
||||
|
||||
form = ConditionAutocompleteForm()
|
||||
|
||||
# logging.debug(atlas.subspecialty.first().name.all())
|
||||
return render(
|
||||
request,
|
||||
"atlas/condition_detail.html",
|
||||
{
|
||||
"condition": condition,
|
||||
"form": form
|
||||
},
|
||||
)
|
||||
|
||||
#class GetConditionAutocomplete(HTMXAutoComplete):
|
||||
# name = "conditions"
|
||||
# multiselect = False
|
||||
#
|
||||
# class Meta:
|
||||
# model = Condition
|
||||
|
||||
@login_required
|
||||
@user_is_atlas_editor
|
||||
def condition_merge(request, pk_to_merge):
|
||||
if not request.htmx:
|
||||
raise Http404
|
||||
|
||||
condition_to_merge = get_object_or_404(Condition, pk=pk_to_merge)
|
||||
#condition_to_merge_into = get_object_or_404(Condition, pk=pk_to_merge_into)
|
||||
|
||||
print(condition_to_merge.case_set)
|
||||
if condition_to_merge.rcr_curriculum:
|
||||
return HttpResponse("You cannot merge rcr curriculum items")
|
||||
|
||||
condition_to_merge_into = request.POST.get("conditions")
|
||||
|
||||
if not condition_to_merge_into:
|
||||
return HttpResponse("You need to select a condition to merge into.")
|
||||
|
||||
condition_to_merge_into = get_object_or_404(Condition, pk=condition_to_merge_into)
|
||||
|
||||
if condition_to_merge == condition_to_merge_into:
|
||||
return HttpResponse("You cannot merge into the same condition.")
|
||||
|
||||
|
||||
# move all relevant relationships
|
||||
cases = condition_to_merge.case_set.all().values_list("id", flat=True)
|
||||
condition_to_merge_into.case_set.add(cases)
|
||||
#cases = Case.objects.filter(condition=condition_to_merge)
|
||||
#cases.update(condition=condition_to_merge_into)
|
||||
|
||||
differentials = Differential.objects.filter(condition=condition_to_merge)
|
||||
differentials.update(condition=condition_to_merge_into)
|
||||
|
||||
return HttpResponse("Merged")
|
||||
|
||||
#conditions = Condition.objects.all()
|
||||
|
||||
#return render(request, "atlas/condition_options.html", {"conditions": conditions})
|
||||
|
||||
|
||||
|
||||
@login_required
|
||||
@user_is_atlas_editor
|
||||
|
||||
Reference in New Issue
Block a user