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

Question & Quiz : homogénéiser les validation_status #1942

Merged
merged 3 commits into from
Feb 19, 2023
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
2 changes: 1 addition & 1 deletion api/quizs/test_quiz_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUpTestData(cls):
text="question 1",
category=cls.category_1,
author=cls.user_1,
validation_status=constants.VALIDATION_STATUS_IN_PROGRESS,
validation_status=constants.VALIDATION_STATUS_TO_VALIDATE,
)
cls.question_2 = QuestionFactory(
text="question 2",
Expand Down
2 changes: 1 addition & 1 deletion api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUpTestData(cls):
text="question 1",
category=cls.category_1,
author=cls.user_1,
validation_status=constants.VALIDATION_STATUS_IN_PROGRESS,
validation_status=constants.VALIDATION_STATUS_TO_VALIDATE,
)
cls.question_2 = QuestionFactory(
text="question 2",
Expand Down
2 changes: 1 addition & 1 deletion api/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_published_quiz_can_have_not_validated_questions(self):
self.question_validated = QuestionFactory(answer_correct="a")
self.question_not_validated = QuestionFactory(
answer_correct="a",
validation_status=constants.VALIDATION_STATUS_IN_PROGRESS,
validation_status=constants.VALIDATION_STATUS_TO_VALIDATE,
)
self.quiz_published = QuizFactory(name="quiz published", publish=True)
self.quiz_not_published = QuizFactory(name="quiz not published")
Expand Down
24 changes: 12 additions & 12 deletions core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@
"traduction",
]

VALIDATION_STATUS_NEW = "Brouillon"
VALIDATION_STATUS_IN_PROGRESS = "A valider"
VALIDATION_STATUS_OK = "Validée"
VALIDATION_STATUS_ASIDE = "Écartée temporairement"
VALIDATION_STATUS_REMOVED = "Écartée"
VALIDATION_STATUS_CHOICE_LIST = [
VALIDATION_STATUS_NEW,
VALIDATION_STATUS_IN_PROGRESS,
VALIDATION_STATUS_OK,
VALIDATION_STATUS_ASIDE,
VALIDATION_STATUS_REMOVED,
VALIDATION_STATUS_DRAFT = "DRAFT"
VALIDATION_STATUS_TO_VALIDATE = "TO_VALIDATE"
VALIDATION_STATUS_VALIDATED = "VALIDATED"
VALIDATION_STATUS_ASIDE = "ASIDE"
VALIDATION_STATUS_REMOVED = "REMOVED"
VALIDATION_STATUS_CHOICES = [
(VALIDATION_STATUS_DRAFT, _("Draft")),
(VALIDATION_STATUS_TO_VALIDATE, _("To validate")),
(VALIDATION_STATUS_VALIDATED, _("Validated")),
(VALIDATION_STATUS_ASIDE, _("Set aside")),
(VALIDATION_STATUS_REMOVED, _("Removed")),
]
VALIDATION_STATUS_CHOICES = [(vs, vs) for vs in VALIDATION_STATUS_CHOICE_LIST]
VALIDATION_STATUS_CHOICE_LIST = [vs[0] for vs in VALIDATION_STATUS_CHOICES]

CONTRIBUTION_TYPE_NEW_QUESTION = "NEW_QUESTION"
CONTRIBUTION_TYPE_NEW_QUIZ = "NEW_QUIZ"
Expand Down
22 changes: 21 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: 2023-02-18 22:24+0100\n"
"POT-Creation-Date: 2023-02-19 10:29+0100\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 @@ -59,6 +59,26 @@ msgstr ""
msgid "Expert"
msgstr ""

#: core/constants.py:65
msgid "Draft"
msgstr ""

#: core/constants.py:66
msgid "To validate"
msgstr ""

#: core/constants.py:67
msgid "Validated"
msgstr ""

#: core/constants.py:68
msgid "Set aside"
msgstr ""

#: core/constants.py:69
msgid "Removed"
msgstr ""

#: core/constants.py:116
msgid "German"
msgstr ""
Expand Down
Binary file modified locale/fr/LC_MESSAGES/django.mo
Binary file not shown.
24 changes: 22 additions & 2 deletions locale/fr/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-02-18 22:24+0100\n"
"PO-Revision-Date: 2023-02-18 22:24+0100\n"
"POT-Creation-Date: 2023-02-19 10:29+0100\n"
"PO-Revision-Date: 2023-02-19 11:00+0100\n"
"Last-Translator: Didier Quirin <[email protected]>\n"
"Language-Team: \n"
"Language: fr\n"
Expand Down Expand Up @@ -59,6 +59,26 @@ msgstr "Difficule"
msgid "Expert"
msgstr "Expert"

#: core/constants.py:65
msgid "Draft"
msgstr "Brouillon"

#: core/constants.py:66
msgid "To validate"
msgstr "A valider"

#: core/constants.py:67
msgid "Validated"
msgstr "Validé"

#: core/constants.py:68
msgid "Set aside"
msgstr "Écarté temporairement"

#: core/constants.py:69
msgid "Removed"
msgstr "Écarté"

#: core/constants.py:116
msgid "German"
msgstr "Allemand"
Expand Down
2 changes: 1 addition & 1 deletion questions/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class Meta:
answer_choice_a = "La réponse A"
answer_choice_b = "La réponse B"
answer_correct = "a" # constants.QUESTION_ANSWER_CHOICE_LIST[0]
validation_status = constants.VALIDATION_STATUS_OK
validation_status = constants.VALIDATION_STATUS_VALIDATED
33 changes: 33 additions & 0 deletions questions/migrations/0024_question_validation_status_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.1.5 on 2023-02-19 10:30

from django.db import migrations


def migrate_question_validation_status(apps, schema_editor):
Question = apps.get_model("questions", "Question")
Question.objects.filter(validation_status="Brouillon").update(validation_status="DRAFT")
Question.objects.filter(validation_status="A valider").update(validation_status="TO_VALIDATE")
Question.objects.filter(validation_status="Validée").update(validation_status="VALIDATED")
Question.objects.filter(validation_status="Écartée temporairement").update(validation_status="ASIDE")
Question.objects.filter(validation_status="Écartée").update(validation_status="REMOVED")


def migrate_historical_question_validation_status(apps, schema_editor):
HistoricalQuestion = apps.get_model("questions", "HistoricalQuestion")
HistoricalQuestion.objects.filter(validation_status="Brouillon").update(validation_status="DRAFT")
HistoricalQuestion.objects.filter(validation_status="A valider").update(validation_status="TO_VALIDATE")
HistoricalQuestion.objects.filter(validation_status="Validée").update(validation_status="VALIDATED")
HistoricalQuestion.objects.filter(validation_status="Écartée temporairement").update(validation_status="ASIDE")
HistoricalQuestion.objects.filter(validation_status="Écartée").update(validation_status="REMOVED")


class Migration(migrations.Migration):

dependencies = [
("questions", "0023_alter_historicalquestion_difficulty_and_more"),
]

operations = [
migrations.RunPython(migrate_question_validation_status),
migrations.RunPython(migrate_historical_question_validation_status),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 4.1.5 on 2023-02-19 09:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("questions", "0024_question_validation_status_migration"),
]

operations = [
migrations.AlterField(
model_name="historicalquestion",
name="validation_status",
field=models.CharField(
choices=[
("DRAFT", "Draft"),
("TO_VALIDATE", "To validate"),
("VALIDATED", "Validated"),
("ASIDE", "Set aside"),
("REMOVED", "Removed"),
],
default="DRAFT",
max_length=150,
verbose_name="Status",
),
),
migrations.AlterField(
model_name="question",
name="validation_status",
field=models.CharField(
choices=[
("DRAFT", "Draft"),
("TO_VALIDATE", "To validate"),
("VALIDATED", "Validated"),
("ASIDE", "Set aside"),
("REMOVED", "Removed"),
],
default="DRAFT",
max_length=150,
verbose_name="Status",
),
),
]
10 changes: 5 additions & 5 deletions questions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@

class QuestionQuerySet(models.QuerySet):
def validated(self):
return self.filter(validation_status=constants.VALIDATION_STATUS_OK)
return self.filter(validation_status=constants.VALIDATION_STATUS_VALIDATED)

def not_validated(self):
return self.exclude(validation_status=constants.VALIDATION_STATUS_OK)
return self.exclude(validation_status=constants.VALIDATION_STATUS_VALIDATED)

def public(self):
return self.exclude(visibility=constants.VISIBILITY_PRIVATE)
Expand Down Expand Up @@ -219,7 +219,7 @@ class Question(models.Model):
verbose_name=_("Status"),
max_length=150,
choices=constants.VALIDATION_STATUS_CHOICES,
default=constants.VALIDATION_STATUS_NEW,
default=constants.VALIDATION_STATUS_DRAFT,
)
validation_date = models.DateTimeField(verbose_name=_("Validation date"), blank=True, null=True)

Expand Down Expand Up @@ -322,7 +322,7 @@ def is_private(self) -> bool:

@property
def is_validated(self) -> bool:
return self.validation_status == constants.VALIDATION_STATUS_OK
return self.validation_status == constants.VALIDATION_STATUS_VALIDATED

@property
def answer_count_agg(self) -> int:
Expand Down Expand Up @@ -374,7 +374,7 @@ def clean(self):
- https://adamj.eu/tech/2020/01/22/djangos-field-choices-dont-constrain-your-data/
"""
# > only run on validated questions
if self.validation_status == constants.VALIDATION_STATUS_OK:
if self.validation_status == constants.VALIDATION_STATUS_VALIDATED:
# > category rules
if self.category is None:
error_message = (
Expand Down
22 changes: 14 additions & 8 deletions questions/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def setUpTestData(cls):
text="Test",
category=cls.category_1,
# tags=[cls.tag_1, cls.tag_2],
validation_status=constants.VALIDATION_STATUS_NEW,
validation_status=constants.VALIDATION_STATUS_DRAFT,
)
cls.question.tags.set([cls.tag_1, cls.tag_2])

Expand Down Expand Up @@ -140,7 +140,7 @@ def test_history_object_created_on_save(self):

def test_history_diff(self):
self.question.text = "La vraie question"
self.question.validation_status = constants.VALIDATION_STATUS_OK
self.question.validation_status = constants.VALIDATION_STATUS_VALIDATED
self.question.category = self.category_2
self.question.save()
self.assertEqual(self.question.history.count(), 2 + 1)
Expand All @@ -160,14 +160,20 @@ class QuestionModelQuerySetTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.user_contributor = UserFactory()
QuestionFactory(validation_status=constants.VALIDATION_STATUS_OK, visibility=constants.VISIBILITY_PUBLIC)
QuestionFactory(validation_status=constants.VALIDATION_STATUS_OK, visibility=constants.VISIBILITY_HIDDEN)
QuestionFactory(validation_status=constants.VALIDATION_STATUS_OK, visibility=constants.VISIBILITY_PRIVATE)
QuestionFactory(validation_status=constants.VALIDATION_STATUS_NEW, visibility=constants.VISIBILITY_PUBLIC)
QuestionFactory(validation_status=constants.VALIDATION_STATUS_NEW, visibility=constants.VISIBILITY_HIDDEN)
QuestionFactory(
validation_status=constants.VALIDATION_STATUS_VALIDATED, visibility=constants.VISIBILITY_PUBLIC
)
QuestionFactory(
validation_status=constants.VALIDATION_STATUS_VALIDATED, visibility=constants.VISIBILITY_HIDDEN
)
QuestionFactory(
validation_status=constants.VALIDATION_STATUS_VALIDATED, visibility=constants.VISIBILITY_PRIVATE
)
QuestionFactory(validation_status=constants.VALIDATION_STATUS_DRAFT, visibility=constants.VISIBILITY_PUBLIC)
QuestionFactory(validation_status=constants.VALIDATION_STATUS_DRAFT, visibility=constants.VISIBILITY_HIDDEN)
QuestionFactory(
text="xyz",
validation_status=constants.VALIDATION_STATUS_NEW,
validation_status=constants.VALIDATION_STATUS_DRAFT,
visibility=constants.VISIBILITY_PRIVATE,
author=cls.user_contributor,
)
Expand Down
2 changes: 1 addition & 1 deletion quizs/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ class Meta:

name = "Le quiz"
slug = factory.LazyAttribute(lambda o: slugify(o.name))
validation_status = constants.VALIDATION_STATUS_OK
validation_status = constants.VALIDATION_STATUS_VALIDATED
publish = False
33 changes: 33 additions & 0 deletions quizs/migrations/0023_quiz_validation_status_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.1.5 on 2023-02-19 10:30

from django.db import migrations


def migrate_quiz_validation_status(apps, schema_editor):
Quiz = apps.get_model("quizs", "Quiz")
Quiz.objects.filter(validation_status="Brouillon").update(validation_status="DRAFT")
Quiz.objects.filter(validation_status="A valider").update(validation_status="TO_VALIDATE")
Quiz.objects.filter(validation_status="Validée").update(validation_status="VALIDATED")
Quiz.objects.filter(validation_status="Écartée temporairement").update(validation_status="ASIDE")
Quiz.objects.filter(validation_status="Écartée").update(validation_status="REMOVED")


def migrate_historical_quiz_validation_status(apps, schema_editor):
HistoricalQuiz = apps.get_model("quizs", "HistoricalQuiz")
HistoricalQuiz.objects.filter(validation_status="Brouillon").update(validation_status="DRAFT")
HistoricalQuiz.objects.filter(validation_status="A valider").update(validation_status="TO_VALIDATE")
HistoricalQuiz.objects.filter(validation_status="Validée").update(validation_status="VALIDATED")
HistoricalQuiz.objects.filter(validation_status="Écartée temporairement").update(validation_status="ASIDE")
HistoricalQuiz.objects.filter(validation_status="Écartée").update(validation_status="REMOVED")


class Migration(migrations.Migration):

dependencies = [
("quizs", "0022_alter_historicalquiz_language_and_more"),
]

operations = [
migrations.RunPython(migrate_quiz_validation_status),
migrations.RunPython(migrate_historical_quiz_validation_status),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Generated by Django 4.1.5 on 2023-02-19 09:44

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("quizs", "0023_quiz_validation_status_migration"),
]

operations = [
migrations.AlterField(
model_name="historicalquiz",
name="validation_status",
field=models.CharField(
choices=[
("DRAFT", "Draft"),
("TO_VALIDATE", "To validate"),
("VALIDATED", "Validated"),
("ASIDE", "Set aside"),
("REMOVED", "Removed"),
],
default="DRAFT",
max_length=150,
verbose_name="Statut",
),
),
migrations.AlterField(
model_name="quiz",
name="validation_status",
field=models.CharField(
choices=[
("DRAFT", "Draft"),
("TO_VALIDATE", "To validate"),
("VALIDATED", "Validated"),
("ASIDE", "Set aside"),
("REMOVED", "Removed"),
],
default="DRAFT",
max_length=150,
verbose_name="Statut",
),
),
]
Loading