-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from Amsterdam/feature/101127-add-alerts
101127 added notification alerts for misfunctioning webapp
- Loading branch information
Showing
9 changed files
with
97 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django.contrib import admin | ||
from .models import Alert | ||
|
||
|
||
@admin.register(Alert) | ||
class AlertAdmin(admin.ModelAdmin): | ||
list_display = ('id', 'is_active_boolean', 'start_time', 'end_time', 'message',) | ||
search_fields = ('message',) | ||
|
||
# Display boolean checkmark instead of True/False | ||
def is_active_boolean(self, obj): | ||
return obj.is_active() | ||
|
||
is_active_boolean.boolean = True # This tells Django to use checkmarks/crosses | ||
is_active_boolean.short_description = 'Active' # Optional, to rename the column |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from .models import Alert | ||
from django.utils import timezone | ||
|
||
|
||
def alerts_processor(request): | ||
alerts = Alert.objects.filter(start_time__lte=timezone.now(), end_time__gte=timezone.now()) | ||
return {'alerts': alerts} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 5.0.8 on 2024-09-11 12:11 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Alert', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('message', models.TextField()), | ||
('start_time', models.DateTimeField()), | ||
('end_time', models.DateTimeField()), | ||
], | ||
options={ | ||
'verbose_name': 'Alert', | ||
'verbose_name_plural': 'Alerts', | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.db import models | ||
from django.utils import timezone | ||
|
||
|
||
class Alert(models.Model): | ||
message = models.TextField() | ||
start_time = models.DateTimeField() | ||
end_time = models.DateTimeField() | ||
|
||
def is_active(self): | ||
""" Check if the alert is active based on start and end time """ | ||
now = timezone.now() | ||
return self.start_time <= now <= self.end_time | ||
|
||
def __str__(self): | ||
return f"Alert: {self.message[:50]}" | ||
|
||
class Meta: | ||
verbose_name = "Alert" | ||
verbose_name_plural = "Alerts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters