From 9ff6268b8a21973e67a32f8a84085582506b09c3 Mon Sep 17 00:00:00 2001 From: "holger.trampe" Date: Fri, 9 Oct 2020 17:24:57 +0200 Subject: [PATCH] =?UTF-8?q?Erste=20Adminoberfl=C3=A4che=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 + adm/__init__.py | 0 adm/admin.py | 3 + adm/apps.py | 5 + adm/migrations/__init__.py | 0 adm/models.py | 12 + adm/templates/adm/adm_agencys.html | 50 ++ adm/templates/adm/adm_base.html | 694 ++++++++++++++++++ adm/templates/adm/adm_main.html | 52 ++ adm/tests.py | 3 + adm/urls.py | 14 + adm/views.py | 70 ++ .../__pycache__/settings.cpython-38.pyc | Bin 4635 -> 4733 bytes .../__pycache__/urls.cpython-38.pyc | Bin 2906 -> 2945 bytes digitaleagentur/settings.py | 2 + digitaleagentur/urls.py | 1 + users/templates/users/base.html | 16 +- users/templates/users/login.html | 10 + 18 files changed, 935 insertions(+), 2 deletions(-) create mode 100644 adm/__init__.py create mode 100644 adm/admin.py create mode 100644 adm/apps.py create mode 100644 adm/migrations/__init__.py create mode 100644 adm/models.py create mode 100644 adm/templates/adm/adm_agencys.html create mode 100644 adm/templates/adm/adm_base.html create mode 100644 adm/templates/adm/adm_main.html create mode 100644 adm/tests.py create mode 100644 adm/urls.py create mode 100644 adm/views.py diff --git a/.gitignore b/.gitignore index 1dbb8ac..8d9f576 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,11 @@ areas/migrations/* !areas/migrations/__init__.py areas/__pycache__/* + +adm/migrations/* +!adm/migrations/__init__.py +adm/__pycache__/* + standards/migrations/* !standards/migrations/__init__.py standards/__pycache__/* diff --git a/adm/__init__.py b/adm/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adm/admin.py b/adm/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/adm/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/adm/apps.py b/adm/apps.py new file mode 100644 index 0000000..da47601 --- /dev/null +++ b/adm/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class AdmConfig(AppConfig): + name = 'adm' diff --git a/adm/migrations/__init__.py b/adm/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/adm/models.py b/adm/models.py new file mode 100644 index 0000000..c2edf13 --- /dev/null +++ b/adm/models.py @@ -0,0 +1,12 @@ +from django.db import models +from django.utils import timezone +# Create your models here. +# MAIN RECOVERDIR PASSWORD AND CONFIG +class MainStatistic(models.Model): + staticdate = models.DateField(default=timezone.now) + agencys = models.IntegerField(default=0) + users = models.IntegerField(default=0) + standards = models.IntegerField(default=0) + chatmessages = models.IntegerField(default=0) + + diff --git a/adm/templates/adm/adm_agencys.html b/adm/templates/adm/adm_agencys.html new file mode 100644 index 0000000..a602d77 --- /dev/null +++ b/adm/templates/adm/adm_agencys.html @@ -0,0 +1,50 @@ +{% extends "adm/adm_base.html" %} +{% block content %} +
+

Agenturübersicht

+
+ + + + + + + + + + {% for ele in agencys %} + + + + + + + + {% endfor %} + +
AgenturnameMitarbeiterStandards
{{ele.name}}
+
+ +{% endblock content %} \ No newline at end of file diff --git a/adm/templates/adm/adm_base.html b/adm/templates/adm/adm_base.html new file mode 100644 index 0000000..0e2a530 --- /dev/null +++ b/adm/templates/adm/adm_base.html @@ -0,0 +1,694 @@ +{% load static %} +{% load counter_tag %} + + + + + + + + + + Digitale Agentur - Administrativer Bereich + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
+ + + + + + +
+ + +
+ + {% if messages %} + {% for message in messages %} + + {% endfor %} + {% endif %} + {% block content %} + {% endblock %} +
+
 
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +{% if request.user.profile.showtooltips %} + +{% endif %} + + + + + + diff --git a/adm/templates/adm/adm_main.html b/adm/templates/adm/adm_main.html new file mode 100644 index 0000000..579c140 --- /dev/null +++ b/adm/templates/adm/adm_main.html @@ -0,0 +1,52 @@ +{% extends "adm/adm_base.html" %} +{% block content %} +
+

Statistikdaten über alle

+
+ + + + + + + + + + + + {% for ele in statistik %} + + + + + + + + {% endfor %} + +
DatumAgenturenBenutzerStandardsChatnachrichten
{{ele.staticdate|date:"d.m.Y"}}{{ele.agencys}}{{ele.users}}{{ele.standards}}{{ele.chatmessages}}
+
+ +{% endblock content %} \ No newline at end of file diff --git a/adm/tests.py b/adm/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/adm/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/adm/urls.py b/adm/urls.py new file mode 100644 index 0000000..82dc024 --- /dev/null +++ b/adm/urls.py @@ -0,0 +1,14 @@ +from django.urls import path +from .views import * +from django.contrib.auth.decorators import login_required, permission_required +from django.contrib.admin.views.decorators import staff_member_required + +''' +Permissions definiert in models.py bei USERS und dann hier vor die View geschrieben! +''' + +urlpatterns = [ + path('', AdmMain.as_view(), name='adm-main'), + path('ag/', AdmAgencys.as_view(), name="adm-agencys"), + path('cron/', statisticCronJob, name="adm-cron") +] diff --git a/adm/views.py b/adm/views.py new file mode 100644 index 0000000..3e40af1 --- /dev/null +++ b/adm/views.py @@ -0,0 +1,70 @@ +from django.views.generic import CreateView, ListView, UpdateView, DetailView, DeleteView, FormView, TemplateView +from django.contrib import messages +from django.shortcuts import render, redirect, reverse +from django.conf import settings +from django.http import HttpResponseRedirect,HttpResponse, JsonResponse +from .models import MainStatistic +from django.contrib.auth.models import User +from chat.models import ChatMessage +from users.models import Agency +from standards.models import Standards + +def checkForStuffUser(request): + if request.user.is_staff: + return True + else: + return False + + +class AdmMain(TemplateView): + template_name = "adm/adm_main.html" + + def dispatch(self, *args, **kwargs): + if(checkForStuffUser(self.request)): + return super().dispatch(*args, **kwargs) + else: + messages.warning(self.request, f'Sie benötigen einen Mitarbeiter-Account, um diese Seiten aufzurufen!') + return redirect("login") + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + context.update({'active_link' : "adm-statistic"}) + + context.update({'statistik' : MainStatistic.objects.all().order_by('-staticdate')}) + + return context + +class AdmAgencys(TemplateView): + template_name = "adm/adm_agencys.html" + + def dispatch(self, *args, **kwargs): + if(checkForStuffUser(self.request)): + return super().dispatch(*args, **kwargs) + else: + messages.warning(self.request, f'Sie benötigen einen Mitarbeiter-Account, um diese Seiten aufzurufen!') + return redirect("login") + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + + context.update({'active_link' : "adm-agencys"}) + + context.update({'agencys' : Agency.objects.all()}) + + return context + +# CRONJOB, um die Statistik zu füllen! +def statisticCronJob(request, code): + data = {} + if(code == settings.CRONAPIKEY_STATSTIC): + print("STATISTIC is running...") + newMainS = MainStatistic(agencys=len(Agency.objects.all()),users=len(User.objects.all().exclude(is_staff=True, is_superuser=True)),standards=len(Standards.objects.all()),chatmessages=len(ChatMessage.objects.all())) + newMainS.save() + data.update({"status" : "success"}) + else: + print("API STATISTIC CODE FAILED") + data.update({"status" : "failed"}) + return JsonResponse(data) + + \ No newline at end of file diff --git a/digitaleagentur/__pycache__/settings.cpython-38.pyc b/digitaleagentur/__pycache__/settings.cpython-38.pyc index b97500910b50164a4512ffc60444c6e63c421d9e..12b4edc239a640f3e4cb57775fa87dba837fb25d 100644 GIT binary patch delta 490 zcmYk0OHWf#6ov0Ty_A9}DUS$ZRjieVg^D~{R35#yNXr{;QQ1D~(RDrCCL|=+PAUlw zoH8IC(m^|SVmfo~%)cNL|AR9V4-F*lo%JPaWoKudM*l`*JHcSPq37)Ib78*UFn*t# z|0kkNO3V9s5-SP5dQwXrVFHsX!o8TnG!jT+1`qKFk1?y-xDRuD4fD!C2n$HT!V{#G z=@K$kQxW%L5l9>Gh#=TNbw=5I3Q1nN{Lyy`W0w3&=K zqj+5x9LF2Jf04AIpp$XDMidhuGy?7@pg689?hEble+ zE#{~W^H{*5Qm-<8v!sg}qXs0f%v}O2CX*&tHKt0`h!o#k87VNV=~imOIyECrK5S46 zoYczYM}`8}q#(Aa4cpX?9SSMzw4!J=*`ZXGSc!q$0?B65smRzZiPVKX>i$b?*yl+P z4yd=B@}GUkQW%FGIC;+qj&O_ zni*4Mp?p&y-wen%hw?2_*|X%bq*E+YtWvCdnNn<^;d7!vm3V$zSiak`+0Vt{f z6mgm*JzGt*=nCW(5W zYXYGXK|qP%l#rCrUZ!Rypb=p}emGD*0xBPwDw+}nWk;t9E|6ZxkSY%4$D|4%`028# z+^L*d%0R4=65Gop&Jd*vWUEbJDq5AQ3YJp`@-={R!c68s$&|P#&6M~kt(1gd2F=9H z*O+*iL|772a`me?fTUh&QBLtKW*}?xLzdmFY$m{fE;5vb>L( Q6!;#nC~`20FtacM0LZm+1^@s6 delta 400 zcmZn^za^#}%FD~e00e8_*2VktFfcp@agc!mkmCTv#mhEo=P=gGrU>>jr!uD)rLv?L zH#4S~K>4Pr>{)VI(kW&s<|!7vOevO7aVwy>JW$*^g};|E#Re*B3lvoVirRri?V+L$ zKv6}Ys3Ta^2`cKG%9r8-WxJ}SvSlfyxIww@Ku35qGd42;9pnjQdjTEf4U(H|!z59k z5||Ry%LJAT21Oj5*NX{H6ml7SNnGzGFl@c4w%%B;!`56-r(`I(oU94=z lz%VQ_o_w4uf-z>Y0=N0(NN#D~Crt8u4_OpA7)6*_7y)U}WSIZ} diff --git a/digitaleagentur/settings.py b/digitaleagentur/settings.py index a8ef592..caa0d6c 100644 --- a/digitaleagentur/settings.py +++ b/digitaleagentur/settings.py @@ -38,6 +38,7 @@ X_FRAME_OPTIONS = 'SAMEORIGIN' SECRET_KEY = '_qv2t2lmsctjxpbb4rrp=op%_20_hxzonv^mvty1o85c)l$s^q' CRONAPIKEY = "gCddsaz6NOnE9QbXZM5LasdEk122D" +CRONAPIKEY_STATSTIC = "aiszdausd876asdtuzagshjdajgAHGJHSDSD67daiuhdj" MAILINFOKEY = "jka7sd8iukashdna78skduJAHDsu6dilaksdjba65a68iadbhjak" # API KEY LEXOFFICE LEX_API = "8f9ba01f-9e84-42c7-9548-48c254f14c19" @@ -68,6 +69,7 @@ INSTALLED_APPS = [ 'timemanagement.apps.TimemanagementConfig', 'recoverdir.apps.RecoverdirConfig', 'news.apps.NewsConfig', + 'adm.apps.AdmConfig', 'crispy_forms', 'colorful', 'django_summernote', diff --git a/digitaleagentur/urls.py b/digitaleagentur/urls.py index bb0eec8..f772138 100644 --- a/digitaleagentur/urls.py +++ b/digitaleagentur/urls.py @@ -22,6 +22,7 @@ urlpatterns = [ path('areas/', include('areas.urls'), name="areas-management"), path('tasks/', include('tasks.urls'), name="tasks-management"), path('organizer/', include('organizer.urls'), name="ql-management"), + path('adm/', include('adm.urls'), name="adm"), path('cloud/', include('cloud.urls'), name="cloud-main"), path('standards/', include('standards.urls'), name="standards"), path('rd/', include('recoverdir.urls'), name="recoverdir"), diff --git a/users/templates/users/base.html b/users/templates/users/base.html index 9237a03..9e641e8 100644 --- a/users/templates/users/base.html +++ b/users/templates/users/base.html @@ -232,7 +232,18 @@
- {% if active_link == 'dasettings' %} + {% if request.user.is_staff %} + + {% endif %} + + + + {% if active_link == 'dasettings' %} - {% if active_link == 'support' %} + + {% if active_link == 'support' %}