Skip to content

Commit

Permalink
CHORE: Alert UID (#1687)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesbiggs authored Jul 25, 2024
1 parent ea44437 commit f204412
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
19 changes: 19 additions & 0 deletions etna/alerts/migrations/0002_alert_uid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 5.0.7 on 2024-07-25 09:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("alerts", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="alert",
name="uid",
field=models.BigIntegerField(blank=True, default=0, editable=False),
preserve_default=False,
),
]
8 changes: 8 additions & 0 deletions etna/alerts/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import time

from django.conf import settings
from django.db import models

Expand Down Expand Up @@ -57,9 +59,15 @@ class Alert(models.Model):
FieldPanel("alert_level"),
]

uid = models.BigIntegerField(null=False, blank=True, editable=False)

def __str__(self):
return self.title

def save(self, *args, **kwargs):
self.uid = round(time.time() * 1000)
super().save(*args, **kwargs)


class AlertMixin(models.Model):
"""Alert mixin.
Expand Down
15 changes: 10 additions & 5 deletions etna/alerts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@

class AlertSerializer(serializers.Serializer):
def to_representation(self, instance):
return {
"title": instance.title,
"message": expand_db_html(instance.message),
"alert_level": instance.alert_level,
}
if instance.active:
return {
"title": instance.title,
"message": expand_db_html(instance.message),
"alert_level": instance.alert_level,
"cascade": instance.cascade,
"uid": instance.uid,
}
else:
return None
4 changes: 3 additions & 1 deletion etna/api/tests/expected_results/author.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"global_alert": {
"title": "BETA",
"message": "<p>Message</p>",
"alert_level": "high"
"alert_level": "high",
"cascade": true,
"uid": ALERT_UID
},
"type_label": "Author",
"teaser_text": "Teaser text",
Expand Down
4 changes: 3 additions & 1 deletion etna/api/tests/expected_results/authors.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"global_alert": {
"title": "BETA",
"message": "<p>Message</p>",
"alert_level": "high"
"alert_level": "high",
"cascade": true,
"uid": ALERT_UID
},
"type_label": "Author index",
"teaser_text": "Teaser text",
Expand Down
1 change: 1 addition & 0 deletions etna/api/tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ def replace_placeholders(self, data: str):
"HOME_PAGE_ID": str(self.root_page.id),
"ARTICLE_INDEX_ID": str(self.article_index.id),
"ARTICLE_ID": str(self.article.id),
"ALERT_UID": str(self.alert.uid),
"FOCUSED_ID": str(self.focused_article.id),
"ARTS_ID": str(self.arts.id),
"EARLY_MODERN_ID": str(self.early_modern.id),
Expand Down

0 comments on commit f204412

Please sign in to comment.