Agenturverbund BEnachrichtigungen neuer Standard fertig

This commit is contained in:
Holger Trampe 2020-07-06 10:41:53 +02:00
parent ed9c60e4f5
commit 3ed92963c2
2 changed files with 105 additions and 3 deletions

View File

@ -87,7 +87,7 @@
<div class="modal-dialog " role="document"> <div class="modal-dialog " role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Agenturverbundslink</h5> <h5 class="modal-title" id="exampleModalLongTitle">Link für Agenturverbund</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Schließen"> <button type="button" class="close" data-dismiss="modal" aria-label="Schließen">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
@ -99,7 +99,7 @@
<p class="mt-2">Leiten Sie den Link an Agenturen weiter, die Sie zu Ihrem Verbund einladen möchten.</p> <p class="mt-2">Leiten Sie den Link an Agenturen weiter, die Sie zu Ihrem Verbund einladen möchten.</p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-success" data-dismiss="modal">Schließen</button> <button type="button" class="btn btn-primary" data-dismiss="modal">Schließen</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -16,6 +16,11 @@ from django.contrib.auth.decorators import login_required
import re import re
from django.template import defaultfilters from django.template import defaultfilters
from organizer.models import QuickLinks, AGContacts, AGPassword from organizer.models import QuickLinks, AGContacts, AGPassword
import channels.layers
from asgiref.sync import async_to_sync
from django.template.loader import render_to_string
from notificsys.models import UserNotification
from django.core.mail import send_mail
# ALLE STANDARDS EINER AGENTUR # ALLE STANDARDS EINER AGENTUR
class StandardsManagement(LoginRequiredMixin, ListView): class StandardsManagement(LoginRequiredMixin, ListView):
@ -327,11 +332,95 @@ def StandardAdd(request, id=False):
# ADD TO NETWORKS # ADD TO NETWORKS
networks = normalForm.cleaned_data['checked_networks'].split(",") networks = normalForm.cleaned_data['checked_networks'].split(",")
'''
Alle Agenturverbunde laden, in denen die Agentur drin ist.
'''
agencynetworks_all = AgencyNetwork.objects.all()
agencynetworks = []
for a in agencynetworks_all:
if request.user.profile.agency in a.adminagencys.all() or request.user.profile.agency in a.members.all() or request.user.profile.agency in a.sharemembers.all():
agencynetworks.append(a)
agencynetworks_standard_in = []
# Agenturverbünde, in denen der Standard drin sein soll
for f in networks: for f in networks:
if(f.isdigit()): if(f.isdigit()):
tempnetwork = AgencyNetwork.objects.get(pk=f) tempnetwork = AgencyNetwork.objects.get(pk=f)
tempnetwork.standards.add(standard) #tempnetwork.standards.add(standard)
agencynetworks_standard_in.append(tempnetwork)
# Wenn Standard im gewünschten Verbund, dann rein, ansonsten raus
for a in agencynetworks:
if a in agencynetworks_standard_in and standard not in a.standards.all():
a.standards.add(standard)
else:
a.standards.remove(standard)
'''
Info an die Agenturen über einen neuen Standard
'''
agency_send = []
for agencynetwork_single in agencynetworks_standard_in:
for agn_admin in agencynetwork_single.adminagencys.all():
if(agn_admin not in agency_send):
agency_send.append(agn_admin)
if agn_admin == request.user.profile.agency:
users_of_other_ag = User.objects.filter(profile__agency=agn_admin)
for u in users_of_other_ag:
if u.has_perm('users.standardmanager'):
if u.usernotifications.agn_standard_created_mail:
notificationtext = "im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name
sendMailNoti(notificationtext, u)
if u.usernotifications.agn_standard_created_push:
newnotification = UserNotification(touser=u, notificationtext="im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name, notificationtype="")
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Agenturverbund | Im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name})
for agn_admin in agencynetwork_single.members.all():
if(agn_admin not in agency_send):
agency_send.append(agn_admin)
if agn_admin == request.user.profile.agency:
users_of_other_ag = User.objects.filter(profile__agency=agn_admin)
for u in users_of_other_ag:
if u.has_perm('users.standardmanager'):
if u.usernotifications.agn_standard_created_mail:
notificationtext = "im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name
sendMailNoti(notificationtext, u)
if u.usernotifications.agn_standard_created_push:
newnotification = UserNotification(touser=u, notificationtext="im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name, notificationtype="")
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Agenturverbund | Im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name})
for agn_admin in agencynetwork_single.sharemembers.all():
if(agn_admin not in agency_send):
agency_send.append(agn_admin)
if agn_admin == request.user.profile.agency:
users_of_other_ag = User.objects.filter(profile__agency=agn_admin)
for u in users_of_other_ag:
if u.has_perm('users.standardmanager'):
if u.usernotifications.agn_standard_created_mail:
notificationtext = "im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name
sendMailNoti(notificationtext, u)
if u.usernotifications.agn_standard_created_push:
newnotification = UserNotification(touser=u, notificationtext="im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name, notificationtype="")
newnotification.save()
channel_layer = channels.layers.get_channel_layer()
async_to_sync(channel_layer.group_send)("user_" + str(u.pk), {'type' : 'pushhandler', 'pushtext' : "pushnotification__Agenturverbund | Im Agenturverbund " + agencynetwork_single.name + " wurde ein neuer Standard geteilt: " + standard.name})
# Clear sended Agencys for multiple Networks
agency_send = []
if request.user.has_perm('users.standardmanager'): if request.user.has_perm('users.standardmanager'):
messages.success(request, f'Standard {standard.name} aktualisiert!') messages.success(request, f'Standard {standard.name} aktualisiert!')
else: else:
@ -450,6 +539,19 @@ def StandardAdd(request, id=False):
} }
return render(request, 'standards/standards_add.html', context) return render(request, 'standards/standards_add.html', context)
def sendMailNoti(notificationtext, user_touched, linktarget=""):
username = user_touched.first_name + " " + user_touched.last_name
msg_html = render_to_string('notificsys/notification_mail.html', {'username': username, 'notificationtext' : notificationtext, 'linktarget' : linktarget})
send_mail(
'Agentur-Benachrichtigung',
'Hallo ' + user_touched.first_name + ' ' + user_touched.last_name + '! ' + notificationtext,
'noreply@digitale-agentur.com',
[user_touched.email],
html_message=msg_html,
fail_silently=True
)
''' '''
@login_required @login_required
def StandardUpdate(request, id): def StandardUpdate(request, id):