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 b975009..12b4edc 100644 Binary files a/digitaleagentur/__pycache__/settings.cpython-38.pyc and b/digitaleagentur/__pycache__/settings.cpython-38.pyc differ diff --git a/digitaleagentur/__pycache__/urls.cpython-38.pyc b/digitaleagentur/__pycache__/urls.cpython-38.pyc index 7f386bd..94df5d0 100644 Binary files a/digitaleagentur/__pycache__/urls.cpython-38.pyc and b/digitaleagentur/__pycache__/urls.cpython-38.pyc differ 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' %}