Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(quizs): allow an admin to add a comment #2014

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: quiz-anthropocene\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-29 13:26+0200\n"
"POT-Creation-Date: 2024-05-29 15:34+0200\n"
"PO-Revision-Date: 2024-03-28 17:14\n"
"Last-Translator: Didier Quirin <[email protected]>\n"
"Language-Team: German\n"
Expand Down Expand Up @@ -975,6 +975,9 @@ msgstr "Keine"
msgid "All the questions "
msgstr "Alle Fragen "

msgid "If you want to <strong>reply</strong> to one of the comments above, click on <strong>View</strong>."
msgstr ""

msgid "You are the <strong>author</strong> of this quiz"
msgstr "Sie sind der <strong>Autor</strong> dieses Quiz"

Expand Down
5 changes: 4 additions & 1 deletion locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-29 13:26+0200\n"
"POT-Creation-Date: 2024-05-29 15:34+0200\n"
"PO-Revision-Date: 2023-02-12 20:12+0100\n"
"Last-Translator: Didier Quirin <[email protected]>\n"
"Language-Team: \n"
Expand Down Expand Up @@ -975,6 +975,9 @@ msgstr ""
msgid "All the questions "
msgstr ""

msgid "If you want to <strong>reply</strong> to one of the comments above, click on <strong>View</strong>."
msgstr ""

msgid "You are the <strong>author</strong> of this quiz"
msgstr ""

Expand Down
5 changes: 4 additions & 1 deletion locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: quiz-anthropocene\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-29 13:26+0200\n"
"POT-Creation-Date: 2024-05-29 15:34+0200\n"
"PO-Revision-Date: 2024-03-28 17:14\n"
"Last-Translator: Didier Quirin <[email protected]>\n"
"Language-Team: Spanish\n"
Expand Down Expand Up @@ -975,6 +975,9 @@ msgstr "Ninguna"
msgid "All the questions "
msgstr "Todas las preguntas "

msgid "If you want to <strong>reply</strong> to one of the comments above, click on <strong>View</strong>."
msgstr ""

msgid "You are the <strong>author</strong> of this quiz"
msgstr ""

Expand Down
5 changes: 4 additions & 1 deletion locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: quiz-anthropocene\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-29 13:26+0200\n"
"POT-Creation-Date: 2024-05-29 15:34+0200\n"
"PO-Revision-Date: 2024-03-28 17:14\n"
"Last-Translator: Didier Quirin <[email protected]>\n"
"Language-Team: French\n"
Expand Down Expand Up @@ -975,6 +975,9 @@ msgstr "Aucun"
msgid "All the questions "
msgstr "Toutes les questions "

msgid "If you want to <strong>reply</strong> to one of the comments above, click on <strong>View</strong>."
msgstr ""

msgid "You are the <strong>author</strong> of this quiz"
msgstr "Vous êtes <strong>l'auteur</strong> de ce quiz"

Expand Down
5 changes: 4 additions & 1 deletion locale/it/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ msgid ""
msgstr ""
"Project-Id-Version: quiz-anthropocene\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-05-29 13:26+0200\n"
"POT-Creation-Date: 2024-05-29 15:34+0200\n"
"PO-Revision-Date: 2024-03-28 17:14\n"
"Last-Translator: Didier Quirin <[email protected]>\n"
"Language-Team: Italian\n"
Expand Down Expand Up @@ -975,6 +975,9 @@ msgstr "Nessuno"
msgid "All the questions "
msgstr "Tutte le domande "

msgid "If you want to <strong>reply</strong> to one of the comments above, click on <strong>View</strong>."
msgstr ""

msgid "You are the <strong>author</strong> of this quiz"
msgstr "Sei l'autore <strong></strong> di questo quiz"

Expand Down
2 changes: 1 addition & 1 deletion templates/questions/detail_comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block question_detail_content %}
<div class="row">
<div class="col-12">
{% if not question_contributions.count %}
{% if not table.rows|length %}
<div class="alert alert-warning" role="status">0 {% translate "Comments" %}</div>
{% else %}
{% render_table table %}
Expand Down
2 changes: 1 addition & 1 deletion templates/questions/detail_quizs.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% block question_detail_content %}
<div class="row">
<div class="col-12">
{% if not question_quizs.count %}
{% if not table.rows|length %}
<div class="alert alert-warning" role="status">0 {% translate "Quizs" %}</div>
{% else %}
{% render_table table %}
Expand Down
43 changes: 32 additions & 11 deletions templates/quizs/detail_comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,44 @@
{% block quiz_detail_content %}
<div class="row">
<div class="col-12">
{% render_table table %}
{% if not table.rows|length %}
<div class="alert alert-warning" role="status">0 {% translate "Comments" %}</div>
{% else %}
{% render_table table %}
{% endif %}
</div>
</div>

<br />
<br />

<div class="row">
<div class="col-12">
<!-- Comment form -->
<div class="card">
<div class="card-header">
<strong>Ajouter un commentaire</strong>
<strong>{% translate "Add a note" %}</strong>
</div>
<div class="card-body">
<div class="alert alert-warning" role="status">
Formulaire pour <strong>ajouter</strong> un commentaire à ce quiz.
{% if table.rows.count %}
<br />
Si vous souhaitez <strong>répondre</strong> à un commentaire au dessus, cliquez sur "Voir".
{% endif %}
</div>
<p><i>à venir</i></p>
{% if table.rows|length %}
<div class="alert alert-warning" role="status">
{% blocktrans %}If you want to <strong>reply</strong> to one of the comments above, click on <strong>View</strong>.{% endblocktrans %}
</div>
{% endif %}
<form id="comment_create_form" method="POST" action="">
{% csrf_token %}

<div class="row">
<div class="col-md-8">
{% bootstrap_form form alert_error_type="all" %}
</div>
</div>

<div class="row">
<div class="col">
{% bootstrap_button button_type="submit" button_class="btn-primary" content=_("Add") %}
</div>
</div>
</form>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion templates/quizs/detail_questions.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% block quiz_detail_content %}
<div class="row">
<div class="col-12">
{% if not quiz_questions.count %}
{% if not table.rows|length %}
<div class="alert alert-warning" role="status">0 {% translate "Questions" %}</div>
{% else %}
{% render_table table %}
Expand Down
1 change: 0 additions & 1 deletion www/questions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def get_table_data(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["question"] = self.question
context["question_quizs"] = self.question.quizquestion_set.all()
return context


Expand Down
43 changes: 39 additions & 4 deletions www/quizs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
from django.utils import timezone
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, DetailView, FormView, UpdateView
from django.views.generic import CreateView, DetailView, FormView, ListView, UpdateView
from django.views.generic.edit import FormMixin
from django_filters.views import FilterView
from django_tables2.views import SingleTableMixin, SingleTableView
from django_tables2.views import SingleTableMixin

from activity.utilities import create_event
from api.quizs.serializers import QuizWithQuestionFullStringSerializer
from contributions.forms import CommentCreateForm
from contributions.models import Comment
from contributions.tables import CommentTable
from core import constants
from core.forms import form_filters_cleaned_dict, form_filters_to_list
from core.mixins import ContributorUserRequiredMixin
from core.utils.s3 import S3Upload
Expand Down Expand Up @@ -148,7 +151,6 @@ def get_table_data(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["quiz"] = self.quiz
context["quiz_questions"] = self.quiz.quizquestion_set.all()
context["user_can_edit"] = self.request.user.can_edit_quiz(self.quiz)
if self.request.POST and context["user_can_edit"]:
context["quiz_question_formset"] = QuizQuestionFormSet(self.request.POST, instance=self.quiz)
Expand Down Expand Up @@ -180,11 +182,12 @@ def get_success_url(self):
return reverse_lazy("quizs:detail_view", args=[self.kwargs.get("pk")])


class QuizDetailCommentListView(ContributorUserRequiredMixin, SingleTableView):
class QuizDetailCommentListView(ContributorUserRequiredMixin, SingleTableMixin, FormMixin, ListView):
model = Comment
template_name = "quizs/detail_comments.html"
context_object_name = "quiz_contributions"
table_class = CommentTable
form_class = CommentCreateForm

def get_queryset(self):
qs = super().get_queryset()
Expand All @@ -197,6 +200,38 @@ def get_context_data(self, **kwargs):
context["quiz"] = Quiz.objects.get(id=self.kwargs.get("pk"))
return context

def get_initial(self):
return {
"type": constants.COMMENT_TYPE_COMMENT_CONTRIBUTOR,
"quiz": self.kwargs.get("pk"),
"status": constants.COMMENT_STATUS_PROCESSED,
"author": self.request.user,
"parent": None,
}

def post(self, request, *args, **kwargs):
form_class = self.get_form_class()
form = self.get_form(form_class)
if form.is_valid():
return self.form_valid(form)
else:
return self.form_invalid(form)

def form_valid(self, form):
form.save()
# response
messages.add_message(self.request, messages.SUCCESS, self.get_success_message(form.cleaned_data))
return HttpResponseRedirect(self.get_success_url())

def form_invalid(self, form):
return self.render_to_response(self.get_context_data())

def get_success_message(self, cleaned_data):
return _("Your message was created.")

def get_success_url(self):
return reverse_lazy("quizs:detail_comments", args=[self.kwargs.get("pk")])


class QuizDetailStatsView(ContributorUserRequiredMixin, DetailView):
model = QuizAggStat
Expand Down
Loading