diff --git a/generic/forms.py b/generic/forms.py new file mode 100755 index 00000000..88f82f5c --- /dev/null +++ b/generic/forms.py @@ -0,0 +1,22 @@ +from django.forms import ( + Form, + ModelForm, + ModelMultipleChoiceField, + ModelChoiceField, + ChoiceField, + CharField, +) +from django.forms import inlineformset_factory + +from generic.models import ( + Examination, +) + +from django.contrib.admin.widgets import FilteredSelectMultiple +from django.forms.widgets import RadioSelect, TextInput, Textarea + + +class ExaminationForm(ModelForm): + class Meta: + model = Examination + fields = ["examination"] \ No newline at end of file diff --git a/generic/urls.py b/generic/urls.py new file mode 100755 index 00000000..a5d7ee67 --- /dev/null +++ b/generic/urls.py @@ -0,0 +1,14 @@ +from django.urls import path, include +from . import views + +app_name = "generic" + +urlpatterns = [ + # path('', views.question_list, name='question_list'), + path("examination/create/", + views.create_examination, + name="create_examination"), + path("examination/ajax/get_examination_id", + views.get_examination_id, + name="get_examination_id"), +] diff --git a/generic/views.py b/generic/views.py index 91ea44a2..16d17f07 100644 --- a/generic/views.py +++ b/generic/views.py @@ -1,3 +1,27 @@ from django.shortcuts import render # Create your views here. +@login_required +def create_examination(request): + form = ExaminationForm(request.POST or None) + if form.is_valid(): + instance = form.save() + return HttpResponse( + '' + % (instance.pk, instance) + ) + return render( + request, "rapids/create_simple.html", {"form": form, "name": "Examination"} + ) + +@csrf_exempt +def get_examination_id(request): + if request.is_ajax(): + examination_name = request.GET["examination_name"] + examination_id = Examination.objects.get(name=examination_name).id + data = { + "examination_id": examination_id, + } + return HttpResponse(json.dumps(data), content_type="application/json") + return HttpResponse("/") + diff --git a/longs/models.py b/longs/models.py index 5b968ddb..ddf5dcf7 100644 --- a/longs/models.py +++ b/longs/models.py @@ -127,8 +127,8 @@ class LongSeries(models.Model): modality = models.ForeignKey(Modality, related_name="series_modality", on_delete=models.SET_NULL, null=True) examination = models.ForeignKey( Examination, help_text="Name of the examination", related_name="series_examination", on_delete=models.SET_NULL, null=True) - long = models.ForeignKey("Long", related_name="series", on_delete=models.SET_NULL, null=True) - description = models.TextField(blank=True, help_text="Description of stack, for admin organisation") + long = models.ForeignKey("Long", help_text="The question this series should be associated with", related_name="series", on_delete=models.SET_NULL, null=True) + description = models.TextField(blank=True, help_text="Description of stack, for admin organisation, will not be visible when taking") def get_examinations(self): """Returns a comma seperated text list of regions""" diff --git a/longs/templates/longs/base.html b/longs/templates/longs/base.html index 01846ab6..1d87cea9 100755 --- a/longs/templates/longs/base.html +++ b/longs/templates/longs/base.html @@ -20,6 +20,7 @@ Longs: Exams / Questions / Create Question +Create Series {% endif %} {% comment %} Questions by: diff --git a/longs/templates/longs/longseries_form.html b/longs/templates/longs/longseries_form.html index 93dd50ad..fd5afa43 100755 --- a/longs/templates/longs/longseries_form.html +++ b/longs/templates/longs/longseries_form.html @@ -39,9 +39,7 @@ $(document).ready(function () { - $("#add_abnormality").appendTo($("label[for='id_abnormality']")); $("#add_examination").appendTo($("label[for='id_examination']")); - $("#add_region").appendTo($("label[for='id_region']")); dropContainer = document.getElementById("drop-container"); @@ -281,9 +279,12 @@ {% endblock %} {% block content %}