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

Add new fields to campaign events to eventually support not recreating on updates #5916

Merged
merged 1 commit into from
Feb 28, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.1.4 on 2025-02-28 15:24

import uuid

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("campaigns", "0066_alter_campaignevent_message"),
]

operations = [
migrations.AddField(
model_name="campaignevent",
name="fire_uuid",
field=models.UUIDField(db_index=True, default=uuid.uuid4),
),
migrations.AddField(
model_name="campaignevent",
name="status",
field=models.CharField(choices=[("P", "Scheduling"), ("S", "Ready")], default="S", max_length=1),
),
]
23 changes: 13 additions & 10 deletions temba/campaigns/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from datetime import datetime, timezone as tzone
from uuid import uuid4

from django_redis import get_redis_connection
from smartmin.models import SmartModel
Expand Down Expand Up @@ -256,6 +257,10 @@ class CampaignEvent(TembaUUIDMixin, SmartModel):
TYPE_MESSAGE = "M"
TYPE_CHOICES = ((TYPE_FLOW, "Flow Event"), (TYPE_MESSAGE, "Message Event"))

STATUS_SCHEDULING = "P"
STATUS_READY = "S"
STATUS_CHOICES = ((STATUS_SCHEDULING, _("Scheduling")), (STATUS_READY, _("Ready")))

UNIT_MINUTES = "M"
UNIT_HOURS = "H"
UNIT_DAYS = "D"
Expand All @@ -273,17 +278,18 @@ class CampaignEvent(TembaUUIDMixin, SmartModel):
START_MODES_CHOICES = ((MODE_INTERRUPT, "Interrupt"), (MODE_SKIP, "Skip"), (MODE_PASSIVE, "Passive"))

campaign = models.ForeignKey(Campaign, on_delete=models.PROTECT, related_name="events")

event_type = models.CharField(max_length=1, choices=TYPE_CHOICES, default=TYPE_FLOW)
status = models.CharField(max_length=1, choices=STATUS_CHOICES, default=STATUS_READY)

# TODO switch contact fires to reference event by this instead of it's ID/UUID so we can invalidate fires without
# recreating events
fire_uuid = models.UUIDField(default=uuid4, db_index=True)

# the contact specific date value this is event is based on
relative_to = models.ForeignKey(ContactField, on_delete=models.PROTECT, related_name="campaign_events")

# offset from that date value (positive is after, negative is before)
offset = models.IntegerField(default=0)

# the unit for the offset, e.g. days, weeks
unit = models.CharField(max_length=1, choices=UNIT_CHOICES, default=UNIT_DAYS)
offset = models.IntegerField(default=0) # offset from that date value (positive is after, negative is before)
unit = models.CharField(max_length=1, choices=UNIT_CHOICES, default=UNIT_DAYS) # the unit for the offset
delivery_hour = models.IntegerField(default=-1) # can also specify the hour during the day

# the flow that will be triggered by this event
flow = models.ForeignKey(Flow, on_delete=models.PROTECT, related_name="campaign_events")
Expand All @@ -294,9 +300,6 @@ class CampaignEvent(TembaUUIDMixin, SmartModel):
# when sending single message events, we store the message here (as well as on the flow) for convenience
message = TranslatableField(max_length=Msg.MAX_TEXT_LEN, null=True)

# can also specify the hour during the day that the even should be triggered
delivery_hour = models.IntegerField(default=-1)

@classmethod
def create_message_event(
cls,
Expand Down