Skip to content

Commit

Permalink
Add code field
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Dec 19, 2023
1 parent 58fd1d4 commit a371b84
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lemarche/conversations/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion lemarche/conversations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
10 changes: 6 additions & 4 deletions lemarche/conversations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a371b84

Please sign in to comment.