.
This commit is contained in:
+1
-1
@@ -58,7 +58,7 @@ class AnatomyQuestionTable(tables.Table):
|
||||
class AnatomyUserAnswerTable(tables.Table):
|
||||
select = tables.CheckBoxColumn(accessor=("pk"))
|
||||
delete = tables.LinkColumn(
|
||||
"anatomy:anatomy_user_answer_delete", text="Delete", args=[A("pk")], orderable=False
|
||||
"anatomy:user_answer_delete", text="Delete", args=[A("pk")], orderable=False
|
||||
)
|
||||
class Meta:
|
||||
model = CidUserAnswer
|
||||
|
||||
+1
-1
@@ -56,5 +56,5 @@ urlpatterns = [
|
||||
views.get_examination_id,
|
||||
name="get_examination_id"),
|
||||
path("user_answers/", views.AnatomyUserAnswerView.as_view(), name="anatomy_user_answer_view"),
|
||||
path("user_answers/<int:pk>/delete", views.UserAnswerDelete.as_view(), name="anatomy_user_answer_delete"),
|
||||
path("user_answers/<int:pk>/delete", views.UserAnswerDelete.as_view(), name="user_answer_delete"),
|
||||
]
|
||||
|
||||
@@ -13,44 +13,9 @@
|
||||
<input class="btn btn-primary btn-sm mt-1 mb-1" type="submit" />
|
||||
</form>
|
||||
</div>
|
||||
<button id="delete-all-button">Delete all</button>
|
||||
{% render_table table %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
//$("thead input:checked").each((n, el) => {
|
||||
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
answer_ids.push(el.value);
|
||||
})
|
||||
$("#delete-all-button").on("click", function () {
|
||||
$.ajax({
|
||||
url: "{% url 'longs: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.')
|
||||
}
|
||||
// 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 %}
|
||||
@@ -0,0 +1,59 @@
|
||||
{% extends 'longs/base.html' %}
|
||||
|
||||
{% load render_table from django_tables2 %}
|
||||
{% block css %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div id="view-filter-options">
|
||||
<h3>Filter 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) => {
|
||||
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
answer_ids.push(el.value);
|
||||
})
|
||||
$("#delete-selected-button").on("click", function () {
|
||||
$.ajax({
|
||||
url: "{% url 'longs: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.')
|
||||
}
|
||||
// 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 %}
|
||||
+1
-1
@@ -1047,7 +1047,7 @@ class UserAnswerView(LoginRequiredMixin, DetailView):
|
||||
class UserAnswerTableView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
model = CidUserAnswer
|
||||
table_class = UserAnswerTable
|
||||
template_name = "longs/question_view.html"
|
||||
template_name = "longs/user_answer_question_view.html"
|
||||
|
||||
filterset_class = UserAnswerFilter
|
||||
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ class RapidTable(tables.Table):
|
||||
class RapidUserAnswerTable(tables.Table):
|
||||
select = tables.CheckBoxColumn(accessor=("pk"))
|
||||
delete = tables.LinkColumn(
|
||||
"rapids:rapid_user_answer_delete", text="Delete", args=[A("pk")], orderable=False
|
||||
"rapids:user_answer_delete", text="Delete", args=[A("pk")], orderable=False
|
||||
)
|
||||
view = tables.LinkColumn('rapids:rapid_user_answer_view',
|
||||
text='View',
|
||||
|
||||
@@ -6,5 +6,5 @@ CID: {{ciduseranswer.cid}}<br/>
|
||||
{{ciduseranswer.question}}<br/>
|
||||
Normal: {{ciduseranswer.normal}}<br/>
|
||||
Answer: {{ciduseranswer.answer}}<br/>
|
||||
<a href="{% url 'rapids:rapid_user_answer_delete' ciduseranswer.id %}">Delete answer</a>
|
||||
<a href="{% url 'rapids:user_answer_delete' ciduseranswer.id %}">Delete answer</a>
|
||||
{% endblock content %}
|
||||
@@ -0,0 +1,59 @@
|
||||
{% extends 'rapids/base.html' %}
|
||||
|
||||
{% load render_table from django_tables2 %}
|
||||
{% block css %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div id="view-filter-options">
|
||||
<h3>Rapid 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) => {
|
||||
|
||||
answer_ids = [];
|
||||
$("tbody input:checked").each((n, el) => {
|
||||
answer_ids.push(el.value);
|
||||
})
|
||||
$("#delete-all-button").on("click", function () {
|
||||
$.ajax({
|
||||
url: "{% url 'longs: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.')
|
||||
}
|
||||
// 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 %}
|
||||
+2
-1
@@ -70,5 +70,6 @@ urlpatterns = [
|
||||
path("<int:pk>/add_note", views.AddNote.as_view(), name="rapid_add_note"),
|
||||
path("user_answers/", views.UserAnswerTableView.as_view(), name="rapid_user_answer_table_view"),
|
||||
path("user_answers/<int:pk>", views.UserAnswerView.as_view(), name="rapid_user_answer_view"),
|
||||
path("user_answers/<int:pk>/delete", views.UserAnswerDelete.as_view(), name="rapid_user_answer_delete"),
|
||||
path("user_answers/<int:pk>/delete", views.UserAnswerDelete.as_view(), name="user_answer_delete"),
|
||||
path("user_answers/delete", views.user_answer_delete_multiple, name="user_answer_delete_multiple"),
|
||||
]
|
||||
|
||||
+12
-1
@@ -1009,7 +1009,7 @@ class UserAnswerView(LoginRequiredMixin, DetailView):
|
||||
class UserAnswerTableView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||
model = CidUserAnswer
|
||||
table_class = RapidUserAnswerTable
|
||||
template_name = "rapids/rapid_question_view.html"
|
||||
template_name = "rapids/user_answer_question_view.html"
|
||||
|
||||
filterset_class = RapidUserAnswerFilter
|
||||
|
||||
@@ -1118,3 +1118,14 @@ class RapidLateralityViewSet(
|
||||
# get_object_or_404(question, pk=pk)
|
||||
# return { "content_type" : content_type,
|
||||
# "object_id" : pk }
|
||||
|
||||
@user_passes_test(lambda u: u.is_superuser)
|
||||
def user_answer_delete_multiple(request):
|
||||
if request.is_ajax():
|
||||
answer_ids = json.loads(request.POST["answer_ids"])
|
||||
|
||||
# We could probably delete them all at once....
|
||||
for id in answer_ids:
|
||||
CidUserAnswer.objects.get(pk=id).delete()
|
||||
return HttpResponseRedirect(request.path_info)
|
||||
return HttpResponse("/")
|
||||
|
||||
Reference in New Issue
Block a user