From a371b84d45306070bbe0dd988135f54fa57b3c28 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Tue, 19 Dec 2023 11:38:51 +0100 Subject: [PATCH] Add code field --- lemarche/conversations/admin.py | 4 ++-- .../migrations/0012_templatetransactional.py | 6 ++++++ lemarche/conversations/models.py | 5 ++++- lemarche/conversations/tests.py | 10 ++++++---- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lemarche/conversations/admin.py b/lemarche/conversations/admin.py index 0de55034e..08d622874 100644 --- a/lemarche/conversations/admin.py +++ b/lemarche/conversations/admin.py @@ -135,6 +135,6 @@ def data_display(self, conversation: Conversation = None): @admin.register(TemplateTransactional, site=admin_site) class TemplateTransactionalAdmin(admin.ModelAdmin): list_display = ["id", "name", "mailjet_id", "brevo_id", "source", "is_active", "created_at", "updated_at"] - search_fields = ["id", "name", "mailjet_id", "brevo_id"] + search_fields = ["id", "name", "code", "mailjet_id", "brevo_id"] - readonly_fields = ["created_at", "updated_at"] + readonly_fields = ["code", "created_at", "updated_at"] diff --git a/lemarche/conversations/migrations/0012_templatetransactional.py b/lemarche/conversations/migrations/0012_templatetransactional.py index 50b08bc56..3cc677ba4 100644 --- a/lemarche/conversations/migrations/0012_templatetransactional.py +++ b/lemarche/conversations/migrations/0012_templatetransactional.py @@ -15,6 +15,12 @@ class Migration(migrations.Migration): fields=[ ("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), ("name", models.CharField(max_length=255, verbose_name="Nom")), + ( + "code", + models.CharField( + blank=True, db_index=True, max_length=255, null=True, unique=True, verbose_name="Nom technique" + ), + ), ("description", models.TextField(blank=True, verbose_name="Description")), ( "mailjet_id", diff --git a/lemarche/conversations/models.py b/lemarche/conversations/models.py index 7b270d768..a9b9e004a 100644 --- a/lemarche/conversations/models.py +++ b/lemarche/conversations/models.py @@ -188,6 +188,9 @@ def set_validated(self): class TemplateTransactional(models.Model): name = models.CharField(verbose_name="Nom", max_length=255) + code = models.CharField( + verbose_name="Nom technique", max_length=255, unique=True, db_index=True, blank=True, null=True + ) description = models.TextField(verbose_name="Description", blank=True) mailjet_id = models.IntegerField( verbose_name="Identifiant Mailjet", unique=True, db_index=True, blank=True, null=True @@ -211,7 +214,7 @@ def __str__(self): @property def get_template_id(self): - if self.is_active and self.source: + if self.is_active and self.source and self.code: if self.source == conversation_constants.SOURCE_MAILJET: return self.mailjet_id elif self.source == conversation_constants.SOURCE_BREVO: diff --git a/lemarche/conversations/tests.py b/lemarche/conversations/tests.py index a2738a7c0..4a0ee290a 100644 --- a/lemarche/conversations/tests.py +++ b/lemarche/conversations/tests.py @@ -71,14 +71,16 @@ class TemplateTransactionalModelTest(TestCase): @classmethod def setUpTestData(cls): cls.tt_inactive = TemplateTransactional( - mailjet_id=10, brevo_id=11, source=conversation_constants.SOURCE_MAILJET, is_active=False + code="EMAIL_1", mailjet_id=10, brevo_id=11, source=conversation_constants.SOURCE_MAILJET, is_active=False + ) + cls.tt_active_empty = TemplateTransactional( + code="EMAIL_2", source=conversation_constants.SOURCE_MAILJET, is_active=False ) - cls.tt_active_empty = TemplateTransactional(source=conversation_constants.SOURCE_MAILJET, is_active=False) cls.tt_active_mailjet = TemplateTransactional( - mailjet_id=30, brevo_id=31, source=conversation_constants.SOURCE_MAILJET, is_active=True + code="EMAIL_3", mailjet_id=30, brevo_id=31, source=conversation_constants.SOURCE_MAILJET, is_active=True ) cls.tt_active_brevo = TemplateTransactional( - mailjet_id=40, brevo_id=41, source=conversation_constants.SOURCE_BREVO, is_active=True + code="EMAIL_4", mailjet_id=40, brevo_id=41, source=conversation_constants.SOURCE_BREVO, is_active=True ) def test_get_template_id(self):