digitaleagenturnc/users/SAVE.py

229 lines
11 KiB
Python

'''
@receiver(post_save, sender=DataDir)
def save_dir(sender, instance, **kwargs):
usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk)
# CREATED
if(kwargs["created"]):
for user in usersofagency:
if(user.usernotifications.filedir_created_mail):
notificationtext = " es gibt neue Ordner: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.filedir_created_push):
newnotification = UserNotification(touser=user, notificationtext="Neuer Ordner: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Ordner | Neuer Ordner: " + instance.name})
# UPDATED
else:
for user in usersofagency:
if(user.usernotifications.filedir_update_mail):
notificationtext = " Ordner wurden aktualisiert: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.filedir_update_push):
newnotification = UserNotification(touser=user, notificationtext="Aktualisierter Ordner: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Ordner | Aktualisierter Ordner: " + instance.name})
'''
'''
@receiver(pre_delete, sender=DataDir)
def del_dir(sender, instance, **kwargs):
usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk)
for user in usersofagency:
if(user.usernotifications.filedir_delete_mail):
notificationtext = " ein Ordner wurde gelöscht: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.filedir_delete_push):
newnotification = UserNotification(touser=user, notificationtext="Ordner gelöscht: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Ordner | Ordner gelöscht: " + instance.name})
'''
@receiver(pre_delete, sender=DataFile)
def del_file(sender, instance, **kwargs):
usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk)
for user in usersofagency:
if(user.usernotifications.filedir_delete_mail):
notificationtext = " eine Datei wurde gelöscht: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.filedir_delete_push):
newnotification = UserNotification(touser=user, notificationtext="Datei gelöscht: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Dateiein | Datei gelöscht: " + instance.name})
# Signals for FILES
@receiver(post_save, sender=DataFile)
def save_file(sender, instance, **kwargs):
if(kwargs["created"] and len(instance.name) > 0):
newNotifiyPush(0, instance, " es gibt eine neue Datei: ", "Neue Datei: ", "Dateien | ", "", "")
elif(len(instance.name) > 0):
newNotifiyPush(1, instance, " Datei wurde aktualisiert: ", "Aktualisierter Datei: ", "Dateien | ", "", "")
usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk)
# CREATED
if(kwargs["created"]):
for user in usersofagency:
if(user.usernotifications.filedir_created_mail):
notificationtext = " es gibt eine neue Datei: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.filedir_created_push):
newnotification = UserNotification(touser=user, notificationtext="Neue Datei: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Dateien | Neue Datei: " + instance.name})
# UPDATED
else:
for user in usersofagency:
if(user.usernotifications.filedir_update_mail):
notificationtext = " Datei wurden aktualisiert: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.filedir_update_push):
newnotification = UserNotification(touser=user, notificationtext="Aktualisierte Datei: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Dateien | Aktualisierte Datei: " + instance.name})
@receiver(post_save, sender=QuickLinks)
def save_ql(sender, instance, **kwargs):
usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk)
# CREATED
if(kwargs["created"]):
for user in usersofagency:
if(user.usernotifications.ql_created_mail):
notificationtext = " es gibt einen neuen Quicklink: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.ql_created_push):
newnotification = UserNotification(touser=user, notificationtext="Neuer Quicklink: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Organizer | Neuer Quicklink: " + instance.name})
# UPDATED
else:
for user in usersofagency:
if(user.usernotifications.ql_update_mail):
notificationtext = " Quicklink wurde aktualisiert: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.ql_update_push):
newnotification = UserNotification(touser=user, notificationtext="Quicklink aktualisiert: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Organizer | Aktualisierter Quicklink: " + instance.name})
@receiver(pre_delete, sender=QuickLinks)
def del_ql(sender, instance, **kwargs):
usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk)
for user in usersofagency:
if(user.usernotifications.ql_delete_mail):
notificationtext = " ein Quicklink wurde gelöscht: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.ql_delete_push):
newnotification = UserNotification(touser=user, notificationtext="Quicklink gelöscht: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Organizer | Quicklink gelöscht: " + instance.name})
@receiver(post_save, sender=Standards)
def save_standard(sender, instance, **kwargs):
usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk)
targeturl = settings.BASE_URL + "standards/standard/" + str(instance.pk) + "/single"
# NEW STANDARD
if(kwargs["created"]):
if(instance.public):
for user in usersofagency:
if(user.usernotifications.standard_created_mail):
notificationtext = " es wurde ein neuer Agenturstandard erstellt: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.standard_created_push):
newnotification = UserNotification(touser=user, notificationtext="Neuer Agenturstandard: " + instance.name, notificationtype="newstandard", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Standards | Neuer Agenturstandard: " + instance.name})
else:
for user in usersofagency:
if(user.has_perm("users.standardmanager") and user.usernotifications.standard_created_unpub_push):
newnotification = UserNotification(touser=user, notificationtext="Neuer unveröffentlichter Agenturstandard: " + instance.name, notificationtype="newstandard", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Standards | Neuer unveröffentlichter Agenturstandard: " + instance.name})
if(user.has_perm("users.standardmanager") and user.usernotifications.standard_created_unpub_mail):
notificationtext = " es wurde ein neuer unveröffentlichter Agenturstandard erstellt: " + instance.name
sendMailNoti(notificationtext, user)
# Standard wurde aktualisiert
else:
for user in usersofagency:
if(user.usernotifications.standard_update_mail):
notificationtext = " es wurde ein neuer Agenturstandard aktualisiert: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.standard_update_push):
newnotification = UserNotification(touser=user, notificationtext="Agenturstandard aktualisiert: " + instance.name, notificationtype="newstandard", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Standards | Agenturstandard aktualisiert: " + instance.name})
# DELETE
@receiver(pre_delete, sender=Standards)
def delete_standard(sender, instance, **kwargs):
usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk)
for user in usersofagency:
if(user.usernotifications.standard_delete_mail):
notificationtext = " es wurde ein neuer Agenturstandard gelöscht: " + instance.name
sendMailNoti(notificationtext, user)
if(user.usernotifications.standard_delete_push):
newnotification = UserNotification(touser=user, notificationtext="Agenturstandard gelöscht: " + instance.name, notificationtype="", elementid=instance.pk)
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(user.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Standards | Agenturstandard gelöscht: " + instance.name})