fix sms org name
This commit is contained in:
1 parent
9a1c99cbd3
commit
05480970d0
3 files changed
+106
-1
No files matched your search
@@ -0,0 +1,38 @@
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
OLD_PHRASE = "توسط واحد فروش برای شما ثبت شد"
|
||||
NEW_PHRASE = "توسط واحد {unit_name} برای شما ثبت شد"
|
||||
|
||||
|
||||
def use_actual_unit_name(apps, schema_editor):
|
||||
sms_template = apps.get_model("notifications", "SMSTemplate")
|
||||
templates = sms_template.objects.filter(
|
||||
event_type="STAFF_TICKET_CREATED",
|
||||
body__contains=OLD_PHRASE,
|
||||
)
|
||||
|
||||
for template in templates.iterator():
|
||||
template.body = template.body.replace(OLD_PHRASE, NEW_PHRASE)
|
||||
allowed_tags = list(template.allowed_tags or [])
|
||||
if "unit_name" not in allowed_tags:
|
||||
allowed_tags.append("unit_name")
|
||||
template.allowed_tags = allowed_tags
|
||||
template.save(update_fields=["body", "allowed_tags"])
|
||||
|
||||
|
||||
def restore_legacy_phrase(apps, schema_editor):
|
||||
sms_template = apps.get_model("notifications", "SMSTemplate")
|
||||
templates = sms_template.objects.filter(
|
||||
event_type="STAFF_TICKET_CREATED",
|
||||
body__contains=NEW_PHRASE,
|
||||
)
|
||||
for template in templates.iterator():
|
||||
template.body = template.body.replace(NEW_PHRASE, OLD_PHRASE)
|
||||
template.save(update_fields=["body"])
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [("notifications", "0009_ensure_global_sms_templates")]
|
||||
|
||||
operations = [migrations.RunPython(use_actual_unit_name, restore_legacy_phrase)]
|
||||
Reference in new issue
Block a user