Эх сурвалжийг харах

Umbau mit Login,
/ -> Web ansicht rechner
/public -> webansicht Display Wand

Rene 9 сар өмнө
parent
commit
08708e799d

BIN
db.sqlite3


+ 3 - 2
main/urls.py

@@ -1,7 +1,7 @@
 from django.urls import path
 from .views import (create_multiple_shifts, edit_shift, delete_shift, delete_event, edit_event,
                     create_event, public, create_helper, edit_helper, delete_helper, create_reinigung, edit_reinigung,
-                    delete_reinigung, ma_month)
+                    delete_reinigung, ma_month, home)
 from django.contrib.auth import views as auth_views
 
 urlpatterns = [
@@ -20,5 +20,6 @@ urlpatterns = [
     path('ma-month/<int:mitarbeiter_id>/<int:monat>/<int:jahr>/', ma_month, name='ma_month'),
     path('login/', auth_views.LoginView.as_view(template_name='registration/login.html'), name='login'),
     path('logout/', auth_views.LogoutView.as_view(next_page='/'), name='logout'),
-    path('', public, name='public'),
+    path('public/', public, name='public'),
+    path('', home, name='home'),
 ]

+ 83 - 0
main/views.py

@@ -123,6 +123,89 @@ def is_admin(user):
     return user.is_authenticated and user.is_staff
 
 
+def home(request):
+    # Standardmäßig die aktuelle Woche anzeigen
+    today = timezone.now().date()
+
+    # Überprüfen, ob ein Startdatum in der URL angegeben ist
+    start_date_str = request.GET.get('start_date')
+    if start_date_str:
+        try:
+            start_of_week = datetime.strptime(start_date_str, '%Y-%m-%d').date()
+        except ValueError:
+            start_of_week = today - timedelta(days=today.weekday())  # Fallback auf die aktuelle Woche bei Fehler
+    else:
+        start_of_week = today - timedelta(days=today.weekday())  # Montag der aktuellen Woche
+
+    end_of_week = start_of_week + timedelta(days=6)  # Sonntag der aktuellen Woche
+
+    # Berechnung für die nächste und vorherige Woche
+    previous_week = start_of_week - timedelta(days=7)
+    next_week = start_of_week + timedelta(days=7)
+
+    # Berechnung der Kalenderwoche
+    calendar_week = start_of_week.isocalendar()[1]
+
+    # Initialisiere ein Dictionary für die Schichten der Mitarbeiter
+    shifts_by_employee = {}
+    events_by_location = {}
+    helpers_by_date = {}
+    employees = Employee.objects.all()
+    locations = Location.objects.all()
+    helpers = Helper.objects.all()
+
+    for employee in employees:
+        shifts_by_employee[employee] = {day: None for day in range(7)}
+
+    for location in locations:
+        events_by_location[location] = {day: None for day in range(7)}
+
+    for helper in helpers:
+        helpers_by_date = {day: None for day in range(7)}
+
+        # Hole alle Schichten für die aktuelle Woche
+    shifts = Shift.objects.filter(date__range=[start_of_week, end_of_week])
+
+    events = Event.objects.filter(date__range=[start_of_week, end_of_week])
+
+    helpers = Helper.objects.filter(date__range=[start_of_week, end_of_week])
+
+
+    # Fülle das Dictionary mit den Schichtdaten
+    for shift in shifts:
+        employee = shift.employee
+        day_of_week = (shift.date - start_of_week).days
+        shifts_by_employee[employee][day_of_week] = shift
+
+    for event in events:
+        location = event.location
+        day_of_week = (event.date - start_of_week).days
+        events_by_location[location][day_of_week] = event
+
+    for helper in helpers:
+        day_of_week = (helper.date - start_of_week).days
+        helpers_by_date[day_of_week] = helper
+
+    # Bereite die Daten der Woche für das Template vor
+    week_dates = [(start_of_week + timedelta(days=i)).strftime("%d.%m.%Y") for i in range(7)]
+    days_of_week = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']
+    days_with_dates = list(zip(days_of_week, week_dates))
+
+    context = {
+        'shifts_by_employee': shifts_by_employee,
+        'events_by_location': events_by_location,
+        'helpers_by_date': helpers_by_date,
+        'start_of_week': start_of_week,
+        'end_of_week': end_of_week,
+        'days_with_dates': days_with_dates,
+        'range_days': range(7),
+        'previous_week': previous_week.strftime('%Y-%m-%d'),
+        'next_week': next_week.strftime('%Y-%m-%d'),
+        'calendar_week': calendar_week,
+    }
+    return render(request, 'main/home.html', context)
+
+
 def public(request):
     # Standardmäßig die aktuelle Woche anzeigen
     today = timezone.now().date()

+ 237 - 0
templates/main/home.html

@@ -0,0 +1,237 @@
+{% load static %}
+{% load custom_tags %}
+{% load bootstrap5 %}
+
+<!DOCTYPE html>
+<html lang="de">
+<head>
+    <meta charset="UTF-8">
+    <title>Dienstplan</title>
+    <link rel="icon" href="{% static 'favicon.png' %}">
+    {% bootstrap_css %}
+    <style>
+        body {
+            font-family: Tahoma, sans-serif;
+            margin: 0;
+            padding: 0;
+            font-size: 10px; /* Set the base font size */
+        }
+        .shift-none {
+            background-color: white !important;
+            text-align: center !important;
+            {% if user.is_authenticated %}
+                cursor: pointer !important;
+            {% endif %}
+        }
+        .shift-vacation {
+            background-color: blue !important;
+            color: white !important;
+            text-align: center;
+        }
+        .shift-sick {
+            background-color: yellow !important;
+            text-align: center;
+        }
+        .shift-other {
+            background-color: gray !important;
+            color: white !important;
+            text-align: center;
+        }
+        .buttons-container {
+            display: flex;
+            justify-content: space-between;
+            padding: 10px;
+            background-color: #f8f9fa;
+            border-bottom: 1px solid #dee2e6;
+        }
+        .container-fluid {
+            padding-top: 10px; /* Reduce the padding to remove extra space */
+        }
+        a {
+            color: black;
+            text-decoration: none;
+        }
+        a:hover {
+            color: black;
+        }
+        .employee-name {
+            text-align: left;
+            font-weight: bold;
+            width: 150px; /* Set a fixed width for the employee column */
+        }
+        .day-name {
+            text-align: center;
+            width: 150px; /* Set a fixed width for the employee column */
+        }
+        .table th, .table td {
+            vertical-align: middle;
+            width: 100px; /* Set a fixed width for all other columns */
+            padding: 4px; /* Reduce padding to decrease row height */
+            line-height: 1.2; /* Adjust line height to decrease row height */
+        }
+        .custom-heading {
+            margin: 0; /* Remove margin to eliminate extra space */
+        }
+        @media print {
+            .btn {
+                display: none; /* Hide the buttons when printing */
+            }
+        }
+    </style>
+</head>
+<body>
+    <div class="container-fluid">
+        <table class="table">
+            <tr>
+                <td><a href="?start_date={{ previous_week }}" class="btn btn-primary text-start">Eine Woche zurück</a></td>
+                <td><a href="/" class="btn btn-primary">Aktuelle Woche</a></td>
+                <td><h4 class="custom-heading text-center">Dienstplan für KW {{ calendar_week }}</h4></td>
+                <td class="text-end">{% if user.is_authenticated %}
+                        <form method="post" action="{% url 'logout' %}" style="display: inline;">
+                            {% csrf_token %}
+                            <button type="submit" class="btn btn-secondary">Logout</button>
+                        </form>
+                    {% else %}
+                        <a href="/login/" class="btn btn-secondary">Login</a>
+                    {% endif %}</td>
+                <td class="text-end"><a href="?start_date={{ next_week }}" class="btn btn-primary">Eine Woche vorwärts</a></td>
+            </tr>
+        </table>
+        {% if user.is_authenticated %}
+        <div class="table-responsive">
+            <table class="table  table-bordered table-striped table-hover w-100">
+                <thead class="table-dark">
+                    <tr>
+                        <th class="employee-name">Veranstaltungen</th>
+                        {% for day, date in days_with_dates %}
+                        <th class="day-name">{{ day }} {{ date }}</th>
+                        {% endfor %}
+                    </tr>
+                </thead>
+                <tbody>
+                    {% for location, events in events_by_location.items %}
+                    <tr>
+                        <td class="employee-name">{{ location.name }}</td>
+                        {% for day, date in days_with_dates %}
+                            {% with event=events|get_item:forloop.counter0 %}
+                                {% if event == None %}
+                                    {% if user.is_authenticated %}
+                                        <td class="shift-none" onclick="window.location.href='{% url 'create_event' %}?date={{ date }}'">--</td>
+                                    {% else %}
+                                        <td class="shift-none">--</td>
+                                    {% endif %}
+                                {% else %}
+                                    <td class="shift-none" {% if user.is_superuser %} onclick="window.location.href='{% url 'edit_event' pk=event.id %}'" {% endif %} data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" title="Name: {{ event.name }}<br> Location: {{ event.location }}<br> Belegung: {{ event.belegung }}<br> PAX: {{ event.pax }}<br> CVD: {{ event.cvd }}<br> CVT: {{ event.cvt }}<br> Info: {{ event.info }}">
+                                            {% if event.name %}
+                                                {{ event.name }}
+                                            {% else %}
+                                                F
+                                            {% endif %}
+                                    </td>
+                                {% endif %}
+                            {% endwith %}
+                        {% endfor %}
+                    </tr>
+                    {% endfor %}
+                    <tr>
+                        <td class="employee-name">Reinigung</td>
+                        {% for day in range_days %}
+                            {% if reinigungs_by_date|default_if_none:None %}
+                                {% if reinigungs_by_date|get_item:day %}
+                                    {% with reinigung=reinigungs_by_date|get_item:day %}
+                                        <td class="shift-none" {% if user.is_superuser %} onclick="window.location.href='{% url 'edit_reinigung' pk=reinigung.id %}'" {% endif %}>
+                                            {{ reinigung.auftrag }}
+                                        </td>
+                                    {% endwith %}
+                                {% else %}
+                                    <td class="shift-none" {% if user.is_superuser %} onclick="window.location.href='{% url 'create_reinigung' %}?date={{ date }}'" {% endif %}>--</td>
+                                {% endif %}
+                            {% else %}
+                                <td class="shift-none" {% if user.is_superuser %} onclick="window.location.href='{% url 'create_reinigung' %}?date={{ date }}'" {% endif %}>--</td>
+                            {% endif %}
+                        {% endfor %}
+                    </tr>
+                    <tr>
+                        <td class="employee-name">Helfer</td>
+                        {% for day in range_days %}
+                            {% if helpers_by_date|default_if_none:None %}
+                                {% if helpers_by_date|get_item:day %}
+                                    {% with helper=helpers_by_date|get_item:day %}
+                                        <td class="shift-none" {% if user.is_superuser %} onclick="window.location.href='{% url 'edit_helper' pk=helper.id %}'" {% endif %}>
+                                            {{ helper.ben }}/{{ helper.best }}
+                                        </td>
+                                    {% endwith %}
+                                {% else %}
+                                    <td class="shift-none" {% if user.is_superuser %} onclick="window.location.href='{% url 'create_helper' %}?date={{ date }}'" {% endif %}>--</td>
+                                {% endif %}
+                            {% else %}
+                                <td class="shift-none" {% if user.is_superuser %} onclick="window.location.href='{% url 'create_helper' %}?date={{ date }}'" {% endif %}>--</td>
+                            {% endif %}
+                        {% endfor %}
+                    </tr>
+
+                </tbody>
+                <tbody>
+                    <tr class="table-dark">
+                        <th class="employee-name">Mitarbeiter</th>
+                        {% for day, date in days_with_dates %}
+                        <th class="day-name">{{ day }} {{ date }}</th>
+                        {% endfor %}
+                    </tr>
+                    {% for employee, shifts in shifts_by_employee.items %}
+                    <tr>
+                        <td class="employee-name">{{ employee.name }}</td>
+                        {% for day, date in days_with_dates %}
+                            {% with shift=shifts|get_item:forloop.counter0 %}
+                                {% if shift == None %}
+                                    <td class="shift-none" {% if user.is_superuser %} onclick="window.location.href='{% url 'create_multiple_shifts' %}?date={{ date }}'"{% endif %}>
+                                        F
+                                    </td>
+                                {% else %}
+                                    <td class="
+                                        {% if shift.start and shift.end %}
+                                            shift-none
+                                        {% elif shift.shifttype == 'U' %}
+                                            shift-vacation
+                                        {% elif shift.shifttype == 'K' %}
+                                            shift-sick
+                                        {% else %}
+                                            shift-other
+                                        {% endif %}
+                                    "
+                                        {% if user.is_superuser %}
+                                            onclick="window.location.href='{% url 'edit_shift' pk=shift.id %}'"
+                                        {% endif %}
+                                            {% if shift.info  %}
+                                                data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" title="Info: {{ shift.info }}"
+                                            {% endif %}
+                                    >
+                                            {% if shift.start and shift.end %}
+                                                {{ shift.start|time:"H:i" }} - {{ shift.end|time:"H:i" }}
+                                                {% if shift.shiftchef  %}
+                                                    {{ shift.shiftchef }}
+                                                {% endif %}
+                                            {% else %}
+                                                {{ shift.get_shifttype_display }}
+                                            {% endif %}
+                                    </td>
+                                {% endif %}
+                            {% endwith %}
+                        {% endfor %}
+                    </tr>
+                    {% endfor %}
+                </tbody>
+            </table>
+        </div>
+        {% endif %}
+    </div>
+    {% bootstrap_javascript %}
+    <script>
+        // Initialize all tooltips on the page
+        var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
+        var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
+            return new bootstrap.Tooltip(tooltipTriggerEl)
+        })
+    </script>
+</body>
+</html>

+ 14 - 28
templates/main/public.html

@@ -7,7 +7,7 @@
 <head>
     <meta charset="UTF-8">
     <meta http-equiv="refresh" content="120; URL=/" >
-    <title>Schichten der aktuellen Woche</title>
+    <title>Dienstplan</title>
     <link rel="icon" href="{% static 'favicon.png' %}">
     {% bootstrap_css %}
     <style>
@@ -84,18 +84,11 @@
     <div class="container-fluid">
         <table class="table">
             <tr>
-                <td><a href="?start_date={{ previous_week }}" class="btn btn-primary text-start">Eine Woche zurück</a></td>
-                <td><a href="/" class="btn btn-primary">Aktuelle Woche</a></td>
+                <td><a href="?start_date={{ previous_week }}" class="btn btn-primary text-start"><<</a></td>
+                <td><a href="/public" class="btn btn-primary">Aktuelle Woche</a></td>
                 <td><h4 class="custom-heading text-center">Dienstplan für KW {{ calendar_week }}</h4></td>
-                <td class="text-end">{% if user.is_authenticated %}
-                        <form method="post" action="{% url 'logout' %}" style="display: inline;">
-                            {% csrf_token %}
-                            <button type="submit" class="btn btn-secondary">Logout</button>
-                        </form>
-                    {% else %}
-                        <a href="/login/" class="btn btn-secondary">Login</a>
-                    {% endif %}</td>
-                <td class="text-end"><a href="?start_date={{ next_week }}" class="btn btn-primary">Eine Woche vorwärts</a></td>
+                <td ></td>
+                <td class="text-end"><a href="?start_date={{ next_week }}" class="btn btn-primary">>></a></td>
             </tr>
         </table>
         <div class="table-responsive">
@@ -115,13 +108,9 @@
                         {% for day, date in days_with_dates %}
                             {% with event=events|get_item:forloop.counter0 %}
                                 {% if event == None %}
-                                    {% if user.is_authenticated %}
-                                        <td class="shift-none" onclick="window.location.href='{% url 'create_event' %}?date={{ date }}'">--</td>
-                                    {% else %}
-                                        <td class="shift-none">--</td>
-                                    {% endif %}
+                                    <td class="shift-none">--</td>
                                 {% else %}
-                                    <td class="shift-none" {% if user.is_authenticated %} onclick="window.location.href='{% url 'edit_event' pk=event.id %}'" {% endif %} data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" title="Name: {{ event.name }}<br> Location: {{ event.location }}<br> Belegung: {{ event.belegung }}<br> PAX: {{ event.pax }}<br> CVD: {{ event.cvd }}<br> CVT: {{ event.cvt }}<br> Info: {{ event.info }}">
+                                    <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> Belegung: {{ event.belegung }}<br> PAX: {{ event.pax }}<br> CVD: {{ event.cvd }}<br> CVT: {{ event.cvt }}<br> Info: {{ event.info }}">
                                             {% if event.name %}
                                                 {{ event.name }}
                                             {% else %}
@@ -139,15 +128,15 @@
                             {% if reinigungs_by_date|default_if_none:None %}
                                 {% if reinigungs_by_date|get_item:day %}
                                     {% with reinigung=reinigungs_by_date|get_item:day %}
-                                        <td class="shift-none" {% if user.is_authenticated %} onclick="window.location.href='{% url 'edit_reinigung' pk=reinigung.id %}'" {% endif %}>
+                                        <td class="shift-none" >
                                             {{ reinigung.auftrag }}
                                         </td>
                                     {% endwith %}
                                 {% else %}
-                                    <td class="shift-none" {% if user.is_authenticated %} onclick="window.location.href='{% url 'create_reinigung' %}?date={{ date }}'" {% endif %}>--</td>
+                                    <td class="shift-none" >--</td>
                                 {% endif %}
                             {% else %}
-                                <td class="shift-none" {% if user.is_authenticated %} onclick="window.location.href='{% url 'create_reinigung' %}?date={{ date }}'" {% endif %}>--</td>
+                                <td class="shift-none" >--</td>
                             {% endif %}
                         {% endfor %}
                     </tr>
@@ -157,15 +146,15 @@
                             {% if helpers_by_date|default_if_none:None %}
                                 {% if helpers_by_date|get_item:day %}
                                     {% with helper=helpers_by_date|get_item:day %}
-                                        <td class="shift-none" {% if user.is_authenticated %} onclick="window.location.href='{% url 'edit_helper' pk=helper.id %}'" {% endif %}>
+                                        <td class="shift-none" >
                                             {{ helper.ben }}/{{ helper.best }}
                                         </td>
                                     {% endwith %}
                                 {% else %}
-                                    <td class="shift-none" {% if user.is_authenticated %} onclick="window.location.href='{% url 'create_helper' %}?date={{ date }}'" {% endif %}>--</td>
+                                    <td class="shift-none" >--</td>
                                 {% endif %}
                             {% else %}
-                                <td class="shift-none" {% if user.is_authenticated %} onclick="window.location.href='{% url 'create_helper' %}?date={{ date }}'" {% endif %}>--</td>
+                                <td class="shift-none" >--</td>
                             {% endif %}
                         {% endfor %}
                     </tr>
@@ -184,7 +173,7 @@
                         {% for day, date in days_with_dates %}
                             {% with shift=shifts|get_item:forloop.counter0 %}
                                 {% if shift == None %}
-                                    <td class="shift-none" {% if user.is_authenticated %} onclick="window.location.href='{% url 'create_multiple_shifts' %}?date={{ date }}'"{% endif %}>
+                                    <td class="shift-none" >
                                         F
                                     </td>
                                 {% else %}
@@ -199,9 +188,6 @@
                                             shift-other
                                         {% endif %}
                                     "
-                                        {% if user.is_authenticated %}
-                                            onclick="window.location.href='{% url 'edit_shift' pk=shift.id %}'"
-                                        {% endif %}
                                             {% if shift.info  %}
                                                 data-bs-toggle="tooltip" data-bs-placement="top" data-bs-html="true" title="Info: {{ shift.info }}"
                                             {% endif %}