Merge branch 'improvements' into 'master'

Questions can be seen during the third phase

See merge request animath/si/plateforme-corres2math!11
This commit is contained in:
Yohann D'ANELLO 2021-01-08 12:42:44 +00:00
commit 4c9e63be3d
3 changed files with 30 additions and 16 deletions

View File

@ -288,7 +288,7 @@ class Phase(models.Model):
)
@classmethod
def current_phase(cls):
def current_phase(cls) -> "Phase":
"""
Retrieve the current phase of this day
"""

View File

@ -194,13 +194,14 @@
{% trans "This video platform is not supported yet." as unsupported_platform %}
{% include "base_modal.html" with modal_id="displayOtherSolution" modal_action="" modal_button="" modal_additional_class="modal-lg" modal_content=participation.received_participation.solution.as_iframe|default:unsupported_platform %}
{% endif %}
{% endif %}
{% if user.registration.participates and current_phase.phase_number == 2 %}
{% trans "Add question" as modal_title %}
{% trans "Add" as modal_button %}
{% url "participation:add_question" pk=participation.pk as modal_action %}
{% include "base_modal.html" with modal_id="addQuestion" modal_button_type="success" %}
{% if current_phase.phase_number == 2 %}
{% trans "Add question" as modal_title %}
{% trans "Add" as modal_button %}
{% url "participation:add_question" pk=participation.pk as modal_action %}
{% include "base_modal.html" with modal_id="addQuestion" modal_button_type="success" %}
{% endif %}
{% for question in participation.questions.all %}
{% with number_str=forloop.counter|stringformat:"d"%}
{% with modal_id="updateQuestion"|add:number_str %}
@ -260,27 +261,29 @@
});
{% endif %}
{% if user.registration.participates and current_phase.phase_number == 2 %}
{% if current_phase.phase_number == 2 %}
$('button[data-target="#addQuestionModal"]').click(function() {
let modalBody = $("#addQuestionModal div.modal-body");
if (!modalBody.html().trim())
modalBody.load("{% url "participation:add_question" pk=participation.pk %} #form-content");
});
{% endif %}
{% for question in participation.questions.all %}
$('button[data-target="#updateQuestion{{ forloop.counter }}Modal"]').click(function() {
let modalBody = $("#updateQuestion{{ forloop.counter }}Modal div.modal-body");
if (!modalBody.html().trim())
modalBody.load("{% url "participation:update_question" pk=question.pk %} #form-content");
});
{% for question in participation.questions.all %}
$('button[data-target="#updateQuestion{{ forloop.counter }}Modal"]').click(function() {
let modalBody = $("#updateQuestion{{ forloop.counter }}Modal div.modal-body");
if (!modalBody.html().trim())
modalBody.load("{% url "participation:update_question" pk=question.pk %} #form-content");
});
{% if current_phase.phase_number == 2 %}
$('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 %}
{% endif %}
{% endfor %}
$('button[data-target="#uploadSolutionModal"]').click(function() {
let modalBody = $("#uploadSolutionModal div.modal-body");

View File

@ -477,6 +477,12 @@ class UpdateQuestionView(LoginRequiredMixin, UpdateView):
return super().dispatch(request, *args, **kwargs)
raise PermissionDenied
def form_valid(self, form):
if not self.request.user.registration.is_admin and Phase.current_phase().phase_number != 2:
form.add_error(None, _("You can update your questions now."))
return self.form_invalid(form)
return super().form_valid(form)
def get_success_url(self):
return reverse_lazy("participation:participation_detail", args=(self.object.participation.pk,))
@ -499,6 +505,11 @@ class DeleteQuestionView(LoginRequiredMixin, DeleteView):
return super().dispatch(request, *args, **kwargs)
raise PermissionDenied
def delete(self, request, *args, **kwargs):
if not request.user.registration.is_admin and Phase.current_phase().phase_number != 2:
raise PermissionDenied(_("You can update your questions now."))
return super().delete(request, *args, **kwargs)
def get_success_url(self):
return reverse_lazy("participation:participation_detail", args=(self.object.participation.pk,))