Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Hunter T Jozwiak
whats-open
Commits
24b69265
Commit
24b69265
authored
Jun 23, 2017
by
David Haynes
Browse files
Merge branch '41-alerts-endpoint' of git.gmu.edu:srct/whats-open into 41-alerts-endpoint
parents
3244d985
00d915fb
Changes
6
Hide whitespace changes
Inline
Side-by-side
requirements/base.txt
View file @
24b69265
...
...
@@ -4,3 +4,4 @@ django-cas-client==1.3.0
djangorestframework==3.6.3
django-model-utils==3.0.0
mysqlclient==1.3.10
setuptools==36.0.1
\ No newline at end of file
whats-open/api/admin.py
View file @
24b69265
...
...
@@ -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
):
"""
...
...
@@ -72,3 +72,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
)
whats-open/api/models.py
View file @
24b69265
...
...
@@ -291,3 +291,44 @@ 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.
"""
# Define string constants to represent urgency tag levels
INFO
=
'info'
# SRCT announcements
MINOR
=
'minor'
# Holiday hours are in effect
MAJOR
=
'major'
# The hungry patriot is closed today
EMERGENCY
=
'emergency'
# Extreme weather
# Tuple that ties a urgency tag with a string representation
URGENCY_CHOICES
=
(
(
INFO
,
'Info'
),
(
MINOR
,
'Minor'
),
(
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"
%
(
self
.
message
)
whats-open/api/serializers.py
View file @
24b69265
...
...
@@ -11,14 +11,20 @@ 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
CategorySerializer
(
serializers
.
ModelSerializer
):
class
AlertSerializer
(
serializers
.
ModelSerializer
):
"""
"""
class
Meta
:
model
=
Alert
fields
=
'__all__'
class
OpenTimeSerializer
(
serializers
.
ModelSerializer
):
"""
Serializer for the Category model.
"""
class
Meta
:
# Choose the model to be serialized
...
...
whats-open/api/urls.py
View file @
24b69265
...
...
@@ -15,7 +15,7 @@ from django.views.generic.base import RedirectView
# App Imports
from
.views
import
(
CategoryViewSet
,
FacilityViewSet
,
ScheduleViewSet
,
LocationViewSet
)
LocationViewSet
,
AlertViewSet
)
# Other Imports
from
rest_framework.routers
import
DefaultRouter
...
...
@@ -28,6 +28,7 @@ ROUTER.register(r'categories', CategoryViewSet)
ROUTER
.
register
(
r
'facilities'
,
FacilityViewSet
)
ROUTER
.
register
(
r
'schedules'
,
ScheduleViewSet
)
ROUTER
.
register
(
r
'locations'
,
LocationViewSet
)
ROUTER
.
register
(
r
'alerts'
,
AlertViewSet
)
urlpatterns
=
[
# / - Default route
...
...
whats-open/api/views.py
View file @
24b69265
...
...
@@ -8,14 +8,20 @@ from __future__ import (absolute_import, division, print_function,
unicode_literals
)
# App Imports
from
.models
import
Facility
,
OpenTime
,
Category
,
Schedule
,
Location
from
.models
import
Facility
,
OpenTime
,
Category
,
Schedule
,
Location
,
Alert
from
.serializers
import
(
CategorySerializer
,
FacilitySerializer
,
ScheduleSerializer
,
OpenTimeSerializer
,
LocationSerializer
)
LocationSerializer
,
AlertSerializer
)
# Other Imports
from
rest_framework
import
viewsets
class
AlertViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
"""
queryset
=
Alert
.
objects
.
all
()
serializer_class
=
AlertSerializer
class
CategoryViewSet
(
viewsets
.
ReadOnlyModelViewSet
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment