From 4c2dd9e98c2b9c646c498da38270cea243a653a5 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Wed, 13 Nov 2024 10:56:45 +0100 Subject: [PATCH] =?UTF-8?q?Suppression=20des=20questions=20de=20migration?= =?UTF-8?q?=20pas=20utilis=C3=A9es=20(branche=20=C3=A0=20part)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/forms.py | 42 ------- ...erationanswer_delete_moderationquestion.py | 19 +++ src/agenda_culturel/models.py | 110 ----------------- .../agenda_culturel/edit-buttons-inc.html | 1 - .../moderationanswer_confirm_delete.html | 20 --- .../moderationanswer_form.html | 31 ----- .../moderationquestion_confirm_delete.html | 20 --- .../moderationquestion_detail.html | 71 ----------- .../moderationquestion_form.html | 23 ---- .../moderationquestion_list.html | 71 ----------- .../templates/agenda_culturel/side-nav.html | 8 -- src/agenda_culturel/urls.py | 35 ------ src/agenda_culturel/views.py | 116 ------------------ 13 files changed, 19 insertions(+), 548 deletions(-) create mode 100644 src/agenda_culturel/migrations/0109_delete_moderationanswer_delete_moderationquestion.py delete mode 100644 src/agenda_culturel/templates/agenda_culturel/moderationanswer_confirm_delete.html delete mode 100644 src/agenda_culturel/templates/agenda_culturel/moderationanswer_form.html delete mode 100644 src/agenda_culturel/templates/agenda_culturel/moderationquestion_confirm_delete.html delete mode 100644 src/agenda_culturel/templates/agenda_culturel/moderationquestion_detail.html delete mode 100644 src/agenda_culturel/templates/agenda_culturel/moderationquestion_form.html delete mode 100644 src/agenda_culturel/templates/agenda_culturel/moderationquestion_list.html diff --git a/src/agenda_culturel/forms.py b/src/agenda_culturel/forms.py index 4c081c8..2242c47 100644 --- a/src/agenda_culturel/forms.py +++ b/src/agenda_culturel/forms.py @@ -20,8 +20,6 @@ from .models import ( Event, RecurrentImport, CategorisationRule, - ModerationAnswer, - ModerationQuestion, Place, Category, ) @@ -417,46 +415,6 @@ class MergeDuplicates(Form): return None -class ModerationQuestionForm(ModelForm): - class Meta: - model = ModerationQuestion - fields = "__all__" - - -class ModerationAnswerForm(ModelForm): - class Meta: - model = ModerationAnswer - exclude = ["question"] - widgets = { - "adds_tags": DynamicArrayWidgetTags(), - "removes_tags": DynamicArrayWidgetTags(), - } - - -class ModerateForm(ModelForm): - class Meta: - model = Event - fields = [] - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - - mqs = ModerationQuestion.objects.all() - mas = ModerationAnswer.objects.all() - - for q in mqs: - self.fields[q.complete_id()] = ChoiceField( - widget=RadioSelect, - label=q.question, - choices=[(a.pk, a.html_description()) for a in mas if a.question == q], - required=True, - ) - for a in mas: - if a.question == q and a.valid_event(self.instance): - self.fields[q.complete_id()].initial = a.pk - break - - class CategorisationForm(Form): def __init__(self, *args, **kwargs): if "events" in kwargs: diff --git a/src/agenda_culturel/migrations/0109_delete_moderationanswer_delete_moderationquestion.py b/src/agenda_culturel/migrations/0109_delete_moderationanswer_delete_moderationquestion.py new file mode 100644 index 0000000..e7e7e68 --- /dev/null +++ b/src/agenda_culturel/migrations/0109_delete_moderationanswer_delete_moderationquestion.py @@ -0,0 +1,19 @@ +# Generated by Django 4.2.9 on 2024-11-13 09:56 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('agenda_culturel', '0108_remove_duplicated_categories'), + ] + + operations = [ + migrations.DeleteModel( + name='ModerationAnswer', + ), + migrations.DeleteModel( + name='ModerationQuestion', + ), + ] diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 26e69de..1f08f56 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -1826,113 +1826,3 @@ class CategorisationRule(models.Model): return True -class ModerationQuestion(models.Model): - question = models.CharField( - verbose_name=_("Question"), - help_text=_("Text that will be shown to moderators"), - max_length=512, - unique=True, - ) - - class Meta: - verbose_name = _("Moderation question") - verbose_name_plural = _("Moderation questions") - permissions = [ - ("use_moderation_question", "Can use a moderation question to tag an event") - ] - - def __str__(self): - char_limit = 30 - return ( - (self.question[:char_limit] + "...") - if char_limit < len(self.question) - else self.question - ) - - def get_absolute_url(self): - return reverse("view_mquestion", kwargs={"pk": self.pk}) - - def complete_id(self): - return "question_" + str(self.pk) - - -class ModerationAnswer(models.Model): - question = models.ForeignKey( - ModerationQuestion, - related_name="answers", - verbose_name=_("Question"), - help_text=_("Associated question from moderation"), - on_delete=models.CASCADE, - ) - - answer = models.CharField( - verbose_name=_("Answer"), - help_text=_("Text that will be shown to moderators"), - max_length=512, - ) - - adds_tags = ArrayField( - models.CharField(max_length=64), - verbose_name=_("Adds tags"), - help_text=_("A list of tags that will be added if you choose this answer."), - blank=True, - null=True, - ) - removes_tags = ArrayField( - models.CharField(max_length=64), - verbose_name=_("Removes tags"), - help_text=_("A list of tags that will be removed if you choose this answer."), - blank=True, - null=True, - ) - - def complete_id(self): - return "answer_" + str(self.question.pk) + "_" + str(self.pk) - - def html_description(self): - result = self.answer + '
' - if self.adds_tags: - result += " ".join( - [ - '' + a + "" - for a in self.adds_tags - ] - ) - if self.removes_tags: - result += " ".join( - [ - '' + a + "" - for a in self.removes_tags - ] - ) - result += "" - return mark_safe(result) - - def valid_event(self, event): - if event.tags: - if self.adds_tags: - for t in self.adds_tags: - if t not in event.tags: - return False - - if self.removes_tags: - for t in self.removes_tags: - if t in event.tags: - return False - - return True - else: - return not self.adds_tags or len(self.adds_tags) == 0 - - def apply_answer(self, event): - if not self.adds_tags: - self.adds_tags = [] - if not self.removes_tags: - self.removes_tags = [] - - if event.tags: - event.tags = list( - (set(event.tags) | set(self.adds_tags)) - set(self.removes_tags) - ) - else: - event.tags = self.adds_tags diff --git a/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html b/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html index 389eac5..3c0c9da 100644 --- a/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html +++ b/src/agenda_culturel/templates/agenda_culturel/edit-buttons-inc.html @@ -1,7 +1,6 @@ {% load utils_extra %} - {% if event.pure_import %} {% with event.get_local_version as local %} {% if local %} diff --git a/src/agenda_culturel/templates/agenda_culturel/moderationanswer_confirm_delete.html b/src/agenda_culturel/templates/agenda_culturel/moderationanswer_confirm_delete.html deleted file mode 100644 index 86f533f..0000000 --- a/src/agenda_culturel/templates/agenda_culturel/moderationanswer_confirm_delete.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends "agenda_culturel/page-admin.html" %} - -{% block title %}{% block og_title %}Supprimer la réponse #{{ object.pk }}{% endblock %}{% endblock %} - -{% block fluid %}{% endblock %} - -{% block content %} - -

Suppression de la réponse de modération {{ object.pk }}

-
{% csrf_token %} -

Êtes-vous sûr·e de vouloir supprimer la réponse de modération #{{object.pk}} « {{ object.answer }} » associée à la question « {{ object.question.question }} » ? -

- {{ form }} -
- Annuler - -
-
- -{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/moderationanswer_form.html b/src/agenda_culturel/templates/agenda_culturel/moderationanswer_form.html deleted file mode 100644 index 7d7bd58..0000000 --- a/src/agenda_culturel/templates/agenda_culturel/moderationanswer_form.html +++ /dev/null @@ -1,31 +0,0 @@ -{% extends "agenda_culturel/page-admin.html" %} -{% load static %} - -{% block title %}{% block og_title %}{% if form.instance.pk %}Modification{% else %}Création{% endif %} d'une réponse de modération{% endblock %}{% endblock %} - -{% block entete_header %} - - - - - - -{% endblock %} - - -{% block content %} - -

{% if form.instance.pk %}Modification{% else %}Création{% endif %} d'une réponse de modération

-

{% if form.instance.pk %}Modifier{% else %}Ajouter{% endif %} une réponse à la question « {{ question }} »

- -
-
{% csrf_token %} - {{ form.as_p }} -
- Annuler - -
-
-
- -{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/moderationquestion_confirm_delete.html b/src/agenda_culturel/templates/agenda_culturel/moderationquestion_confirm_delete.html deleted file mode 100644 index 2839b97..0000000 --- a/src/agenda_culturel/templates/agenda_culturel/moderationquestion_confirm_delete.html +++ /dev/null @@ -1,20 +0,0 @@ -{% extends "agenda_culturel/page-admin.html" %} - -{% block title %}{% block og_title %}Supprimer la question #{{ object.pk }}{% endblock %}{% endblock %} - -{% block fluid %}{% endblock %} - -{% block content %} - -

Suppression de la question de modération {{ object.pk }}

-
{% csrf_token %} -

Êtes-vous sûr·e de vouloir supprimer la question de modération #{{object.pk}} « {{ object.question }} » ainsi que les réponses associées ? -

- {{ form }} -
- Annuler - -
-
- -{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/moderationquestion_detail.html b/src/agenda_culturel/templates/agenda_culturel/moderationquestion_detail.html deleted file mode 100644 index a6fecac..0000000 --- a/src/agenda_culturel/templates/agenda_culturel/moderationquestion_detail.html +++ /dev/null @@ -1,71 +0,0 @@ -{% extends "agenda_culturel/page-admin.html" %} - -{% block title %}{% block og_title %}Question de modération #{{ object.pk }}{% endblock %}{% endblock %} - -{% load tag_extra %} -{% load utils_extra %} -{% load cat_extra %} - -{% block entete_header %} - {% css_categories %} -{% endblock %} - - -{% block sidemenu-bouton %} -
  • {% picto_from_name "chevron-up" %}
  • -
  • {% picto_from_name "chevron-down" %}
  • -{% endblock %} - -{% block content %} -
    -
    -
    - < Retour - -

    Question de modération #{{ object.pk }}

    -

    {{ object.question }}

    -
    - - {% if object.answers %} - {% for answer in object.answers.all %} -
    - -
    -

    Réponse #{{ answer.pk }} : « {{ answer.answer }} »

    - {% if answer.adds_tags %} -

    Cette réponse ajoute les étiquettes suivantes à l'événement : - {% for tag in answer.adds_tags %} - {{ tag | tag_button }} - {% endfor %} -

    - {% else %} -

    Cette réponse n'ajoute pas d'étiquette à l'événement.

    - {% endif %} - {% if answer.removes_tags %} -

    Cette réponse supprimer les étiquettes suivantes à l'événement : - {% for tag in answer.removes_tags %} - {{ tag | tag_button }} - {% endfor %} -

    - {% else %} -

    Cette réponse ne supprime pas d'étiquette à l'événement.

    - {% endif %} -
    -
    - {% endfor %} - {% else %} - Il n'y a pas encore de réponse associée à cette question. - {% endif %} -
    - -{% include "agenda_culturel/side-nav.html" with current="moderationquestions" %} -
    - -{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/moderationquestion_form.html b/src/agenda_culturel/templates/agenda_culturel/moderationquestion_form.html deleted file mode 100644 index 04543af..0000000 --- a/src/agenda_culturel/templates/agenda_culturel/moderationquestion_form.html +++ /dev/null @@ -1,23 +0,0 @@ -{% extends "agenda_culturel/page-admin.html" %} -{% load static %} - - -{% block title %}{% block og_title %} -{% if form.instance.pk %}Modification{% else %}Création{% endif %} d'une question de modération -{% endblock %}{% endblock %} - - -{% block content %} - -

    {% if form.instance.pk %}Modification{% else %}Création{% endif %} d'une question de modération

    -
    -
    {% csrf_token %} - {{ form.as_p }} -
    - Annuler - -
    -
    -
    - -{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/moderationquestion_list.html b/src/agenda_culturel/templates/agenda_culturel/moderationquestion_list.html deleted file mode 100644 index 1c38275..0000000 --- a/src/agenda_culturel/templates/agenda_culturel/moderationquestion_list.html +++ /dev/null @@ -1,71 +0,0 @@ -{% extends "agenda_culturel/page-admin.html" %} - -{% block title %}{% block og_title %}Questions de modération{% endblock %}{% endblock %} - -{% load utils_extra %} -{% load cat_extra %} -{% block entete_header %} - {% css_categories %} -{% endblock %} - -{% block sidemenu-bouton %} -
  • {% picto_from_name "chevron-up" %}
  • -
  • {% picto_from_name "chevron-down" %}
  • -{% endblock %} - -{% block content %} -
    -
    -
    - Ajouter {% picto_from_name "plus-circle" %} -

    Questions de modération

    -
    - {% if object_list %} - {% for question in object_list %} -
    -
    - Détails... -

    Question #{{ question.pk }} : {{ question.question }}

    -

    {% if question.answers %} -

    réponses possibles :

    -
      - {% for answer in question.answers.all %} -
    • {{ answer.answer }}
    • - {% endfor %} -
    - {% else %} -

    aucune réponse définie

    - {% endif %} -

    -
    - -
    - {% endfor %} - {% else %} -

    Il n'y a aucune question définie.

    - {% endif %} -
    - - {% if page_obj.has_previous %} - « premier - précédent - {% endif %} - - - Page {{ page_obj.number }} sur {{ page_obj.paginator.num_pages }} - - - {% if page_obj.has_next %} - suivant - dernier » - {% endif %} - -
    - -
    - - -{% include "agenda_culturel/side-nav.html" with current="moderationquestions" %} -
    - -{% endblock %} \ No newline at end of file diff --git a/src/agenda_culturel/templates/agenda_culturel/side-nav.html b/src/agenda_culturel/templates/agenda_culturel/side-nav.html index 3e74b88..7af6ff7 100644 --- a/src/agenda_culturel/templates/agenda_culturel/side-nav.html +++ b/src/agenda_culturel/templates/agenda_culturel/side-nav.html @@ -60,14 +60,6 @@ {% endif %} - {% if perms.agenda_culturel.view_moderationquestion %} - - {% endif %} {% if user.is_staff %}

    Configuration interne