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.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'
......
"""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')
"""The models defined by the pushnotifications package"""
from django.conf import settings
from django.db import models
from django.utils.translation import override
......
"""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))
......
""""The routes defined by the pushnotifications package"""
from django.conf.urls import url
from . import views
......
"""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')
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