Merge "update the huawei's lab"
[pharos.git] / tools / pharos-dashboard / src / notification / signals.py
1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
3 #
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 ##############################################################################
9
10
11 from django.db.models.signals import post_save
12 from django.dispatch import receiver
13
14 from booking.models import Booking
15 from notification.models import BookingNotification
16
17
18 @receiver(post_save, sender=Booking)
19 def booking_notification_handler(sender, instance, **kwargs):
20     BookingNotification.objects.update_or_create(
21         booking=instance, type='booking_start', defaults={'submit_time': instance.start}
22     )
23     BookingNotification.objects.update_or_create(
24         booking=instance, type='booking_end', defaults={'submit_time': instance.end}
25     )