diff --git a/dasettings/forms.py b/dasettings/forms.py index 7afb06e..8dc1116 100644 --- a/dasettings/forms.py +++ b/dasettings/forms.py @@ -149,7 +149,7 @@ class UsersNotificationFormAbTime(forms.ModelForm): "absence_created_mail" : "Anfrage erstellt", "absence_user_is_rep_mail" : "Als Vertreter eingesetzt", "absence_user_is_rep_reminder_mail" : "Erinnerung für Vertretung", - "time_data_changed_push" : "Datei/Ordner gelöscht", + "time_data_changed_mail" : "Abwesenheit bearbeitet", } fields = [ 'absence_created_mail', diff --git a/message/views.py b/message/views.py index 3db0582..25fb657 100644 --- a/message/views.py +++ b/message/views.py @@ -12,6 +12,9 @@ from django.contrib import messages from django.http import JsonResponse from notificsys.models import UserNotification from django.urls import reverse_lazy +import channels.layers +from asgiref.sync import async_to_sync + # ALLE STANDARDS EINER AGENTUR @login_required @@ -26,7 +29,6 @@ def mainmessageview(request): if formtocheck.is_valid(): targetuser_ids = formtocheck.cleaned_data["target_user"] - print(targetuser_ids) for user in targetuser_ids: targetuser = User.objects.get(pk=user) messagecontent = formtocheck.cleaned_data["message_content"] @@ -35,9 +37,7 @@ def mainmessageview(request): targeturl = request.build_absolute_uri() + "sl/" + str(message.id) notificationtext = "Sie haben eine neue Mitteilung erhalten: " + message.content - - if(targetuser.profile.user_messages_mail): - + if(targetuser.usernotifications.message_received_mail): username = targetuser.first_name + " " + targetuser.last_name msg_html = render_to_string('notificsys/notification_mail.html', {'username': username, 'notificationtext' : notificationtext, 'linktarget' : targeturl}) send_mail( @@ -49,9 +49,12 @@ def mainmessageview(request): fail_silently=True ) - if(targetuser.profile.user_messages_push): + if(targetuser.usernotifications.message_received_push): newnotification = UserNotification(touser=targetuser, elementid=message.id, notificationtext='Hallo ' + targetuser.first_name + ' ' + targetuser.last_name + '! ' + notificationtext, notificationtype="messagereceived") newnotification.save() + + channel_layer = channels.layers.get_channel_layer() + async_to_sync(channel_layer.group_send)("user_" + str(targetuser.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Mitteilung | Neue Mitteilung erhalten: " + message.content}) else: diff --git a/timemanagement/views.py b/timemanagement/views.py index 44bc949..814bb39 100644 --- a/timemanagement/views.py +++ b/timemanagement/views.py @@ -93,13 +93,6 @@ def AbsenceUpdate(request, pk): is_nextyear = True abinfo_nextyear = abinfo_nextyear[0] - - print(formtocheck.cleaned_data["holidays_normal"]) - print(formtocheck.cleaned_data["holidays_rest"]) - - print(formtocheck.cleaned_data["startday_info"]) - print(formtocheck.cleaned_data["endday_info"]) - abinfo.days_inuse -= formtocheck.cleaned_data["holidays_normal"] abinfo.restdays -= formtocheck.cleaned_data["holidays_rest"] abinfo.save() @@ -124,9 +117,7 @@ def AbsenceUpdate(request, pk): absence.holidays_rest = 0.0 absence.holidays_normal_next = 0.0 absence.holidays_rest_next = 0.0 - - absence.save() - + absence.save() messages.success(request, f'Abwesenheit aktualisiert!') else: messages.success(request, f'Fehler bei Abwesenheitsaktualisierung!') diff --git a/users/models.py b/users/models.py index c7b9c37..d1ab0d6 100644 --- a/users/models.py +++ b/users/models.py @@ -334,16 +334,16 @@ class UserNotifications(models.Model): password_delete_push = models.BooleanField(default=True) # MESSAGES - message_received_mail = models.BooleanField(default=True) + message_received_mail = models.BooleanField(default=False) message_received_push = models.BooleanField(default=True) # TASKS - task_activity_mail = models.BooleanField(default=True) + task_activity_mail = models.BooleanField(default=False) task_activity_push = models.BooleanField(default=True) # CHAT # Diese Einstellung sorgt dafür, dass User eine Mail/Push erhalten, wenn neue Chatnachrichten vorhanden sind. - chat_received_mail = models.BooleanField(default=True) + chat_received_mail = models.BooleanField(default=False) chat_received_push = models.BooleanField(default=True) # Benachrichtigunge, wenn es Raumaktivitäten gab diff --git a/users/signals.py b/users/signals.py index e06b684..07dc512 100644 --- a/users/signals.py +++ b/users/signals.py @@ -345,43 +345,91 @@ def newNotifiyPush(mode, instance, mailtext, notifytext, pushtext, notifytype, t usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk) # CREATED - if(mode == 0): - for user in usersofagency: - if(user.usernotifications.filedir_created_mail): + for user in usersofagency: + + # LOAD USERNOTIFICATIONS + created_mail = False + created_push = False + update_mail = False + update_push = False + delete_mail = False + delete_push = False + + + if isinstance(instance, Standards): + created_mail = user.usernotifications.standard_created_mail + created_push = user.usernotifications.standard_created_push + update_mail = user.usernotifications.standard_update_mail + update_push = user.usernotifications.standard_update_push + delete_mail = user.usernotifications.standard_delete_mail + delete_push = user.usernotifications.standard_delete_push + elif isinstance(instance, News): + created_mail = user.usernotifications.news_created_mail + created_push = user.usernotifications.news_created_push + elif isinstance(instance, DataFile) or isinstance(instance, DataDir): + created_mail = user.usernotifications.filedir_created_mail + created_push = user.usernotifications.filedir_created_push + update_mail = user.usernotifications.filedir_update_mail + update_push = user.usernotifications.filedir_update_push + delete_mail = user.usernotifications.filedir_delete_mail + delete_push = user.usernotifications.filedir_delete_push + elif isinstance(instance, QuickLinks): + created_mail = user.usernotifications.ql_created_mail + created_push = user.usernotifications.ql_created_push + update_mail = user.usernotifications.ql_update_mail + update_push = user.usernotifications.ql_update_push + delete_mail = user.usernotifications.ql_delete_mail + delete_push = user.usernotifications.ql_delete_push + elif isinstance(instance, AGContacts): + created_mail = user.usernotifications.contact_created_mail + created_push = user.usernotifications.contact_created_push + update_mail = user.usernotifications.contact_update_mail + update_push = user.usernotifications.contact_update_push + delete_mail = user.usernotifications.contact_delete_mail + delete_push = user.usernotifications.contact_delete_push + elif isinstance(instance, AGPassword): + created_mail = user.usernotifications.password_created_mail + created_push = user.usernotifications.password_created_push + update_mail = user.usernotifications.password_update_mail + update_push = user.usernotifications.password_update_push + delete_mail = user.usernotifications.password_delete_mail + delete_push = user.usernotifications.password_delete_push + elif isinstance(instance, Message): + created_mail = user.usernotifications.message_received_mail + created_push = user.usernotifications.message_received_push + + + if(mode == 0): + if(created_mail): notificationtext = mailtext + instance.name sendMailNoti(notificationtext, user, targeturl) - if(user.usernotifications.filedir_created_push): + if(created_push): newnotification = UserNotification(touser=user, notificationtext=notifytext + 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__"+ pushtext + notifytext + instance.name}) - # UPDATED - elif(mode == 1): - for user in usersofagency: - if(user.usernotifications.filedir_update_mail): + # UPDATED + elif(mode == 1): + if(update_mail): notificationtext = mailtext + instance.name - sendMailNoti(notificationtext, user, targeturl) + sendMailNoti(notificationtext, user, targeturl) - - if(user.usernotifications.filedir_update_push): + if(update_push): newnotification = UserNotification(touser=user, notificationtext=notifytext + 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__" + pushtext + notifytext + instance.name}) - #DELETE - elif(mode == 2): - usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk) - - for user in usersofagency: - if(user.usernotifications.filedir_delete_mail): + #DELETE + elif(mode == 2): + if(delete_mail): notificationtext = mailtext + instance.name sendMailNoti(notificationtext, user, targeturl) - if(user.usernotifications.filedir_delete_push): + if(delete_push): newnotification = UserNotification(touser=user, notificationtext=notifytext + instance.name, notificationtype="", elementid=instance.pk) newnotification.save() @@ -564,6 +612,8 @@ def save_newabsence(sender, instance, **kwargs): instance.holidays_rest_next = newdata[3][3] instance.save() + + else: print("Absence-Object is no holiday...") diff --git a/users/templates/users/base.html b/users/templates/users/base.html index 164a5a1..cbff605 100644 --- a/users/templates/users/base.html +++ b/users/templates/users/base.html @@ -627,11 +627,13 @@ function loadUnsendNotifications(){ action : "checknotifications" }, success: function( data ) - { + { + $("#notification_items").html(""); notifications = data['unknownnotification']; var i = 0; for (var key in notifications) { - $("#notification_items").append('
'+notifications[i]['date']+'
'+notifications[i]['text']+'
') + + $("#notification_items").append('
'+notifications[i]['date']+'
'+notifications[i]['text']+'
') i = i + 1; newunknownotificationscounter = newunknownotificationscounter + 1; } @@ -654,6 +656,7 @@ function loadUnviewnNotifications(){ { notifications = data['oldnotifications']; i = 0; + $("#notification_items").html(""); for (var key in notifications) { if(newunknownotificationscounter <= 5){ $("#notification_items").append('
'+notifications[i]['date']+'
'+notifications[i]['text']+'
')