1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
13 from datetime import timedelta
15 from celery import shared_task
16 from django.conf import settings
17 from django.utils import timezone
19 from notification.models import BookingNotification
21 # this adds the top level directory to the python path, this is needed so that we can access the
22 # notification library
23 sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
25 from dashboard_notification.notification import Notification, Message
29 def send_booking_notifications():
30 with Notification(dashboard_url=settings.RABBITMQ_URL, user=settings.RABBITMQ_USER, password=settings.RABBITMQ_PASSWORD) as messaging:
32 notifications = BookingNotification.objects.filter(submitted=False,
33 submit_time__gt=now - timedelta(minutes=1),
34 submit_time__lt=now + timedelta(minutes=5))
35 for notification in notifications:
36 message = Message(type=notification.type, topic=notification.booking.resource.name,
37 content=notification.get_content())
38 messaging.send(message)
39 notification.submitted = True
43 def notification_debug():
44 with Notification(dashboard_url=settings.RABBITMQ_URL) as messaging:
45 notifications = BookingNotification.objects.all()
46 for notification in notifications:
47 message = Message(type=notification.type, topic=notification.booking.resource.name,
48 content=notification.get_content())
49 messaging.send(message)