From 763a3a5247c7215759c677c4de74ce2d0521c774 Mon Sep 17 00:00:00 2001 From: Holger Trampe Date: Sat, 30 May 2020 00:41:17 +0200 Subject: [PATCH] Info welcher Mitarbeiter schon Abwesenheiten in diesem Zeitraum hat --- .../dasettings/change_absence_yeardata.html | 8 +- .../dasettings/data_absence_yeardata.html | 8 +- .../templates/dasettings/user_usprof.html | 8 +- .../__pycache__/urls.cpython-38.pyc | Bin 2500 -> 2584 bytes digitaleagentur/urls.py | 6 +- .../timemanagement/rendered_confirmform.html | 20 +++- .../timemanagement/rendered_table.html | 18 +++- .../timemanagement/tm_ab_management.html | 13 +-- timemanagement/views.py | 29 +++++- users/signals.py | 3 +- users/templates/users/errors/404.html | 6 ++ users/templates/users/errors/500.html | 6 ++ users/views.py | 87 +++++++++++++----- 13 files changed, 169 insertions(+), 43 deletions(-) create mode 100644 users/templates/users/errors/404.html create mode 100644 users/templates/users/errors/500.html diff --git a/dasettings/templates/dasettings/change_absence_yeardata.html b/dasettings/templates/dasettings/change_absence_yeardata.html index 043656a..0bf9564 100644 --- a/dasettings/templates/dasettings/change_absence_yeardata.html +++ b/dasettings/templates/dasettings/change_absence_yeardata.html @@ -19,7 +19,13 @@ {% endfor %} - Resturlaub + Genommener Urlaub + {% for ab_info in user_years.all %} + {{ab_info.days_inuse}} + {% endfor %} + + + Resturlaub aus Vorjahr {% for ab_info in user_years.all %} {% if forloop.counter0 > 0 %} diff --git a/dasettings/templates/dasettings/data_absence_yeardata.html b/dasettings/templates/dasettings/data_absence_yeardata.html index 0bd2818..89c9605 100644 --- a/dasettings/templates/dasettings/data_absence_yeardata.html +++ b/dasettings/templates/dasettings/data_absence_yeardata.html @@ -15,7 +15,13 @@ {% endfor %} - Resturlaub Vorjahr + Genommener Urlaub + {% for ab_info in user_years.all %} + {{ab_info.days_inuse}} + {% endfor %} + + + Resturlaub aus Vorjahr {% for ab_info in user_years.all %} {% if forloop.counter0 > 0 %} {{ab_info.restdays}} diff --git a/dasettings/templates/dasettings/user_usprof.html b/dasettings/templates/dasettings/user_usprof.html index 8fe90ca..88a2929 100644 --- a/dasettings/templates/dasettings/user_usprof.html +++ b/dasettings/templates/dasettings/user_usprof.html @@ -213,7 +213,13 @@ {% endfor %} - Resturlaub + Genommener Urlaub + {% for ab_info in user_years.all %} + {{ab_info.days_inuse}} + {% endfor %} + + + Resturlaub aus Vorjahr {% for ab_info in user_years.all %} {% if forloop.counter0 > 0 %} {{ab_info.restdays}} diff --git a/digitaleagentur/__pycache__/urls.cpython-38.pyc b/digitaleagentur/__pycache__/urls.cpython-38.pyc index 2629cd83f5114a64d063553121e4a5650d454a2c..7b362bb09038859b7896193ddf03c06b5d32df44 100644 GIT binary patch delta 157 zcmX>iJVS&xl$V!_0SI)PF2=o?$Scd}w^7@ji6=@qB_v8EB{Y~pGi-Ai(*qXcDzVby z)S_a&vdq--V!e#Syp){OA`=4>tm38y27a2VlOx&ZG2YtzgI$VIF^UVJ1ZF~pQiHUiR|+jqc$6G aNHKD*WGK=CDlgKSoXr`@=rj2!r#}Faz!HuC diff --git a/digitaleagentur/urls.py b/digitaleagentur/urls.py index c655777..4dc132f 100644 --- a/digitaleagentur/urls.py +++ b/digitaleagentur/urls.py @@ -36,4 +36,8 @@ urlpatterns = [ path('api-token-auth/', obtain_auth_token, name='api-token-auth'), ] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) if settings.DEBUG: - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +# ERROR HANDLERS +handler404 = 'users.views.handler404' +handler500 = 'users.views.handler500' \ No newline at end of file diff --git a/timemanagement/templates/timemanagement/rendered_confirmform.html b/timemanagement/templates/timemanagement/rendered_confirmform.html index 4c6089c..6db32f0 100644 --- a/timemanagement/templates/timemanagement/rendered_confirmform.html +++ b/timemanagement/templates/timemanagement/rendered_confirmform.html @@ -1,4 +1,5 @@ {% load crispy_forms_tags %} +{% load mathfilters %}
Abwesenheit für {{absence.user.first_name}} {{absence.user.last_name}} annehmen oder ablehnen

Informationen der Abwesenheit
@@ -7,6 +8,23 @@ Bis: {{absence.end|date:"d.m Y"}}
Grund: {{absence.reason.name}}
Informationen: {{absence.info}}

+
Übersicht Urlaubstage wenn Anfrage genehmigt
+ + + + + + + + + + + + + + + +
Gewünschte Tage{{absence.holidays_normal|addition:absence.holidays_rest|addition:absence.holidays_normal_next|addition:absence.holidays_rest_next}}
Resturlaub {{absence.start.year}}{{timeinfo_thisyear.restdays|addition:timeinfo_thisyear.days|sub:timeinfo_thisyear.days_inuse|addition:absence.holidays_rest}}
Resturlaub {{timeinfo_nextyear.year}}{{timeinfo_nextyear.restdays|addition:timeinfo_nextyear.days|sub:timeinfo_nextyear.days_inuse|addition:absence.holidays_rest_next}}
{% csrf_token %} @@ -20,4 +38,4 @@ Informationen: {{absence.info}}
\ No newline at end of file + diff --git a/timemanagement/templates/timemanagement/rendered_table.html b/timemanagement/templates/timemanagement/rendered_table.html index a2590dc..948a3ab 100644 --- a/timemanagement/templates/timemanagement/rendered_table.html +++ b/timemanagement/templates/timemanagement/rendered_table.html @@ -369,7 +369,13 @@ function recalculateChoosenDays(){ success : function(data){ - console.log(data); + if(data["other_absences"] != false){ + $("#otherholidays").show(); + $("#otherholidays_users").html(data["other_absences"]); + } + else{ + $("#otherholidays").hide(); + } $("#startAbsenceProgress").modal("show"); @@ -434,7 +440,15 @@ function recalculateChoosenDaysAfterInit(){ endday_info : $("#id_endday_info").val(), }, success : function(data){ - console.log(data); + + if(data["other_absences"] != false){ + $("#otherholidays").show(); + $("#otherholidays_users").html(data["other_absences"]); + } + else{ + $("#otherholidays").hide(); + } + $("#restholidays").html(data["restholiday_thisyear"]); $("#detail_rest").html(data["restholiday_thisyear"]); $("#detail_resthol").html(data["restholiday_lastyear"]); diff --git a/timemanagement/templates/timemanagement/tm_ab_management.html b/timemanagement/templates/timemanagement/tm_ab_management.html index d06d1ae..01a607f 100644 --- a/timemanagement/templates/timemanagement/tm_ab_management.html +++ b/timemanagement/templates/timemanagement/tm_ab_management.html @@ -126,12 +126,7 @@ - - + +
{{abscenceform.nextmonth}} diff --git a/timemanagement/views.py b/timemanagement/views.py index 894353e..0fab956 100644 --- a/timemanagement/views.py +++ b/timemanagement/views.py @@ -380,9 +380,18 @@ def TimeAjax(request): # GET FORM FOR CONFIRM ABSENCE elif request.GET["action"] == "getrenderedform": + absence = Absence.objects.get(pk=request.GET["abscenceid"]) + timeinfo_thisyear = list(UserYearAbsenceInfo.objects.filter(year=absence.start.year, user=absence.user))[0] + try: + timeinfo_nextyear = list(UserYearAbsenceInfo.objects.filter(year=absence.start.year+1, user=absence.user))[0] + except: + timeinfo_nextyear = False + context = { "confirmform" : ConfirmAbsenceForm(instance=request.user), - "absence" : Absence.objects.get(pk=request.GET["abscenceid"]) + "absence" : absence, + "timeinfo_thisyear" : timeinfo_thisyear, + "timeinfo_nextyear" : timeinfo_nextyear } return render(request, "timemanagement/rendered_confirmform.html", context) @@ -506,7 +515,15 @@ def TimeAjax(request): holiday_nextyear += temprest days_nextyear_rest = need_days_next + temprest days_nextyear_normal = temprest * -1 - + + other_absences = Absence.objects.filter(start__lte=start_day_obj, end__gte=end_day_obj, agency=request.user.profile.agency) | Absence.objects.filter(start__lte=start_day_obj, end__lte=end_day_obj, agency=request.user.profile.agency) | Absence.objects.filter(start__gte=start_day_obj, end__lte=start_day_obj, agency=request.user.profile.agency) | Absence.objects.filter(start__lte=end_day_obj, end__gte=end_day_obj, agency=request.user.profile.agency) + + other_absences_string = False + if (len(other_absences) > 0): + other_absences_string = "" + for a in other_absences: + other_absences_string += a.user.first_name + " " + a.user.last_name + " - Vom " + a.start.strftime("%d.%m.%Y") + " bis " + a.end.strftime("%d.%m.%Y") + "
" + data = { "restholiday_thisyear" : holiday_thisyear, "restholiday_lastyear" : holiday_lastyear, @@ -516,6 +533,7 @@ def TimeAjax(request): "need_days" : need_days, "need_days_next" : need_days_next, "need_days_this" : need_days_this, + "other_absences" : other_absences_string } # REQUEST USER NO RIGHTS else: @@ -578,16 +596,16 @@ def calculatingHolidaysByAbsence(request, absence): # Start und Ende gleich, nur ein Tag. Checken, ob Halber Tag if(absence.start == absence.end): - if abscence.startday_info == "1" or abscence.startday_info == "2": + if absence.startday_info == "1" or absence.startday_info == "2": finalholidayinabsence = 0.5 else: finalholidayinabsence = 1 return finalholidayinabsence else: - if abscence.startday_info == "1" or abscence.startday_info == "2": + if absence.startday_info == "1" or absence.startday_info == "2": finalholidayinabsence -= 0.5 - if abscence.endday_info == "1" or abscence.endday_info == "2": + if absence.endday_info == "1" or absence.endday_info == "2": finalholidayinabsence -= 0.5 weekdays = [6,7] @@ -608,3 +626,4 @@ def daterange(date1, date2): for n in range(int ((date2 - date1).days)+1): yield date1 + timedelta(n) + diff --git a/users/signals.py b/users/signals.py index 6d08a1f..2d33bd8 100644 --- a/users/signals.py +++ b/users/signals.py @@ -500,13 +500,12 @@ def delete_absence(sender, instance, **kwargs): multiple_info_needays = False if(hasattr(newdata[3], "__len__")): multiple_info_needays = True - + # Mehrere Jahre oder nicht if(instance.start.year != instance.end.year): abinfo.days_inuse = abinfo.days_inuse - instance.holidays_normal abinfo.save() abinfo_nextyear.days_inuse = abinfo_nextyear.days_inuse - instance.holidays_normal_next abinfo_nextyear.restdays = abinfo_nextyear.restdays + instance.holidays_rest_next - abinfo_nextyear.save() else: # Gleiches Jahr MIT Rest diff --git a/users/templates/users/errors/404.html b/users/templates/users/errors/404.html new file mode 100644 index 0000000..069b22f --- /dev/null +++ b/users/templates/users/errors/404.html @@ -0,0 +1,6 @@ +{% extends "users/base.html" %} +{% block content %} +
+

Hopala! Fehler 404 - Die aufgerufene Seite existiert nicht.

+
+{% endblock content %} \ No newline at end of file diff --git a/users/templates/users/errors/500.html b/users/templates/users/errors/500.html new file mode 100644 index 0000000..1534fae --- /dev/null +++ b/users/templates/users/errors/500.html @@ -0,0 +1,6 @@ +{% extends "users/base.html" %} +{% block content %} +
+

Hopala! Fehler 500 - Interner Serverfehler. Bitte kontaktieren Sie den Support!

+
+{% endblock content %} \ No newline at end of file diff --git a/users/views.py b/users/views.py index e2e585c..62aecab 100644 --- a/users/views.py +++ b/users/views.py @@ -7,7 +7,7 @@ from django.views.generic import CreateView, ListView, UpdateView, DetailView, D from django.contrib import messages from django.contrib.auth.models import User, Permission from django.db import models -from .models import Profile, Agency, UserTime +from .models import Profile, Agency, UserTime, UserYearAbsenceInfo from django.core.mail import send_mail from django.http import HttpResponseRedirect,HttpResponse, JsonResponse from areas.models import Areas @@ -40,6 +40,7 @@ from asgiref.sync import async_to_sync from channels_presence.models import Room from channels_presence.models import Presence import channels.layers +from datetime import date def randomString(stringLength=10): """Generate a random string of fixed length """ @@ -801,6 +802,25 @@ def impressum(request): else: return render(request, 'users/impressum_p.html') +''' + + ERROR HANDLER VIEWS + +''' +def handler404(request, exception): + context = {} + response = render(request, "users/errors/404.html", context=context) + response.status_code = 404 + return response + + +def handler500(request): + context = {} + response = render(request, "users/errors/500.html", context=context) + response.status_code = 500 + return response + + ''' CRONJOB FUNCTION @@ -811,43 +831,63 @@ def cronactions(request, code): if(code == settings.CRONAPIKEY): # NEWS CHECKING all_unnotifc_news = News.objects.filter(agnotify=False, go_online_on__lt=timezone.now()) - + allusers = User.objects.all() 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): + for user in allusers: + if(user.profile.news_mail and news.agency == user.profile.agency): 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 + send_mail( + 'Agentur-Benachrichtigung', + 'Hallo ' + user.first_name + ' ' + user.last_name + '! ' + notificationtext, + 'noreply@digitale-agentur.com', + [user.email], + html_message=msg_html, + fail_silently=True + ) - if(GLOBALSENDMAILS): - send_mail( - 'Agentur-Benachrichtigung', - 'Hallo ' + user.first_name + ' ' + user.last_name + '! ' + notificationtext, - 'noreply@digitale-agentur.com', - [user.email], - html_message=msg_html, - fail_silently=True - ) - - if(user.profile.news_push): + if(user.profile.news_push and news.agency == user.profile.agency): newnotification = UserNotification(touser=user, notificationtext="Neue Agenturnews: " + news.name, notificationtype="agencynews", elementid=news.pk) newnotification.save() - # TODO: CronJob für REST-Urlaub implementieren - ''' - - Pro User gibt es das Feld loose_holiday in der UserTime-Info. Ist dieser Tag vorbei, muss die Differenz der days_inuse des VORJHARES in den Rest das AKTUELLEN JAHRES gespeichert werden! + # TODO: CronJob für REST-Urlaub implementieren + ''' + + Pro User gibt es das Feld loose_holiday in der UserTime-Info. Ist dieser Tag vorbei, muss die Differenz der days_inuse des VORJHARES in den Rest das AKTUELLEN JAHRES gespeichert werden! - ''' + ''' + today = date.today() + for user in allusers: + usertimedata = UserTime.objects.get(user=user) - data.update({"status" : "ok"}) + day_tocheck = usertimedata.loose_holidedate.split(".")[0] + month_tocheck = usertimedata.loose_holidedate.split(".")[1] + + month = today.month + + if month < 10: + month = "0" + str(month) + + day = today.day + if day < 10: + day = "0" + str(day) + + # Restetag erreicht, Reste ins nächste Jahr übertragen + if(str(day_tocheck) == str(day) and str(month_tocheck) == str(month)): + sourceyear = today.year + this_year = list(UserYearAbsenceInfo.objects.filter(year=sourceyear, user=user))[0] + next_year = list(UserYearAbsenceInfo.objects.filter(year=sourceyear+1, user=user))[0] + next_year.restdays = this_year.days - this_year.days_inuse + next_year.save() + + data.update({"status" : "ok"}) elif(code == settings.MAILINFOKEY): pass ''' @@ -876,3 +916,4 @@ def cronactions(request, code): print("API CODE FAILED") data.update({"status" : "failed"}) return JsonResponse(data) +