Browse Source

20240614_1400

Rene 1 year ago
parent
commit
0d40441e83

+ 3 - 0
AD/settings.py

@@ -128,3 +128,6 @@ STATICFILES_DIRS = [
 # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
 # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
 
 
 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
+
+LOGIN_REDIRECT_URL = '/current-week-shifts/'
+LOGOUT_REDIRECT_URL = '/public'

+ 2 - 1
AD/urls.py

@@ -19,8 +19,9 @@ from django.urls import path, include
 from django.views.generic import RedirectView
 from django.views.generic import RedirectView
 from django.urls import re_path as url
 from django.urls import re_path as url
 
 
+
 urlpatterns = [
 urlpatterns = [
-    url(r'^favicon\.ico$',RedirectView.as_view(url='/static/favicon.png')),
+    url(r'^favicon\.ico$', RedirectView.as_view(url='/static/favicon.png')),
     path('admin/', admin.site.urls),
     path('admin/', admin.site.urls),
     path('', include('main.urls'))
     path('', include('main.urls'))
 ]
 ]

BIN
db.sqlite3


+ 3 - 0
main/urls.py

@@ -1,5 +1,6 @@
 from django.urls import path
 from django.urls import path
 from .views import create_multiple_shifts, current_week_shifts, edit_shift, delete_shift, delete_event, edit_event, create_event, public
 from .views import create_multiple_shifts, current_week_shifts, edit_shift, delete_shift, delete_event, edit_event, create_event, public
+from django.contrib.auth import views as auth_views
 
 
 urlpatterns = [
 urlpatterns = [
     path('create-multiple-shifts/', create_multiple_shifts, name='create_multiple_shifts'),
     path('create-multiple-shifts/', create_multiple_shifts, name='create_multiple_shifts'),
@@ -9,5 +10,7 @@ urlpatterns = [
     path('delete-shift/<int:pk>/', delete_shift, name='delete_shift'),
     path('delete-shift/<int:pk>/', delete_shift, name='delete_shift'),
     path('edit-event/<int:pk>/', edit_event, name='edit_event'),
     path('edit-event/<int:pk>/', edit_event, name='edit_event'),
     path('delete-event/<int:pk>/', delete_event, name='delete_event'),
     path('delete-event/<int:pk>/', delete_event, name='delete_event'),
+    path('login/', auth_views.LoginView.as_view(template_name='registration/login.html'), name='login'),
+    path('logout/', auth_views.LogoutView.as_view(next_page='/public'), name='logout'),
     path('public/', public, name='public'),
     path('public/', public, name='public'),
 ]
 ]

+ 7 - 0
main/views.py

@@ -3,6 +3,7 @@ from .forms import MultipleShiftForm, ShiftForm, EventForm
 from .models import Shift, Employee, Location, Event
 from .models import Shift, Employee, Location, Event
 from django.utils.timezone import datetime, timedelta
 from django.utils.timezone import datetime, timedelta
 from django.utils import timezone
 from django.utils import timezone
+from django.contrib.auth.decorators import user_passes_test
 import calendar
 import calendar
 
 
 
 
@@ -66,6 +67,12 @@ def create_event(request):
     return render(request, 'main/create_event.html', {'form': form})
     return render(request, 'main/create_event.html', {'form': form})
 
 
 
 
+# Test function to check if the user is an admin
+def is_admin(user):
+    return user.is_authenticated and user.is_staff
+
+
+@user_passes_test(is_admin, login_url='/public')
 def current_week_shifts(request):
 def current_week_shifts(request):
     # Standardmäßig die aktuelle Woche anzeigen
     # Standardmäßig die aktuelle Woche anzeigen
     today = timezone.now().date()
     today = timezone.now().date()

BIN
requirements.txt


+ 4 - 0
templates/main/current_week_shifts.html

@@ -82,6 +82,10 @@
     <div class="buttons-container">
     <div class="buttons-container">
         <a href="?start_date={{ previous_week }}" class="btn btn-primary">Eine Woche zurück</a>
         <a href="?start_date={{ previous_week }}" class="btn btn-primary">Eine Woche zurück</a>
         <a href="/current-week-shifts/" class="btn btn-primary">Aktuelle Woche</a>
         <a href="/current-week-shifts/" class="btn btn-primary">Aktuelle Woche</a>
+        <form method="post" action="{% url 'logout' %}" style="display: inline;">
+            {% csrf_token %}
+            <button type="submit" class="btn btn-secondary">Logout</button>
+        </form>
         <a href="?start_date={{ next_week }}" class="btn btn-primary">Eine Woche vorwärts</a>
         <a href="?start_date={{ next_week }}" class="btn btn-primary">Eine Woche vorwärts</a>
     </div>
     </div>
     <div class="container-fluid">
     <div class="container-fluid">

+ 7 - 7
templates/main/public.html

@@ -6,7 +6,7 @@
 <html lang="de">
 <html lang="de">
 <head>
 <head>
     <meta charset="UTF-8">
     <meta charset="UTF-8">
-    <meta http-equiv="refresh" content="120; URL=/current-week-shifts/" >
+    <meta http-equiv="refresh" content="120; URL=/public/" >
     <title>Schichten der aktuellen Woche</title>
     <title>Schichten der aktuellen Woche</title>
     <link rel="icon" href="{% static 'favicon.png' %}">
     <link rel="icon" href="{% static 'favicon.png' %}">
     {% bootstrap_css %}
     {% bootstrap_css %}
@@ -20,7 +20,6 @@
         .shift-none {
         .shift-none {
             background-color: white !important;
             background-color: white !important;
             text-align: center;
             text-align: center;
-            cursor: pointer;
         }
         }
         .shift-vacation {
         .shift-vacation {
             background-color: blue !important;
             background-color: blue !important;
@@ -81,7 +80,8 @@
 <body>
 <body>
     <div class="buttons-container">
     <div class="buttons-container">
         <a href="?start_date={{ previous_week }}" class="btn btn-primary">Eine Woche zurück</a>
         <a href="?start_date={{ previous_week }}" class="btn btn-primary">Eine Woche zurück</a>
-        <a href="/current-week-shifts/" class="btn btn-primary">Aktuelle Woche</a>
+        <a href="/public/" class="btn btn-primary">Aktuelle Woche</a>
+        <a href="/login/" class="btn btn-secondary">Login</a>
         <a href="?start_date={{ next_week }}" class="btn btn-primary">Eine Woche vorwärts</a>
         <a href="?start_date={{ next_week }}" class="btn btn-primary">Eine Woche vorwärts</a>
     </div>
     </div>
     <div class="container-fluid">
     <div class="container-fluid">
@@ -103,9 +103,9 @@
                         {% for day, date in days_with_dates %}
                         {% for day, date in days_with_dates %}
                             {% with event=events|get_item:forloop.counter0 %}
                             {% with event=events|get_item:forloop.counter0 %}
                                 {% if event == None %}
                                 {% if event == None %}
-                                    <td class="shift-none" onclick="window.location.href='{% url 'create_event' %}?date={{ date }}'"></td>
+                                    <td class="shift-none"></td>
                                 {% else %}
                                 {% else %}
-                                    <td class="shift-none" onclick="window.location.href='{% url 'edit_event' pk=event.id %}'" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" title="Name: {{ event.name }}<br> Location: {{ event.location }}<br> CVD: {{ event.cvd }}<br> CVT: {{ event.cvt }}">
+                                    <td class="shift-none" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" title="Name: {{ event.name }}<br> Location: {{ event.location }}<br> CVD: {{ event.cvd }}<br> CVT: {{ event.cvt }}">
                                             {% if event.name %}
                                             {% if event.name %}
                                                 {{ event.name }}
                                                 {{ event.name }}
                                             {% else %}
                                             {% else %}
@@ -131,7 +131,7 @@
                         {% for day, date in days_with_dates %}
                         {% for day, date in days_with_dates %}
                             {% with shift=shifts|get_item:forloop.counter0 %}
                             {% with shift=shifts|get_item:forloop.counter0 %}
                                 {% if shift == None %}
                                 {% if shift == None %}
-                                    <td class="shift-none" onclick="window.location.href='{% url 'create_multiple_shifts' %}?date={{ date }}'">
+                                    <td class="shift-none">
                                         F
                                         F
                                     </td>
                                     </td>
                                 {% else %}
                                 {% else %}
@@ -145,7 +145,7 @@
                                         {% else %}
                                         {% else %}
                                             shift-other
                                             shift-other
                                         {% endif %}
                                         {% endif %}
-                                    " onclick="window.location.href='{% url 'edit_shift' pk=shift.id %}'">
+                                    ">
                                             {% if shift.start and shift.end %}
                                             {% if shift.start and shift.end %}
                                                 {{ shift.start|time:"H:i" }} - {{ shift.end|time:"H:i" }}
                                                 {{ shift.start|time:"H:i" }} - {{ shift.end|time:"H:i" }}
                                             {% else %}
                                             {% else %}

+ 38 - 0
templates/registration/login.html

@@ -0,0 +1,38 @@
+{% load bootstrap5 %}
+<!DOCTYPE html>
+<html lang="de">
+<head>
+    <meta charset="UTF-8">
+    <title>Login</title>
+    {% bootstrap_css %}
+    <style>
+        body {
+            font-family: Tahoma, sans-serif;
+            margin: 0;
+            padding: 0;
+            display: flex;
+            justify-content: center;
+            align-items: center;
+            height: 100vh;
+            background-color: #f8f9fa;
+        }
+        .login-container {
+            background: white;
+            padding: 20px;
+            border-radius: 8px;
+            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
+        }
+    </style>
+</head>
+<body>
+    <div class="login-container">
+        <h2>Login</h2>
+        <form method="post">
+            {% csrf_token %}
+            {% bootstrap_form form %}
+            <button type="submit" class="btn btn-primary">Login</button>
+        </form>
+    </div>
+    {% bootstrap_javascript %}
+</body>
+</html>