1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-06-24 21:40:30 +02:00

Add a delete question button

This commit is contained in:
Yohann D'ANELLO
2020-10-31 22:18:04 +01:00
parent d0007ee9b2
commit 2f6a1f6e56
6 changed files with 104 additions and 35 deletions

View File

@ -181,13 +181,23 @@
{% url "participation:add_question" pk=participation.pk as modal_action %}
{% include "base_modal.html" with modal_id="addQuestion" modal_button_type="success" %}
{% for question in participation.questions.all %}
{% trans "Update question" as modal_title %}
{% trans "Update" as modal_button %}
{% url "participation:update_question" pk=question.pk as modal_action %}
{% with number_str=forloop.counter|stringformat:"d" %}
{% with modal_id="updateQuestion"|add:number_str %}
{% include "base_modal.html" %}
{% endwith %}
{% with number_str=forloop.counter|stringformat:"d"%}
{% with modal_id="updateQuestion"|add:number_str %}
{% trans "Delete" as delete %}
{% with extra_modal_button='<button class="btn btn-danger" type="button" data-dismiss="modal" data-toggle="modal" data-target="#deleteQuestion'|add:number_str|add:'Modal">'|add:delete|add:"</button>"|safe %}
{% trans "Update question" as modal_title %}
{% trans "Update" as modal_button %}
{% url "participation:update_question" pk=question.pk as modal_action %}
{% include "base_modal.html" %}
{% endwith %}
{% endwith %}
{% with modal_id="deleteQuestion"|add:number_str %}
{% trans "Delete question" as modal_title %}
{% trans "Delete" as modal_button %}
{% url "participation:delete_question" pk=question.pk as modal_action %}
{% include "base_modal.html" with modal_button_type="danger" %}
{% endwith %}
{% endwith %}
{% endfor %}
{% endif %}
@ -223,6 +233,12 @@
if (!modalBody.html().trim())
modalBody.load("{% url "participation:update_question" pk=question.pk %} #form-content");
});
$('button[data-target="#deleteQuestion{{ forloop.counter }}Modal"]').click(function() {
let modalBody = $("#deleteQuestion{{ forloop.counter }}Modal div.modal-body");
if (!modalBody.html().trim())
modalBody.load("{% url "participation:delete_question" pk=question.pk %} #form-content");
});
{% endfor %}
{% endif %}

View File

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% load crispy_forms_filters i18n %}
{% block content %}
<form method="post">
<div id="form-content">
<div class="alert alert-danger">
{% trans "Are you sure you want to delete this question?" %}
</div>
{% csrf_token %}
{{ form|crispy }}
</div>
<button class="btn btn-danger" type="submit">{% trans "Delete" %}</button>
</form>
{% endblock content %}

View File

@ -1,10 +1,10 @@
from django.urls import path
from django.views.generic import TemplateView
from .views import CalendarView, CreateQuestionView, CreateTeamView, JoinTeamView, MyParticipationDetailView, \
MyTeamDetailView, ParticipationDetailView, PhaseUpdateView, SetParticipationReceiveParticipationView, \
SetParticipationSendParticipationView, TeamAuthorizationsView, TeamDetailView, TeamLeaveView, TeamUpdateView, \
UpdateQuestionView, UploadVideoView
from .views import CalendarView, CreateQuestionView, CreateTeamView, DeleteQuestionView, JoinTeamView, \
MyParticipationDetailView, MyTeamDetailView, ParticipationDetailView, PhaseUpdateView, \
SetParticipationReceiveParticipationView, SetParticipationSendParticipationView, TeamAuthorizationsView, \
TeamDetailView, TeamLeaveView, TeamUpdateView, UpdateQuestionView, UploadVideoView
app_name = "participation"
@ -26,6 +26,7 @@ urlpatterns = [
name="participation_send_participation"),
path("detail/<int:pk>/add-question/", CreateQuestionView.as_view(), name="add_question"),
path("update-question/<int:pk>/", UpdateQuestionView.as_view(), name="update_question"),
path("delete-question/<int:pk>/", DeleteQuestionView.as_view(), name="delete_question"),
path("calendar/", CalendarView.as_view(), name="calendar"),
path("calendar/<int:pk>/", PhaseUpdateView.as_view(), name="update_phase"),
path("chat/", TemplateView.as_view(template_name="participation/chat.html"), name="chat")

View File

@ -13,8 +13,7 @@ from django.shortcuts import redirect
from django.template.loader import render_to_string
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, DetailView, FormView, RedirectView, UpdateView
from django.views.generic.base import TemplateView
from django.views.generic import CreateView, DeleteView, DetailView, FormView, RedirectView, TemplateView, UpdateView
from django.views.generic.edit import FormMixin, ProcessFormView
from django_tables2 import SingleTableView
from magic import Magic
@ -430,6 +429,27 @@ class UpdateQuestionView(LoginRequiredMixin, UpdateView):
return reverse_lazy("participation:participation_detail", args=(self.object.participation.pk,))
class DeleteQuestionView(LoginRequiredMixin, DeleteView):
"""
Remove a question.
"""
model = Question
def dispatch(self, request, *args, **kwargs):
self.object = self.get_object()
if not request.user.is_authenticated:
return self.handle_no_permission()
if request.user.registration.is_admin or \
request.user.registration.participates and \
request.user.registration.team.pk == self.object.participation.team_id:
return super().dispatch(request, *args, **kwargs)
raise PermissionDenied
def get_success_url(self):
return reverse_lazy("participation:participation_detail", args=(self.object.participation.pk,))
class UploadVideoView(LoginRequiredMixin, UpdateView):
"""
Upload a solution video for a team.