summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/src/notification
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pharos-dashboard/src/notification')
-rw-r--r--tools/pharos-dashboard/src/notification/__init__.py11
-rw-r--r--tools/pharos-dashboard/src/notification/admin.py17
-rw-r--r--tools/pharos-dashboard/src/notification/apps.py18
-rw-r--r--tools/pharos-dashboard/src/notification/migrations/0001_initial.py28
-rw-r--r--tools/pharos-dashboard/src/notification/migrations/__init__.py10
-rw-r--r--tools/pharos-dashboard/src/notification/models.py33
-rw-r--r--tools/pharos-dashboard/src/notification/signals.py25
-rw-r--r--tools/pharos-dashboard/src/notification/tasks.py49
-rw-r--r--tools/pharos-dashboard/src/notification/tests.py41
9 files changed, 0 insertions, 232 deletions
diff --git a/tools/pharos-dashboard/src/notification/__init__.py b/tools/pharos-dashboard/src/notification/__init__.py
deleted file mode 100644
index 37dcbddf..00000000
--- a/tools/pharos-dashboard/src/notification/__init__.py
+++ /dev/null
@@ -1,11 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-default_app_config = 'notification.apps.NotificationConfig' \ No newline at end of file
diff --git a/tools/pharos-dashboard/src/notification/admin.py b/tools/pharos-dashboard/src/notification/admin.py
deleted file mode 100644
index bcaa1ab7..00000000
--- a/tools/pharos-dashboard/src/notification/admin.py
+++ /dev/null
@@ -1,17 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-from django.conf import settings
-from django.contrib import admin
-
-from notification.models import BookingNotification
-
-if settings.DEBUG:
- admin.site.register(BookingNotification) \ No newline at end of file
diff --git a/tools/pharos-dashboard/src/notification/apps.py b/tools/pharos-dashboard/src/notification/apps.py
deleted file mode 100644
index 2de22c4e..00000000
--- a/tools/pharos-dashboard/src/notification/apps.py
+++ /dev/null
@@ -1,18 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-from django.apps import AppConfig
-
-
-class NotificationConfig(AppConfig):
- name = 'notification'
-
- def ready(self):
- import notification.signals #noqa \ No newline at end of file
diff --git a/tools/pharos-dashboard/src/notification/migrations/0001_initial.py b/tools/pharos-dashboard/src/notification/migrations/0001_initial.py
deleted file mode 100644
index 8b8414e6..00000000
--- a/tools/pharos-dashboard/src/notification/migrations/0001_initial.py
+++ /dev/null
@@ -1,28 +0,0 @@
-# -*- coding: utf-8 -*-
-# Generated by Django 1.10 on 2016-11-03 13:33
-from __future__ import unicode_literals
-
-from django.db import migrations, models
-import django.db.models.deletion
-
-
-class Migration(migrations.Migration):
-
- initial = True
-
- dependencies = [
- ('booking', '0001_initial'),
- ]
-
- operations = [
- migrations.CreateModel(
- name='BookingNotification',
- fields=[
- ('id', models.AutoField(primary_key=True, serialize=False)),
- ('type', models.CharField(max_length=100)),
- ('submit_time', models.DateTimeField()),
- ('submitted', models.BooleanField(default=False)),
- ('booking', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='booking.Booking')),
- ],
- ),
- ]
diff --git a/tools/pharos-dashboard/src/notification/migrations/__init__.py b/tools/pharos-dashboard/src/notification/migrations/__init__.py
deleted file mode 100644
index b5914ce7..00000000
--- a/tools/pharos-dashboard/src/notification/migrations/__init__.py
+++ /dev/null
@@ -1,10 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
diff --git a/tools/pharos-dashboard/src/notification/models.py b/tools/pharos-dashboard/src/notification/models.py
deleted file mode 100644
index 89b30234..00000000
--- a/tools/pharos-dashboard/src/notification/models.py
+++ /dev/null
@@ -1,33 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-from django.db import models
-
-class BookingNotification(models.Model):
- id = models.AutoField(primary_key=True)
- type = models.CharField(max_length=100)
- booking = models.ForeignKey('booking.Booking', on_delete=models.CASCADE)
- submit_time = models.DateTimeField()
- submitted = models.BooleanField(default=False)
-
- def get_content(self):
- return {
- 'resource_id': self.booking.resource.id,
- 'booking_id': self.booking.id,
- 'user': self.booking.user.username,
- 'user_id': self.booking.user.id,
- }
-
- def save(self, *args, **kwargs):
- notifications = self.booking.bookingnotification_set.filter(type=self.type).exclude(
- id=self.id)
- #if notifications.count() > 0:
- # raise ValueError('Doubled Notification')
- return super(BookingNotification, self).save(*args, **kwargs)
diff --git a/tools/pharos-dashboard/src/notification/signals.py b/tools/pharos-dashboard/src/notification/signals.py
deleted file mode 100644
index 936c25ba..00000000
--- a/tools/pharos-dashboard/src/notification/signals.py
+++ /dev/null
@@ -1,25 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-from django.db.models.signals import post_save
-from django.dispatch import receiver
-
-from booking.models import Booking
-from notification.models import BookingNotification
-
-
-@receiver(post_save, sender=Booking)
-def booking_notification_handler(sender, instance, **kwargs):
- BookingNotification.objects.update_or_create(
- booking=instance, type='booking_start', defaults={'submit_time': instance.start}
- )
- BookingNotification.objects.update_or_create(
- booking=instance, type='booking_end', defaults={'submit_time': instance.end}
- ) \ No newline at end of file
diff --git a/tools/pharos-dashboard/src/notification/tasks.py b/tools/pharos-dashboard/src/notification/tasks.py
deleted file mode 100644
index 7f737625..00000000
--- a/tools/pharos-dashboard/src/notification/tasks.py
+++ /dev/null
@@ -1,49 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-import os
-import sys
-from datetime import timedelta
-
-from celery import shared_task
-from django.conf import settings
-from django.utils import timezone
-
-from notification.models import BookingNotification
-
-# this adds the top level directory to the python path, this is needed so that we can access the
-# notification library
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..'))
-
-from dashboard_notification.notification import Notification, Message
-
-
-@shared_task
-def send_booking_notifications():
- with Notification(dashboard_url=settings.RABBITMQ_URL, user=settings.RABBITMQ_USER, password=settings.RABBITMQ_PASSWORD) as messaging:
- now = timezone.now()
- notifications = BookingNotification.objects.filter(submitted=False,
- submit_time__gt=now - timedelta(minutes=1),
- submit_time__lt=now + timedelta(minutes=5))
- for notification in notifications:
- message = Message(type=notification.type, topic=notification.booking.resource.name,
- content=notification.get_content())
- messaging.send(message)
- notification.submitted = True
- notification.save()
-
-@shared_task
-def notification_debug():
- with Notification(dashboard_url=settings.RABBITMQ_URL) as messaging:
- notifications = BookingNotification.objects.all()
- for notification in notifications:
- message = Message(type=notification.type, topic=notification.booking.resource.name,
- content=notification.get_content())
- messaging.send(message)
diff --git a/tools/pharos-dashboard/src/notification/tests.py b/tools/pharos-dashboard/src/notification/tests.py
deleted file mode 100644
index 9df9aa60..00000000
--- a/tools/pharos-dashboard/src/notification/tests.py
+++ /dev/null
@@ -1,41 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 Max Breitenfeldt and others.
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-
-
-from datetime import timedelta
-from unittest import TestCase
-
-from django.contrib.auth.models import User
-from django.utils import timezone
-
-from booking.models import Booking
-from dashboard.models import Resource
-from jenkins.models import JenkinsSlave
-from notification.models import *
-
-
-class JenkinsModelTestCase(TestCase):
- def setUp(self):
- self.slave = JenkinsSlave.objects.create(name='test1', url='test')
- self.res1 = Resource.objects.create(name='res1', slave=self.slave, description='x',
- url='x')
- self.user1 = User.objects.create(username='user1')
-
- start = timezone.now()
- end = start + timedelta(days=1)
- self.booking = Booking.objects.create(start=start, end=end, purpose='test',
- resource=self.res1, user=self.user1)
-
- def test_booking_notification(self):
- BookingNotification.objects.create(type='test', booking=self.booking,
- submit_time=timezone.now())
-
- self.assertRaises(ValueError, BookingNotification.objects.create, type='test',
- booking=self.booking,
- submit_time=timezone.now())