.
This commit is contained in:
@@ -71,6 +71,69 @@ $(document).ready(function () {
|
||||
$(document).keydown(keyDownHandler);
|
||||
$(document).keyup(keyUpHandler);
|
||||
|
||||
$("#button-select-add-exam").click(function (evt) {
|
||||
// Find selected objects
|
||||
|
||||
|
||||
|
||||
var jqxhr = $.get(evt.target.dataset.exam_list_url, function (data) {
|
||||
console.log(data);
|
||||
data.forEach((obj, n) => {
|
||||
$("#exam-options").append($(document.createElement('button')).prop({
|
||||
type: 'button',
|
||||
innerHTML: obj.name,
|
||||
class: '',
|
||||
|
||||
}).data("exam-id", obj.id).click((evt) => { addToExam(evt) }))
|
||||
})
|
||||
})
|
||||
.done(function () {
|
||||
//alert( "second success" );
|
||||
})
|
||||
.fail(function () {
|
||||
//alert( "error" );
|
||||
})
|
||||
.always(function () {
|
||||
//alert( "finished" );
|
||||
});
|
||||
|
||||
return;
|
||||
|
||||
|
||||
function addToExam(evt) {
|
||||
|
||||
ids = []
|
||||
$("table input:checked").each((n, el) => {
|
||||
ids.push(el.value)
|
||||
})
|
||||
post_url = document.getElementById("button-select-add-exam").dataset.exam_json_edit_url;
|
||||
type = document.getElementById("button-select-add-exam").dataset.type;
|
||||
$.ajax({
|
||||
url: post_url,
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||
add_exam_questions: JSON.stringify(ids),
|
||||
type: type,
|
||||
exam_id: $(evt.target).data("exam-id"),
|
||||
},
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
})
|
||||
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||
.done(function (data) {
|
||||
console.log(data);
|
||||
|
||||
if (data.status == "success") {
|
||||
toastr.info('Questions added to exams.')
|
||||
}
|
||||
})
|
||||
.always(function () {
|
||||
console.log('[Done]');
|
||||
$("#exam-options").empty();
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@ from django.urls import path, include
|
||||
from . import views
|
||||
|
||||
from rapids import views as rapid_views
|
||||
from longs import views as long_views
|
||||
|
||||
from rest_framework import routers
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'rapids/exams', rapid_views.ExamViewSet, basename="rapid-exams")
|
||||
router.register(r'longs/exams', long_views.ExamViewSet, basename="long-exams")
|
||||
|
||||
app_name = "generic"
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
# serializers.py
|
||||
from rest_framework import serializers, permissions
|
||||
|
||||
|
||||
from .models import Exam
|
||||
|
||||
class ExamSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Exam
|
||||
fields = ('name', 'id', 'active', "publish_results")
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
@@ -16,4 +16,8 @@
|
||||
</div>
|
||||
{% render_table table %}
|
||||
</div>
|
||||
|
||||
<button id="button-select-add-exam" data-exam_json_edit_url="{% url 'generic:generic_exam_json_edit' %}" data-exam_list_url="{% url 'generic:long-exams-list' %}" data-type="long">Add selected questions to
|
||||
exam</button>
|
||||
<div id="exam-options"></div>
|
||||
{% endblock %}
|
||||
+10
-1
@@ -58,6 +58,11 @@ from longs.models import LongCreationDefault
|
||||
|
||||
from generic.views import ExamViews
|
||||
|
||||
|
||||
from rest_framework import viewsets
|
||||
|
||||
from .serializers import ExamSerializer
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -947,4 +952,8 @@ def long_series_order_upload_filename(request, pk):
|
||||
|
||||
return redirect("longs:long_series_detail", pk=pk)
|
||||
|
||||
LongExamViews = ExamViews(Exam, Long, "longs", "long", loadJsonAnswer)
|
||||
LongExamViews = ExamViews(Exam, Long, "longs", "long", loadJsonAnswer)
|
||||
|
||||
class ExamViewSet(viewsets.ModelViewSet):
|
||||
queryset = Exam.objects.all().order_by('name')
|
||||
serializer_class = ExamSerializer
|
||||
+1
-1
@@ -6,7 +6,7 @@ from .models import Rapid
|
||||
class RapidFilter(django_filters.FilterSet):
|
||||
class Meta:
|
||||
model = Rapid
|
||||
fields = ("normal", "abnormality", "region", "examination",
|
||||
fields = ("normal", "abnormality", "exams", "region", "examination",
|
||||
"laterality",
|
||||
#"site",
|
||||
"created_date", "author")
|
||||
|
||||
@@ -21,68 +21,6 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$("#button-select-add-exam").click(function (evt) {
|
||||
// Find selected objects
|
||||
|
||||
|
||||
|
||||
var jqxhr = $.get(evt.target.dataset.exam_list_url, function (data) {
|
||||
console.log(data);
|
||||
data.forEach((obj, n) => {
|
||||
$("#exam-options").append($(document.createElement('button')).prop({
|
||||
type: 'button',
|
||||
innerHTML: obj.name,
|
||||
class: '',
|
||||
|
||||
}).data("exam-id", obj.id).click((evt) => { addToExam(evt) }))
|
||||
})
|
||||
})
|
||||
.done(function () {
|
||||
//alert( "second success" );
|
||||
})
|
||||
.fail(function () {
|
||||
//alert( "error" );
|
||||
})
|
||||
.always(function () {
|
||||
//alert( "finished" );
|
||||
});
|
||||
|
||||
return;
|
||||
|
||||
|
||||
function addToExam(evt) {
|
||||
|
||||
ids = []
|
||||
$("table input:checked").each((n, el) => {
|
||||
ids.push(el.value)
|
||||
})
|
||||
post_url = document.getElementById("button-select-add-exam").dataset.exam_json_edit_url;
|
||||
type = document.getElementById("button-select-add-exam").dataset.type;
|
||||
$.ajax({
|
||||
url: post_url,
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||
add_exam_questions: JSON.stringify(ids),
|
||||
type: type,
|
||||
exam_id: $(evt.target).data("exam-id"),
|
||||
},
|
||||
type: "POST",
|
||||
dataType: "json",
|
||||
})
|
||||
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||
.done(function (data) {
|
||||
console.log(data);
|
||||
|
||||
if (data.status == "success") {
|
||||
toastr.info('Questions added to exams.')
|
||||
}
|
||||
})
|
||||
.always(function () {
|
||||
console.log('[Done]');
|
||||
$("#exam-options").empty();
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user