.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
{% extends 'sbas/base.html' %}
|
||||
|
||||
{% load render_table from django_tables2 %}
|
||||
{% block css %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div id="view-filter-options">
|
||||
<h3>SBA User Answers</h3>
|
||||
<form action="" method="get">
|
||||
{{ filter.form }}
|
||||
<input class="btn btn-primary btn-sm mt-1 mb-1" type="submit" />
|
||||
</form>
|
||||
</div>
|
||||
{% render_table table %}
|
||||
<button id="delete-selected-button">Delete selected answers</button>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("table thead th input").click((e) => {
|
||||
let status = e.currentTarget.checked; console.log(status, $("table tbody input")); $("table tbody input").prop("checked", status);
|
||||
})
|
||||
//$("thead input:checked").each((n, el) => {
|
||||
|
||||
$("#delete-selected-button").on("click", function () {
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
answer_ids.push(el.value);
|
||||
})
|
||||
|
||||
if (confirm(`Delete ${answer_ids.length} answers?`)) {
|
||||
$.ajax({
|
||||
url: "{% url 'sbas:user_answer_delete_multiple' %}",
|
||||
data: {
|
||||
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||
answer_ids: JSON.stringify(answer_ids) // true if checked else false
|
||||
},
|
||||
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('Deleted.')
|
||||
location.reload();
|
||||
} else {
|
||||
toastr.info('Error deleting questions.')
|
||||
|
||||
}
|
||||
// show some message according to the response.
|
||||
// For eg. A message box showing that the status has been changed
|
||||
})
|
||||
.always(function () {
|
||||
console.log('[Done]');
|
||||
})
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -8,6 +8,7 @@ urlpatterns = [
|
||||
# path('', views.question_list, name='question_list'),
|
||||
path("", views.SbasExamViews.index, name="index"),
|
||||
path("question/", views.QuestionView.as_view(), name="question_view"),
|
||||
path("user_answers/", views.UserAnswerTableView.as_view(), name="user_answer_table_view"),
|
||||
path("question/<int:pk>/", views.question_detail, name="question_detail"),
|
||||
#path("question/create/", views.QuestionCreate.as_view(), name="anatomy_question_create"),
|
||||
#path("question/<int:pk>/update", views.QuestionUpdate.as_view(), name="anatomy_question_update"),
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from generic.mixins import SuperuserRequiredMixin
|
||||
from django.views.generic.detail import DetailView
|
||||
from sbas.forms import CidUserAnswerForm
|
||||
from django.shortcuts import render, get_object_or_404, redirect
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
@@ -362,3 +364,19 @@ class QuestionView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
template_name = "sbas/question_view.html"
|
||||
|
||||
filterset_class = QuestionFilter
|
||||
|
||||
class UserAnswerView(LoginRequiredMixin, DetailView):
|
||||
model = CidUserAnswer
|
||||
|
||||
|
||||
class UserAnswerTableView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
model = CidUserAnswer
|
||||
table_class = UserAnswerTable
|
||||
template_name = "sbas/user_answer_question_view.html"
|
||||
|
||||
filterset_class = UserAnswerFilter
|
||||
|
||||
|
||||
class UserAnswerDelete(SuperuserRequiredMixin, DeleteView):
|
||||
model = CidUserAnswer
|
||||
success_url = reverse_lazy("sbas:user_answer_table_view")
|
||||
Reference in New Issue
Block a user