Verified Commit 22979385 authored by David Haynes's avatar David Haynes 🙆
Browse files

Alert model added

- An alert is a message we display to clients in case of some event
- start/stop date and time
- message
- urgency tag for colorization purposes
parent 22258c5d
......@@ -13,7 +13,7 @@ from __future__ import (absolute_import, division, print_function,
from django.contrib import admin
# App Imports
from .models import Facility, Schedule, OpenTime, Category, Location
from .models import Facility, Schedule, OpenTime, Category, Location, Alert
class FacilityAdmin(admin.ModelAdmin):
"""
......@@ -60,3 +60,4 @@ admin.site.register(Schedule, ScheduleAdmin)
# Use the default ModelAdmin interface for these
admin.site.register(Category)
admin.site.register(Location)
admin.site.register(Alert)
......@@ -289,3 +289,51 @@ class OpenTime(TimeStampedModel):
# to
weekdays[self.end_day],
self.end_time.strftime("%H:%M:%S"))
class Alert(TimeStampedModel):
"""
Some type of notification that is displayed to clients that conveys a
message. Past examples include: random closings, modified schedules being
in effect, election reminder, advertising for other SRCT projects.
Alerts last for a period of time until the information is no longer dank.
alert: {
urgency_tag: [info, slight, major, emergency],
message: String(),
startDate: Date(),
endDate: Date()
}
"""
# Define string constants to represent urgency tag levels
INFO = 'info'
SLIGHT = 'slight'
MAJOR = 'major'
EMERGENCY = 'emergency'
# Tuple that ties a urgency tag with an integer representation
URGENCY_CHOICES = (
(INFO, 'Info'),
(SLIGHT, 'Slight'),
(MAJOR, 'Major'),
(EMERGENCY, 'Emergency'),
)
# The urgency tag for this Alert
urgency_tag = models.CharField(max_length=10, default='Info',
choices=URGENCY_CHOICES)
# The text that is displayed that describes the Alert
message = models.CharField(max_length=140)
# The date + time that the alert will be start being served
start_datetime = models.DateTimeField()
# The date + time that the alert will stop being served
end_datetime = models.DateTimeField()
def __str__(self):
"""
String representation of an Alert object.
"""
return "%s | %s" % (self.message, self.urgency_tag)
......@@ -8,11 +8,18 @@ from __future__ import (absolute_import, division, print_function,
unicode_literals)
# App Imports
from .models import Category, Facility, Schedule, OpenTime, Location
from .models import Category, Facility, Schedule, OpenTime, Location, Alert
# Other Imports
from rest_framework import serializers
class AlertSerializer(serializers.ModelSerializer):
"""
"""
class Meta:
model = Alert
fields = '__all__'
class OpenTimeSerializer(serializers.ModelSerializer):
"""
"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment