Skip to content

Commit

Permalink
Merge pull request #5343 from nyaruka/bcast_template_variables
Browse files Browse the repository at this point in the history
Add `Broadcast.template_variables`
  • Loading branch information
rowanseymour authored Jul 1, 2024
2 parents 884b008 + d50a256 commit a8d39a9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
19 changes: 19 additions & 0 deletions temba/msgs/migrations/0265_broadcast_template_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.4 on 2024-07-01 19:24

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("msgs", "0264_broadcast_exclusions"),
]

operations = [
migrations.AddField(
model_name="broadcast",
name="template_variables",
field=django.contrib.postgres.fields.ArrayField(base_field=models.TextField(), null=True, size=None),
),
]
7 changes: 4 additions & 3 deletions temba/msgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@ class Broadcast(models.Model):
query = models.TextField(null=True)
exclusions = models.JSONField(default=dict, null=True)

# message content in different languages, e.g. {"eng": {"text": "Hello", "attachments": [...]}, "spa": ...}
translations = models.JSONField()
# message content
translations = models.JSONField() # text, attachments and quick replies by language
base_language = models.CharField(max_length=3) # ISO-639-3
optin = models.ForeignKey("msgs.OptIn", null=True, on_delete=models.PROTECT)
template = models.ForeignKey("templates.Template", null=True, on_delete=models.PROTECT)
template_variables = ArrayField(models.TextField(), null=True)

status = models.CharField(max_length=1, choices=STATUS_CHOICES, default=STATUS_QUEUED)
created_by = models.ForeignKey(User, null=True, on_delete=models.PROTECT, related_name="broadcast_creations")
Expand Down Expand Up @@ -291,7 +292,7 @@ def get_translation(self, contact=None) -> dict:

def trans(d):
# ensure that we have all fields
return {"text": "", "attachments": [], "quick_replies": [], "template_variables": []} | d
return {"text": "", "attachments": [], "quick_replies": []} | d

if contact and contact.language and contact.language in self.org.flow_languages: # try contact language
if contact.language in self.translations:
Expand Down

0 comments on commit a8d39a9

Please sign in to comment.