[PYTHON] Fond de symbole de décalage Django avec différentes couleurs en fonction de l'installation

La table des équipes contient des données telles que A, B, C et les jours fériés. Même si je dis A, puisqu'il y a trois installations, je le crée actuellement dans Excel afin de pouvoir comprendre sur quelle base je travaille. Cela correspond en changeant la couleur de la cellule.

image.png

Dans Excel, il est créé comme ceci. Le café a géré deux bases et a créé une table de travail séparée. (Je ne l'ai pas encore vu, donc il peut y avoir des changements ...)

Lors de son implémentation avec Django, nous avons un champ de couleur dans la table des équipes, nous allons donc le gérer et l'afficher. Lors de la mise en œuvre, lorsque j'ai remarqué que je choisissais payé ou en vacances, je peux choisir l'établissement, donc il sera coloré même pendant les vacances. Il semble que le contrôle d'entrée soit facile à implémenter si vous le faites dans forms.py, mais je ne l'ai jamais fait, donc j'aimerais l'implémenter à l'avenir.

J'ai également décidé de passer la table Shisetsu au html pour la coloration.

schedule/views.py



from django.shortcuts import render
from shisetsu.models import *
from accounts.models import *
from .models import *
from django.shortcuts import redirect
import calendar
import datetime
from datetime import timedelta
from datetime import datetime as dt

# Create your views here.

def homeschedule(request):
    from datetime import datetime
    now = datetime.now()
    return redirect('schedule/monthschedule/%s/%s/' % (now.year,now.month,))  #Rediriger automatiquement vers l'écran d'équipe de ce mois

def monthschedulefunc(request,year_num,month_num):
    user_list = User.objects.all()
    year, month = int(year_num), int(month_num)
    shisetsu_object = Shisetsu.objects.all()
    print(shisetsu_object)
    object_list = Schedule.objects.filter(year = year, month = month).order_by('user', 'date')
    #Obtenez le nombre de jours dans la plage de travail
    startdate = datetime.date(year,month-1,21)
    enddate = datetime.date(year,month,20)
    kaisu = enddate - startdate
    kaisu = int(kaisu.days) + 1
    
    #Faites une liste de dates et de jours
    hiduke = str(year) + "-" + str(month-1) + "-" + str(20)
    date_format = "%Y-%m-%d"
    hiduke = dt.strptime(hiduke, date_format)
    weekdays = ["Mois","Feu","eau","bois","Argent","sol","journée"]
    calender_object = []
    youbi_object = []
    for i in range(kaisu):
        hiduke = hiduke + timedelta(days=1)    
        calender_object.append(hiduke)
        youbi = weekdays[hiduke.weekday()] 
        youbi_object.append(youbi)
    
    kaisu = str(kaisu)

    context = {
        'object_list': Schedule.objects.all(),
        'staff_list' : User.objects.all(),
        'shisetsu_object': shisetsu_object.all(),
        'kaisu' : kaisu
    }
    return render(request,'schedule/month.html', {
    'object_list': object_list,
    'user_list': user_list,
    'calender_object': calender_object,
    'youbi_object':youbi_object,
    'kaisu':kaisu,
    'shisetsu_object':shisetsu_object
    }, )

schedule/month.html


{% extends 'schedule/base.html' %}
{% block header %}
{% endblock header %}

{% block content %}
<table class="table table-striped table-bordered">
<thead>
    <tr align="center" class="info">    <!--Date-->
        <th rowspan="2"></th>
        {% for item in calender_object %}
                <th class="day_{{ item.date }}">{{ item.date | date:"d" }}</th>
        {% endfor %}
    <tr align="center" class="info">   <!--journée-->
        {% for item in youbi_object %}
            <th class="day_{{ item.date }}">{{ item }}</th>
        {% endfor %}
    </tr>
</thead>
<tbody>
    {% for staff in user_list %}
        <tr align="center">
        <th class="staff_name" staff_id="{{ staff.staff_id }}" width="200" >{{ staff.last_name }} {{ staff.first_name }}</th>  <!--staff_Élément id utilisé dans js-->
        {% for item in object_list %} 
            {% if item.user|stringformat:"s" == staff.username|stringformat:"s" %}<!--Si le nom d'utilisateur est le même-->
                <td class="day_{{ item.date }}" id="s{{ staff.id }}d{{ item.date }}"> 
                    {% if item.shift_name_1 != None %}
                        {% if item.shift_name_1|stringformat:"s" == "Oui" or item.shift_name_1|stringformat:"s" == "Fermé" %}
                            {{ item.shift_name_1 }}
                        {% else %}
                            {% for shisetsu in shisetsu_object %}
                                {% if item.shisetsu_name_1|stringformat:"s" == shisetsu.name|stringformat:"s" %}                          
                                        <span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_1 }}</span>
                                {% endif %}
                            {% endfor %} 
                        {% endif %}    
                    {% endif %}
                    {% if item.shift_name_2 != None %}
                        {% if item.shift_name_2|stringformat:"s" == "Oui" or item.shift_name_2|stringformat:"s" == "Fermé" %}
                            {{ item.shift_name_2 }}
                        {% else %}
                            {% for shisetsu in shisetsu_object %}
                                {% if item.shisetsu_name_2|stringformat:"s" == shisetsu.name|stringformat:"s" %}                          
                                        <span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_2 }}</span>
                                {% endif %}
                            {% endfor %} 
                        {% endif %}    
                    {% endif %}
                    {% if item.shift_name_3 != None %}
                        {% if item.shift_name_3|stringformat:"s" == "Oui" or item.shift_name_3|stringformat:"s" == "Fermé" %}
                            {{ item.shift_name_3 }}
                        {% else %}
                            {% for shisetsu in shisetsu_object %}
                                {% if item.shisetsu_name_3|stringformat:"s" == shisetsu.name|stringformat:"s" %}                          
                                        <span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_3 }}</span>
                                {% endif %}
                            {% endfor %} 
                        {% endif %}    
                    {% endif %}
                    {% if item.shift_name_4 != None %}
                        {% if item.shift_name_4|stringformat:"s" == "Oui" or item.shift_name_4|stringformat:"s" == "Fermé" %}
                            {{ item.shift_name_4 }}
                        {% else %}
                            {% for shisetsu in shisetsu_object %}
                                {% if item.shisetsu_name_4|stringformat:"s" == shisetsu.name|stringformat:"s" %}                          
                                        <span style="background-color:{{ shisetsu.color }}">{{ item.shift_name_4 }}</span>
                                {% endif %}
                            {% endfor %} 
                        {% endif %}    
                    {% endif %}
                </td>
            {% endif %}            
        {% endfor %}
        </tr>
    {% endfor %}
</tbody>

</table>
{% endblock content %}

Je pense qu'un processus itératif peut être fait, mais comme 1 a bien fonctionné, je l'utilise en copier-coller. Après cela, il peut être remis à neuf au fur et à mesure du calcul des heures de travail mensuelles totales.

Et voici le résultat de l'affichage.

image.png

Non, vous avez terminé! La couleur de fond est un peu petite, mais c'est bon (⌒∇⌒)

Je suis arrivé dans environ 3 heures, donc je pense que j'ai pu le faire assez rapidement.

Ensuite, j'aimerais travailler sur le calcul du temps total du mois. Tout d'abord, je voudrais confirmer que les heures de travail de la journée peuvent être modifiées ou ajoutées.

Recommended Posts

Fond de symbole de décalage Django avec différentes couleurs en fonction de l'installation
Django + Apache avec mod_wsgi sur Windows Server 2016
Remarques sur l'activation de PostgreSQL avec Django