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 9c74d84..08ab686 100644 Binary files a/news/__pycache__/models.cpython-38.pyc and b/news/__pycache__/models.cpython-38.pyc differ diff --git a/news/models.py b/news/models.py index a5f6a10..4bf8dd4 100644 --- a/news/models.py +++ b/news/models.py @@ -14,15 +14,17 @@ class News(models.Model): #content = RichTextUploadingField(blank=True, verbose_name='Inhalt') content = models.TextField(blank=True, verbose_name='Inhalt', default="") - created_by = models.ForeignKey(User, on_delete=models.PROTECT) + created_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True) created_date = models.DateTimeField(default=timezone.now, blank=True) go_online_on = models.DateTimeField(default=timezone.now, blank=True) # Default date plus two weeks go_offline_on = models.DateTimeField(default=timezone.now()+timedelta(days=14), blank=True) - last_modified_by = models.ForeignKey(User, on_delete=models.PROTECT, related_name='news_mod_by', default=None) + last_modified_by = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='news_mod_by', default=None) last_modified_on = models.DateTimeField(default=timezone.now, blank=True) + + agnotify = models.BooleanField(default=True) def __str__(self): return f'{self.name}' diff --git a/news/templates/news/news_addnews.html b/news/templates/news/news_addnews.html index c3690db..e80c0be 100644 --- a/news/templates/news/news_addnews.html +++ b/news/templates/news/news_addnews.html @@ -4,8 +4,7 @@ {% block content %} {% if request.user.profile.agency.module_news %}
- - +

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 b959d3d..5325431 100644 Binary files a/standards/templatetags/__pycache__/counter_tag.cpython-38.pyc and b/standards/templatetags/__pycache__/counter_tag.cpython-38.pyc differ 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