From 06315cc953ebd72375f4a16c916263cedffabefa Mon Sep 17 00:00:00 2001 From: "holger.trampe" Date: Mon, 23 Mar 2020 23:19:09 +0100 Subject: [PATCH] Zwischecom 0.8.2 --- cloud/templates/cloud/cloud_main.html | 114 ++++++++++---- cloud/urls.py | 1 + cloud/views.py | 35 ++++- .../templates/dasettings/groups_content.html | 2 +- .../dasettings/notifications_content.html | 2 +- .../templates/dasettings/profil_content.html | 5 +- dasettings/templates/dasettings/settings.html | 18 +-- .../__pycache__/settings.cpython-38.pyc | Bin 3736 -> 3825 bytes digitaleagentur/settings.py | 6 +- media/userprofilepics/default.jpg | Bin 5787 -> 0 bytes message/__pycache__/models.cpython-38.pyc | Bin 194 -> 1113 bytes message/__pycache__/urls.cpython-38.pyc | Bin 480 -> 665 bytes message/__pycache__/views.cpython-38.pyc | Bin 1785 -> 3595 bytes message/models.py | 19 ++- message/templates/message/message.html | 140 ++++++++++++++++-- message/templates/message/message_send.html | 15 -- message/templates/message/message_single.html | 54 +++++++ message/urls.py | 7 +- message/views.py | 114 +++++++++++--- news/__pycache__/models.cpython-38.pyc | Bin 1489 -> 1557 bytes news/models.py | 6 +- news/templates/news/news_addnews.html | 3 +- .../notificsys/allnotifications.html | 4 + .../notificsys/notification_mail.html | 3 + notificsys/views.py | 13 +- orga/templates/orga/orga_single.html | 7 +- .../templates/standards/standards_add.html | 8 +- .../standards/standards_management.html | 2 +- .../templates/standards/standards_update.html | 8 +- .../__pycache__/counter_tag.cpython-38.pyc | Bin 2045 -> 2256 bytes standards/templatetags/counter_tag.py | 7 + users/admin.py | 2 + users/signals.py | 47 +++--- users/templates/users/base.html | 6 +- users/urls.py | 4 +- users/views.py | 56 ++++++- 36 files changed, 564 insertions(+), 144 deletions(-) delete mode 100644 media/userprofilepics/default.jpg delete mode 100644 message/templates/message/message_send.html create mode 100644 message/templates/message/message_single.html diff --git a/cloud/templates/cloud/cloud_main.html b/cloud/templates/cloud/cloud_main.html index b7cd6a5..e7ff9ad 100644 --- a/cloud/templates/cloud/cloud_main.html +++ b/cloud/templates/cloud/cloud_main.html @@ -24,14 +24,14 @@ a.disabled {
-

Dateien 

+

Dateien{% if request.user.profile.showtooltips %} {% endif %}


-
Aktuelle Quota: {{actquota}} / 2 GB
+
Belegter Speicherplatz: {{actquota}} / 2 GB
@@ -120,7 +120,7 @@ a.disabled { - {{file.name}} + {{file.name}} {{file.owner.first_name}} {{file.owner.last_name}} {{file.date_created|date:"d.m.Y G:i"}} {{file.date_last_modified|date:"d.m.Y G:i"}} @@ -227,6 +227,26 @@ a.disabled {
+ + + + + + + {% else %}

Das Modul Mitteilungen wurde in ihrer Agentur deaktiviert.

diff --git a/message/templates/message/message_send.html b/message/templates/message/message_send.html deleted file mode 100644 index 84c200a..0000000 --- a/message/templates/message/message_send.html +++ /dev/null @@ -1,15 +0,0 @@ -{% extends "users/base.html" %} -{% load crispy_forms_tags %} -{% block content %} -{% if request.user.profile.agency.module_messages %} -
-

Mitteilungen 

-
- Ihre Mitteilung wurde gesendet. - -
- -{% else %} -

Das Modul Mitteilungen wurde in ihrer Agentur deaktiviert.

-{% endif %} -{% endblock content %} \ No newline at end of file diff --git a/message/templates/message/message_single.html b/message/templates/message/message_single.html new file mode 100644 index 0000000..f34f645 --- /dev/null +++ b/message/templates/message/message_single.html @@ -0,0 +1,54 @@ +{% extends "users/base.html" %} +{% load crispy_forms_tags %} +{% block content %} +{% if request.user.profile.agency.module_messages %} +
+

Mitteilung von {{mess.created_by.first_name}} {{mess.created_by.last_name}}

+ Versendet am {{mess.created_date}} +
+ + Hallo {{request.user.first_name}} {{request.user.last_name}},

+ {{mess.content}} +

+ Mit freundlichen Grüßen

+ {{mess.created_by.first_name}} {{mess.created_by.last_name}} +
+ +
+ + + + + +{% else %} +

Das Modul Mitteilungen wurde in ihrer Agentur deaktiviert.

+{% endif %} +{% endblock content %} \ No newline at end of file diff --git a/message/urls.py b/message/urls.py index 84f68ef..c9d1f6f 100644 --- a/message/urls.py +++ b/message/urls.py @@ -5,5 +5,10 @@ from . import views from django.contrib.auth.decorators import login_required urlpatterns = [ - path('', views.mainmessageview, name="messages"), + path('', views.mainmessageview, name="messages"), + path('sl/', views.singelmessageview, name="message-single"), + path('delsingle/', views.delsinglemessage, name='delsinglemessage'), + path('delmessage/', views.delsinglemessagefromsingle, name='delsinglemessagefromsingle'), + + ] \ No newline at end of file diff --git a/message/views.py b/message/views.py index c604586..9e2695a 100644 --- a/message/views.py +++ b/message/views.py @@ -1,4 +1,4 @@ -from django.shortcuts import render, redirect +from django.shortcuts import render, redirect, reverse from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import CreateView, ListView, UpdateView, DetailView, DeleteView from django.contrib.auth.models import User @@ -7,6 +7,11 @@ from .forms import MessageForm from notificsys.models import UserNotification from django.core.mail import send_mail from django.template.loader import render_to_string +from .models import Message +from django.contrib import messages +from django.http import JsonResponse +from notificsys.models import UserNotification + # ALLE STANDARDS EINER AGENTUR @login_required def mainmessageview(request): @@ -15,39 +20,100 @@ def mainmessageview(request): 'active_link' : 'messages' } - targetuser_id = request.POST["target_user"] - message = request.POST["message_content"] + formtocheck = MessageForm(request.user, request.POST) - targetuser = User.objects.get(pk=targetuser_id) - - notificationtext = message + " Grüße, " + request.user.first_name + " " + request.user.last_name - - if(targetuser.profile.user_messages_mail): + if formtocheck.is_valid(): + targetuser_id = formtocheck.cleaned_data["target_user"] + targetuser = User.objects.get(pk=targetuser_id) + messagecontent = formtocheck.cleaned_data["message_content"] + message = Message.objects.create(target_user=targetuser, agency=request.user.profile.agency, content=messagecontent, created_by=request.user) - username = targetuser.first_name + " " + targetuser.last_name - msg_html = render_to_string('notificsys/notification_mail.html', {'username': username, 'notificationtext' : notificationtext}) - send_mail( - 'Agentur-Benachrichtigung', - 'Hallo ' + targetuser.first_name + ' ' + targetuser.last_name + '! ' + notificationtext, - 'support@digitale-agentur.com', - [targetuser.email], - html_message=msg_html, - fail_silently=False - ) + targeturl = request.build_absolute_uri() + "sl/" + str(message.id) + notificationtext = "Sie haben eine neue Mitteilung erhalten." - if(targetuser.profile.user_messages_push): - newnotification = UserNotification(touser=targetuser, notificationtext='Hallo ' + targetuser.first_name + ' ' + targetuser.last_name + '! ' + notificationtext, notificationtype="messagereceived") - newnotification.save() - return render (request, 'message/message_send.html', context) + if(targetuser.profile.user_messages_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( + 'Agentur-Benachrichtigung', + 'Hallo ' + targetuser.first_name + ' ' + targetuser.last_name + '! ' + notificationtext + " Klicken Sie hier.", + 'support@digitale-agentur.com', + [targetuser.email], + html_message=msg_html, + fail_silently=False + ) + + if(targetuser.profile.user_messages_push): + newnotification = UserNotification(touser=targetuser, elementid=message.id, notificationtext='Hallo ' + targetuser.first_name + ' ' + targetuser.last_name + '! ' + notificationtext, notificationtype="messagereceived") + newnotification.save() + + else: + messages.warning(request, f'Bitte valide Daten eingeben!') + context = { + 'active_link' : 'messages', + 'form' : MessageForm(request.user), + 'usermessages' : Message.objects.filter(target_user=request.user, agency=request.user.profile.agency).order_by('-created_date') + } + return render (request, 'message/message.html', context) + + context = { + 'active_link' : 'messages', + 'form' : MessageForm(request.user), + 'usermessages' : Message.objects.filter(target_user=request.user, agency=request.user.profile.agency).order_by('-created_date') + } + + messages.success(request, f'Ihre Nachricht wurde verschickt!') + return render (request, 'message/message.html', context) else: context = { 'active_link' : 'messages', - 'form' : MessageForm(request.user) + 'form' : MessageForm(request.user), + 'usermessages' : Message.objects.filter(target_user=request.user, agency=request.user.profile.agency).order_by('-created_date') } # Adding active_link # Loading only user same agency # Change context and return for template-data # # Get all Users of the Same Agency as logged user - return render (request, 'message/message.html', context) \ No newline at end of file + return render (request, 'message/message.html', context) + +@login_required +def singelmessageview(request, pk): + + context = { + 'active_link' : 'messages', + 'mess' : Message.objects.get(pk=pk) + } + + return render (request, 'message/message_single.html', context) + +@login_required +def delsinglemessage(request): + if request.method == 'GET': + if request.GET['action'] == 'delsingle': + Message.objects.get(pk=request.GET['todelid']).delete() + UserNotification.objects.filter(elementid=request.GET['todelid']).delete() + return JsonResponse({}) + + +@login_required +def delsinglemessagefromsingle(request, pk): + + context = { + 'active_link' : 'messages', + 'form' : MessageForm(request.user), + 'usermessages' : Message.objects.filter(target_user=request.user, agency=request.user.profile.agency).order_by('-created_date') + } + + todelmess = Message.objects.get(pk=pk) + + if(todelmess.agency == request.user.profile.agency and todelmess.target_user == request.user): + messages.success(request, f'Mitteilung gelöscht.') + Message.objects.get(pk=pk).delete() + UserNotification.objects.filter(elementid=pk).delete() + else: + messages.success(request, f'Sie dürfen diese Mitteilung nicht löschen.') + + return render (request, 'message/message.html', context) diff --git a/news/__pycache__/models.cpython-38.pyc b/news/__pycache__/models.cpython-38.pyc index 9c74d84d9fa1f6102b4ca0acfc6fcbe113898c23..08ab686174e358f84d3586e24eba2b33d26a9e1b 100644 GIT binary patch delta 466 zcmZ8eyH3L}6pfwql_stGOzA^B)S(q(M`8gaI-rWBtq>Uq0lQVJkVvj8(TRmMlf}Y- zU`7lqZ2SQWYs6RZ1=t0FR7>~Vd(OSrK9WDuw}v?|OEfDpc(ZQ72h~COI6(dI;_O5-$Mf6b!>=m5D`5VQq;(~#TqNw3aPidF>0U6t_fU{OgMRDOqysq~nH2q1`Het~sZ7TMrm+7nt{<Ef&Aj$sZV_Cr2=;iZB;(108jXrzkZiu_QGmJ})shb@E&$ zM@GrX_nEvHr6+4K=V{9Tl@y7C2uV001=1#vo>~&0m{gpfQ(BT5Us{wSKlw1T5~I}Q zXUyS@Vw3GyWI5Rbg8V~VokOA~r?RLpMosQw3AQhi1{os - - +

News anlegen


diff --git a/notificsys/templates/notificsys/allnotifications.html b/notificsys/templates/notificsys/allnotifications.html index 790db6e..ba031bd 100644 --- a/notificsys/templates/notificsys/allnotifications.html +++ b/notificsys/templates/notificsys/allnotifications.html @@ -14,6 +14,10 @@ {{notification.notificationtext}}
+ {% elif notification.notificationtype == "messagereceived" %} + + {{notification.notificationtext}} +
{% else %} {{notification.notificationtext}}
{% endif %} diff --git a/notificsys/templates/notificsys/notification_mail.html b/notificsys/templates/notificsys/notification_mail.html index a75773d..299b991 100644 --- a/notificsys/templates/notificsys/notification_mail.html +++ b/notificsys/templates/notificsys/notification_mail.html @@ -125,6 +125,9 @@

Hallo {{username}},

{{notificationtext}}

+ {% if linktarget|length > 0 %} +

Hier klicken!

+ {% endif %}

Mit freundlichen Grüßen

Ihr Team von Digitale Agentur

diff --git a/notificsys/views.py b/notificsys/views.py index c5050a1..709a8b3 100644 --- a/notificsys/views.py +++ b/notificsys/views.py @@ -16,9 +16,14 @@ def CheckNotifications(request): i = 0 for notify in unknownnotification: - elelink = "notifications/showallnotificaions/" + elelink = "" if notify.notificationtype == "agencynews": elelink = "news/news/" + str(notify.elementid) + "/single" + elif notify.notificationtype == "messagereceived": + elelink = "messages/sl/" + str(notify.elementid) + else: + elelink = "notifications/showallnotificaions/" + formatedDate = notify.created.strftime("%d.%m.20%y um %H:%M") @@ -46,9 +51,13 @@ def GetBasicNotifications(request): i = 0 for notify in oldnotifications: - elelink = "notifications/showallnotificaions/" + elelink = "" if notify.notificationtype == "agencynews": elelink = "news/news/" + str(notify.elementid) + "/single" + elif notify.notificationtype == "messagereceived": + elelink = "messages/sl/" + str(notify.elementid) + else: + elelink = "notifications/showallnotificaions/" formatedDate = notify.created.strftime("%d.%m.20%y um %H:%M") diff --git a/orga/templates/orga/orga_single.html b/orga/templates/orga/orga_single.html index 3ebc65a..81ce686 100644 --- a/orga/templates/orga/orga_single.html +++ b/orga/templates/orga/orga_single.html @@ -1,7 +1,12 @@ {% extends "users/base.html" %} +{% load counter_tag %} {% block content %}
-

Bereiche und Aufgaben von {{user_first_name}} {{user_last_name}}

+

Bereiche und Aufgaben von {{user_first_name}} {{user_last_name}} + {% if user|usergperm:"usermanager" %} + + {% endif %} +


diff --git a/standards/templates/standards/standards_add.html b/standards/templates/standards/standards_add.html index 49f1fcc..1f3a6b3 100644 --- a/standards/templates/standards/standards_add.html +++ b/standards/templates/standards/standards_add.html @@ -3,7 +3,7 @@ {% load counter_tag %} {% block content %}
-

Neuen Standard anlegen 

+

Neuen Standard anlegen{% if request.user.profile.showtooltips %} {% endif %}


{% csrf_token %} @@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@
@@ -82,7 +82,7 @@
diff --git a/standards/templates/standards/standards_management.html b/standards/templates/standards/standards_management.html index 2377535..218aae1 100644 --- a/standards/templates/standards/standards_management.html +++ b/standards/templates/standards/standards_management.html @@ -3,7 +3,7 @@ {% block content %}
-

Standards 

+

Standards{% if request.user.profile.showtooltips %} {% endif %}

Sichtbar sind alle veröffentlichten und von {{ user.first_name }} {{ user.last_name}} erstellten Standards.
diff --git a/standards/templates/standards/standards_update.html b/standards/templates/standards/standards_update.html index 94ab528..5966a6f 100644 --- a/standards/templates/standards/standards_update.html +++ b/standards/templates/standards/standards_update.html @@ -3,7 +3,7 @@ {% load counter_tag %} {% block content %}
-

Standard bearbeiten 

+

Standard bearbeiten{% if request.user.profile.showtooltips %} {% endif %}


{% csrf_token %} @@ -24,7 +24,7 @@
@@ -49,7 +49,7 @@
@@ -88,7 +88,7 @@
diff --git a/standards/templatetags/__pycache__/counter_tag.cpython-38.pyc b/standards/templatetags/__pycache__/counter_tag.cpython-38.pyc index b959d3d38d12f4f15234b1129aa19cb9e727a5f2..53254318cd860d9b2df1b7dd3c0db467e6074e54 100644 GIT binary patch delta 1170 zcmZ`&O>fgc5cN8a<2Z?(G++IqO%ZJqR9aLjF0{RXdO<~s5F9K)NV-du%1)xSgH#F8 zLpjnzwSNGPh@ZfbD?*(85BLEbk(ikjg+^e>FEelU?Reg9e!1TZ&XZiu*5LV8IeGrZ zx^NbCi(PEoJ`F6-Vj9PSOMQETS34=*j zHT9Bm_42JWFfw-)97tocE239zIRkO11850Z0M*?c3u5_yS+9QtvMS2P?JOpX>a*^% zvZ^QQtfHEUjnbqeHj^cQC3TUwx0izGBa72rIT#H)gMlwIxZvvgI2DQri*=|?rdqk2 zs&FdvC|bU%q&;Z16wHS5O_W~_cOBv*2Jq*>7$>+7Z-_QTTEvd^~e&yS$OEX}~Jx+#0zZc0HlzBGq$!I{7mySd*99O3{c8P7l+Ey5y_@X)4 z-ez)J_03(DSD(z<%?echb;j}z6rQ4NY)4~3{WK4%o`Y_|-QElaT=?PG=pD6}s-EH> zUe*9&JM0BRU$mljSGvd+5Q+$B1>HBff)O6OTth%3&fM@cA@jg7yEcY d!d-wY%d;%Ys;{Y9IcYH4wV7?gn}pZE-`}q9Bb-7%JppY2Z;Yb@V*-%ZP9^uxaZt^=HC0>x8iT#dz8<+8h+m&@9h1w zPP}>jmv*wcaon{8dvAZxx(?U+F3Vu^Ua)SSn9Utx9x<2C5c820c#h{^ zGw$&mX+^5=d4X7oSdo{Am8rf=^%Y(w?M{WnDv32-C$UOegR~2Lmb4mabEM7lInwGp z^HA$7$m?ufzqc*F8kgl;R%1E&nLY7maM?JcRyHyWJlWJcYc?{-orOHo)EtWBun$Fy zV;w;=pn#5we5JQHE#&ZjYq0+mtu z#!VBWPb_tYFgh3yMxzkaJDr-62DD<4sN@pnrdu^}#>GwWmEq!97xkN1aW`dMQ`W!B zwPYhZSe!*A&5Q*^X(mqk$+@P`#{6yhE*rEf7&kdIP zr1r437bi!d*q#2~Ww0(=))w>Sp4Gfk#mv7h6gDvNK-uU<^iD&5w6>4oDoUxf6AYja zN2v{B7{s_8IO;!_RML%uXdH@O(jS7S)PjPN0`)lbvd~mfOM$vWSW&R9K(#%!&GeP* ht!Tsx2cfvduq3{QkYfe;#%>o&E^|#hSv(m$`X2{F!%qMJ diff --git a/standards/templatetags/counter_tag.py b/standards/templatetags/counter_tag.py index f6a6b16..7c8c9cc 100644 --- a/standards/templatetags/counter_tag.py +++ b/standards/templatetags/counter_tag.py @@ -1,6 +1,7 @@ from django import template from django.contrib.auth.models import Group, User from users.models import AgencyGroup +from message.models import Message import os register = template.Library() @@ -48,6 +49,9 @@ def getbool(): return groupbool +@register.simple_tag +def getmesscounter(user): + return len(Message.objects.filter(target_user=user)) # usergperm @@ -82,6 +86,9 @@ def split_dir_style(dirtosplit): @register.filter(name="filename") def filename(value): return os.path.basename(value.file.name) + + + ''' class Counter: count = 0 diff --git a/users/admin.py b/users/admin.py index e12db48..ee9b62e 100644 --- a/users/admin.py +++ b/users/admin.py @@ -2,10 +2,12 @@ from django.contrib import admin from .models import Profile, Agency, AgencyGroup, AgencyJob from .priomodel import Prio from django.contrib.auth.models import Permission +from message.models import Message admin.site.register(Permission) admin.site.register(Profile) admin.site.register(Agency) admin.site.register(AgencyGroup) admin.site.register(AgencyJob) admin.site.register(Prio) +admin.site.register(Message) diff --git a/users/signals.py b/users/signals.py index 1c34c1c..b11e5f0 100644 --- a/users/signals.py +++ b/users/signals.py @@ -10,6 +10,8 @@ from django.template.loader import render_to_string from tasks.models import Tasks from cloud.models import DataFile import os +from django.conf import settings +from django.utils import timezone # Deletes all Notifications added to to delete news @receiver(pre_delete, sender=News) @@ -107,26 +109,37 @@ def save_news(sender, instance, **kwargs): GLOBALSENDMAILS = True if(kwargs["created"]): usersofagency = User.objects.filter(profile__agency__pk=instance.agency.pk) - for user in usersofagency: - if(user.profile.news_mail): - notificationtext = "Neue Agenturnews: " + instance.name + targeturl = settings.BASE_URL + "news/news/" + str(instance.pk) + "/single" + + if(instance.go_online_on < timezone.now() and instance.agnotify): + + for user in usersofagency: - username = user.first_name + " " + user.last_name - msg_html = render_to_string('notificsys/notification_mail.html', {'username': username, 'notificationtext' : notificationtext}) - if(GLOBALSENDMAILS): - send_mail( - 'Agentur-Benachrichtigung', - 'Hallo ' + user.first_name + ' ' + user.last_name + '! ' + notificationtext, - 'support@digitale-agentur.com', - [user.email], - html_message=msg_html, - fail_silently=False - ) + if(user.profile.news_mail): + notificationtext = "Neue Agenturnews: " + instance.name - if(user.profile.news_push): - newnotification = UserNotification(touser=user, notificationtext="Neue Agenturnews: " + instance.name, notificationtype="agencynews", elementid=instance.pk) - newnotification.save() + username = user.first_name + " " + user.last_name + msg_html = render_to_string('notificsys/notification_mail.html', {'username': username, 'notificationtext' : notificationtext, 'linktarget' : targeturl}) + + + if(GLOBALSENDMAILS): + send_mail( + 'Agentur-Benachrichtigung', + 'Hallo ' + user.first_name + ' ' + user.last_name + '! ' + notificationtext, + 'support@digitale-agentur.com', + [user.email], + html_message=msg_html, + fail_silently=False + ) + + if(user.profile.news_push): + newnotification = UserNotification(touser=user, notificationtext="Neue Agenturnews: " + instance.name, notificationtype="agencynews", elementid=instance.pk) + newnotification.save() + else: + instance.agnotify = False + instance.save() + # SIGNALS FOR TASK @receiver(signal=m2m_changed, sender=Tasks.usersfield.through) diff --git a/users/templates/users/base.html b/users/templates/users/base.html index 631c7c8..161c7f9 100644 --- a/users/templates/users/base.html +++ b/users/templates/users/base.html @@ -162,9 +162,13 @@ {% else%} {% endif %} diff --git a/users/urls.py b/users/urls.py index 01a89c1..17a3bf6 100644 --- a/users/urls.py +++ b/users/urls.py @@ -34,7 +34,9 @@ urlpatterns = [ path('datenschutz/', views.datenschutz, name="datenschutzda"), path('impressum/', views.impressum, name="impressumda"), path('setuserparent/', views.setuserparent, name="users-setuserparent"), - path('sendpassmail/', views.sendpassmail, name="users-sendpassmail") + path('sendpassmail/', views.sendpassmail, name="users-sendpassmail"), + path('dacron/', views.cronactions, name="cronmain"), + ] diff --git a/users/views.py b/users/views.py index b6b4b8d..e490187 100644 --- a/users/views.py +++ b/users/views.py @@ -16,6 +16,7 @@ from quicklinks.models import QuickLinks from .priomodel import Prio from standards.models import Standards from datetime import datetime +from django.utils import timezone from django.utils import formats from news.models import News import requests @@ -30,6 +31,8 @@ from io import StringIO from users.models import AgencyJob, AgencyGroup from django.contrib.auth.models import Group from cloud.models import DataDir +from message.models import Message +from notificsys.models import UserNotification def randomString(stringLength=10): """Generate a random string of fixed length """ @@ -615,12 +618,7 @@ def support(request): # HEADERS CURL headers = {'X-API-Key': 'F025A238EB74914E3653BA2989BFF7C4'} subject = "Digitale Agentur: " + str(problemconc) - - #final_img = image['image'] - - #fi = Image.open(final_img) - #print(fi) - + # DataJSON ostdata = { "topicId" : '12', @@ -670,4 +668,48 @@ def impressum(request): if request.user.is_authenticated: return render(request, 'users/impressum.html') else: - return render(request, 'users/impressum_p.html') \ No newline at end of file + return render(request, 'users/impressum_p.html') + +''' + + CRONJOB FUNCTION + +''' +def cronactions(request, code): + + if(code == settings.CRONAPIKEY): + # NEWS CHECKING + all_unnotifc_news = News.objects.filter(agnotify=False, go_online_on__lt=timezone.now()) + + for news in all_unnotifc_news: + targeturl = settings.BASE_URL + "news/news/" + str(news.pk) + "/single" + usersofagency = User.objects.filter(profile__agency=news.agency) + news.agnotify = True + news.save() + + for user in usersofagency: + if(user.profile.news_mail): + notificationtext = "Neue Agenturnews: " + news.name + username = user.first_name + " " + user.last_name + msg_html = render_to_string('notificsys/notification_mail.html', {'username': username, 'notificationtext' : notificationtext, 'linktarget' : targeturl}) + GLOBALSENDMAILS = True + + if(GLOBALSENDMAILS): + send_mail( + 'Agentur-Benachrichtigung', + 'Hallo ' + user.first_name + ' ' + user.last_name + '! ' + notificationtext, + 'support@digitale-agentur.com', + [user.email], + html_message=msg_html, + fail_silently=False + ) + + if(user.profile.news_push): + newnotification = UserNotification(touser=user, notificationtext="Neue Agenturnews: " + news.name, notificationtype="agencynews", elementid=news.pk) + newnotification.save() + + + + else: + print("API CODE FAILED") + return JsonResponse({}) \ No newline at end of file