Verified Commit 4d962f2c authored by Sébastiaan Versteeg's avatar Sébastiaan Versteeg
Browse files

Complete docs in pushnotifications package, closes #583

parent 4ae90c69
"""The admin interfaces registered by the pushnotifications package"""
from django.contrib import admin from django.contrib import admin
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
...@@ -8,6 +9,7 @@ from utils.translation import TranslatedModelAdmin ...@@ -8,6 +9,7 @@ from utils.translation import TranslatedModelAdmin
@admin.register(models.Device) @admin.register(models.Device)
class DeviceAdmin(admin.ModelAdmin): class DeviceAdmin(admin.ModelAdmin):
"""Manage the devices"""
list_display = ('name', 'type', 'active', 'date_created') list_display = ('name', 'type', 'active', 'date_created')
list_filter = ('active', 'type') list_filter = ('active', 'type')
actions = ('enable', 'disable') actions = ('enable', 'disable')
...@@ -31,6 +33,7 @@ class DeviceAdmin(admin.ModelAdmin): ...@@ -31,6 +33,7 @@ class DeviceAdmin(admin.ModelAdmin):
@admin.register(models.Message) @admin.register(models.Message)
class MessageAdmin(TranslatedModelAdmin): class MessageAdmin(TranslatedModelAdmin):
"""Manage normal messages"""
list_display = ('title', 'body', 'category', 'sent', 'success', 'failure') list_display = ('title', 'body', 'category', 'sent', 'success', 'failure')
filter_horizontal = ('users',) filter_horizontal = ('users',)
list_filter = ('sent', 'category') list_filter = ('sent', 'category')
...@@ -56,6 +59,7 @@ class MessageAdmin(TranslatedModelAdmin): ...@@ -56,6 +59,7 @@ class MessageAdmin(TranslatedModelAdmin):
@admin.register(models.ScheduledMessage) @admin.register(models.ScheduledMessage)
class ScheduledMessageAdmin(TranslatedModelAdmin): class ScheduledMessageAdmin(TranslatedModelAdmin):
"""Manage scheduled messages"""
list_display = ('title', 'body', 'time', 'category', 'sent', 'success', list_display = ('title', 'body', 'time', 'category', 'sent', 'success',
'failure') 'failure')
date_hierarchy = 'time' date_hierarchy = 'time'
......
"""Configuration for the pushnotifications package"""
from django.apps import AppConfig from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
class PushNotificationsConfig(AppConfig): class PushNotificationsConfig(AppConfig):
"""AppConfig for the pushnotifications package"""
name = 'pushnotifications' name = 'pushnotifications'
verbose_name = _('Push Notifications') verbose_name = _('Push Notifications')
"""The models defined by the pushnotifications package"""
from django.conf import settings from django.conf import settings
from django.db import models from django.db import models
from django.utils.translation import override from django.utils.translation import override
......
"""The celery tasks defined by the pushnotifications package"""
from celery import shared_task from celery import shared_task
from django.apps import apps from django.apps import apps
@shared_task @shared_task
def send_message(message_id): def send_message(message_id):
"""Send a push notification""" """Send a scheduled push notification"""
print('Sending push notification {}'.format(message_id)) print('Sending push notification {}'.format(message_id))
......
""""The routes defined by the pushnotifications package"""
from django.conf.urls import url from django.conf.urls import url
from . import views from . import views
......
"""Views provided by the pushnotifications package"""
from django.contrib.admin.views.decorators import staff_member_required from django.contrib.admin.views.decorators import staff_member_required
from django.contrib.auth.decorators import permission_required from django.contrib.auth.decorators import permission_required
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
...@@ -8,6 +9,13 @@ from pushnotifications.models import Message ...@@ -8,6 +9,13 @@ from pushnotifications.models import Message
@staff_member_required @staff_member_required
@permission_required('pushnotifications.change_message') @permission_required('pushnotifications.change_message')
def admin_send(request, pk): 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 = get_object_or_404(Message, pk=pk)
message.send() message.send()
return redirect('admin:pushnotifications_message_changelist') return redirect('admin:pushnotifications_message_changelist')
Supports Markdown
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