Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
4d962f2c
Verified
Commit
4d962f2c
authored
Sep 09, 2018
by
Sébastiaan Versteeg
Browse files
Complete docs in pushnotifications package, closes
#583
parent
4ae90c69
Changes
6
Hide whitespace changes
Inline
Side-by-side
website/pushnotifications/admin.py
View file @
4d962f2c
"""The admin interfaces registered by the pushnotifications package"""
from
django.contrib
import
admin
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -8,6 +9,7 @@ from utils.translation import TranslatedModelAdmin
@
admin
.
register
(
models
.
Device
)
class
DeviceAdmin
(
admin
.
ModelAdmin
):
"""Manage the devices"""
list_display
=
(
'name'
,
'type'
,
'active'
,
'date_created'
)
list_filter
=
(
'active'
,
'type'
)
actions
=
(
'enable'
,
'disable'
)
...
...
@@ -31,6 +33,7 @@ class DeviceAdmin(admin.ModelAdmin):
@
admin
.
register
(
models
.
Message
)
class
MessageAdmin
(
TranslatedModelAdmin
):
"""Manage normal messages"""
list_display
=
(
'title'
,
'body'
,
'category'
,
'sent'
,
'success'
,
'failure'
)
filter_horizontal
=
(
'users'
,)
list_filter
=
(
'sent'
,
'category'
)
...
...
@@ -56,6 +59,7 @@ class MessageAdmin(TranslatedModelAdmin):
@
admin
.
register
(
models
.
ScheduledMessage
)
class
ScheduledMessageAdmin
(
TranslatedModelAdmin
):
"""Manage scheduled messages"""
list_display
=
(
'title'
,
'body'
,
'time'
,
'category'
,
'sent'
,
'success'
,
'failure'
)
date_hierarchy
=
'time'
...
...
website/pushnotifications/apps.py
View file @
4d962f2c
"""Configuration for the pushnotifications package"""
from
django.apps
import
AppConfig
from
django.utils.translation
import
ugettext_lazy
as
_
class
PushNotificationsConfig
(
AppConfig
):
"""AppConfig for the pushnotifications package"""
name
=
'pushnotifications'
verbose_name
=
_
(
'Push Notifications'
)
website/pushnotifications/models.py
View file @
4d962f2c
"""The models defined by the pushnotifications package"""
from
django.conf
import
settings
from
django.db
import
models
from
django.utils.translation
import
override
...
...
website/pushnotifications/tasks.py
View file @
4d962f2c
"""The celery tasks defined by the pushnotifications package"""
from
celery
import
shared_task
from
django.apps
import
apps
@
shared_task
def
send_message
(
message_id
):
"""Send a push notification"""
"""Send a
scheduled
push notification"""
print
(
'Sending push notification {}'
.
format
(
message_id
))
...
...
website/pushnotifications/urls.py
View file @
4d962f2c
""""The routes defined by the pushnotifications package"""
from
django.conf.urls
import
url
from
.
import
views
...
...
website/pushnotifications/views.py
View file @
4d962f2c
"""Views provided by the pushnotifications package"""
from
django.contrib.admin.views.decorators
import
staff_member_required
from
django.contrib.auth.decorators
import
permission_required
from
django.shortcuts
import
get_object_or_404
,
redirect
...
...
@@ -8,6 +9,13 @@ from pushnotifications.models import Message
@
staff_member_required
@
permission_required
(
'pushnotifications.change_message'
)
def
admin_send
(
request
,
pk
):
"""
Send the provided push notification
:param request: the request
:param pk: key of the message
:return: redirect 304 to the overview of notifications
"""
message
=
get_object_or_404
(
Message
,
pk
=
pk
)
message
.
send
()
return
redirect
(
'admin:pushnotifications_message_changelist'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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