J'ai ajouté un utilisateur pour créer une fonction de création de table de décalage, mais j'ai soudainement décidé d'implémenter le tri par ordre d'affichage.
Cependant, je suis resté coincé ici. J'ai lié l'utilisateur et le profil à l'utilisateur, mais j'ai essayé d'obtenir le prénom et le nom dans l'utilisateur, mais je ne pouvais pas les obtenir après tout ...
Enfin, il a été soutenu en ajoutant un jugement sur HTML si l'ID du profil et l'ID de l'utilisateur sont identiques. Je suis nouveau, mais je pense que ce n'est pas beau ... Je l'ai vérifié pendant environ 3 heures, essayé et vérifié à nouveau.
J'ai fait de mon mieux (⌒∇⌒)
python:schedule.views.py
from django.shortcuts import render, redirect, HttpResponseRedirect
from shisetsu.models import *
from accounts.models import *
from .models import *
import calendar
import datetime
from datetime import timedelta
from datetime import datetime as dt
from django.db.models import Sum
from django.contrib.auth.models import User
from django.views.generic import FormView, UpdateView
from django.urls import reverse_lazy
from .forms import *
from dateutil.relativedelta import relativedelta
from django.contrib.auth.models import User
# Create your views here.
def homeschedule(request):
from datetime import datetime
now = datetime.now()
return HttpResponseRedirect('/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()
profile_list = Profile.objects.select_related().values().order_by('hyoujijyun')
print(profile_list)
print(user_list)
year, month = int(year_num), int(month_num)
shisetsu_object = Shisetsu.objects.all()
shift_object = Shift.objects.all()
object_list = Schedule.objects.filter(year = year, month = month).order_by('user', 'date')
month_total = Schedule.objects.select_related('User').filter(year = year, month = month).values("user").order_by("user").annotate(month_total_worktime = Sum("day_total_worktime"))
#Obtenez le nombre de jours dans la plage de travail
enddate = datetime.date(year,month,20)
startdate = enddate + relativedelta(months=-1)
kaisu = enddate - startdate
kaisu = int(kaisu.days)
kikan = str(startdate) +"~"+ str(enddate)
#Faites une liste de dates et de jours
hiduke = str(startdate)
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 = {
'year': year,
'month': month,
'kikan': kikan,
'object_list': object_list,
'user_list': user_list,
'shift_object': shift_object,
'calender_object': calender_object,
'youbi_object': youbi_object,
'kaisu': kaisu,
'shisetsu_object': shisetsu_object,
'month_total' : month_total,
'profile_list' : profile_list,
}
return render(request,'schedule/month.html', context)
def scheduleUpdatefunc(request,pk):
Schedule_list = Schedule.objects.get(pk = int(pk))
User_list = User.objects.get(username = Schedule_list.user)
shift_object = Shift.objects.all()
if request.method == 'POST':
form = ScheduleUpdateForm(data=request.POST)
year = Schedule_list.year
month = Schedule_list.month
if form.is_valid():
Schedule_list.shift_name_1 = form.cleaned_data['shift_name_1']
Schedule_list.shisetsu_name_1 = form.cleaned_data['shisetsu_name_1']
Schedule_list.shift_name_2 = form.cleaned_data['shift_name_2']
Schedule_list.shisetsu_name_2 = form.cleaned_data['shisetsu_name_2']
Schedule_list.shift_name_3 = form.cleaned_data['shift_name_3']
Schedule_list.shisetsu_name_3 = form.cleaned_data['shisetsu_name_3']
Schedule_list.shift_name_4 = form.cleaned_data['shift_name_4']
Schedule_list.shisetsu_name_4 = form.cleaned_data['shisetsu_name_4']
Schedule_list.day_total_worktime = form.cleaned_data['day_total_worktime']
Schedule_list.save()
return HttpResponseRedirect('/schedule/monthschedule/%s/%s/' % (year,month,))
else:
item = {
"shift_name_1":Schedule_list.shift_name_1,
"shisetsu_name_1": Schedule_list.shisetsu_name_1,
"shift_name_2": Schedule_list.shift_name_2,
"shisetsu_name_2": Schedule_list.shisetsu_name_2,
"shift_name_3": Schedule_list.shift_name_3,
"shisetsu_name_3": Schedule_list.shisetsu_name_3,
"shift_name_4": Schedule_list.shift_name_4,
"shisetsu_name_4": Schedule_list.shisetsu_name_4,
}
form = ScheduleUpdateForm(initial=item)
context = {
'form' : form,
'Schedule_list': Schedule_list,
'User_list': User_list,
'shift_object': shift_object,
}
return render(request,'schedule/update.html', context )
'''
#### **`schedule/month.py`**
```html
{% extends 'schedule/base.html' %}
{% block header %}
<ul class="page">
<div align="left">
<li class="previous">
{% ifnotequal month 1 %}
<a href="{% url'schedule:monthschedule' year month | add:'-1'%} "class =" btn-info btn active "> le mois précédent </a>
{% else %}
<a href="{% url'schedule:monthschedule' year | add:'-1' 12%} "class =" btn-info btn active "> le mois précédent </a>
{% endifnotequal %}
</li>
</div>
<div align="right">
<li class="next">
{% ifnotequal month 12 %}
<a href="{% url'schedule:monthschedule' year month | add: '1'%} "class =" btn-info btn active "> Le mois prochain </a>
{% else %}
<a href="{% url'schedule:monthschedule' year | add: '1' 1%} "class =" btn-info btn active "> Le mois prochain </a>
{% endifnotequal %}
</li>
</div>
</ul>
<p>
{% for shisetsu in shisetsu_object %}
<span style="background-color:{{ shisetsu.color }}">{{ shisetsu.name }}</span>
{% endfor %}
</p>
{{ kikan }}
{% for shift in shift_object %}
{% if shift.name! = "Holiday" et shift.name! = "Oui"%}
{{ shift.name }} : {{ shift.start_time | date:"G"}}~{{ shift.end_time | date:"G"}}
{% endif %}
{% endfor %}
{% 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"> <! - Jour->
{% for item in youbi_object %}
<th class="day_{{ item.date }}">{{ item }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for profile in profile_list %}
{% for staff in user_list %}
{% if profile.user_id == staff.id %}
<tr align="center">
<th rowspan = "1" class = "staff_name" staff_id = "{{staff.staff_id}}" width = "200"> {{staff.last_name}} {{staff.first_name}} </ th> <! - L'élément -staff_id est 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" 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 %}
{% endif %}
{% endfor %}
</td>
<tr align="center">
{% for month in month_total %}
{% if month.user == staff.id%} <! - Si le nom d'utilisateur est le même->
<td><b>{{ month.month_total_worktime }}</b></td>
{% endif %}
{% endfor %}
{% 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" id="s{{ staff.id }}d{{ item.date }}">
<a href="{% url 'schedule:update' item.pk %}">{{ item.day_total_worktime }} </a>
</td>
{% endif %}
{% endfor %}
</tr>
{% endif %}
{% endfor %}
{% endfor %}
</tbody>
</table>
{% endblock content %}
J'entrerai dans la fonction de création de décalage à partir d'ici. Il y a beaucoup de gens qui travaillent pour un double travail, donc il y a des gens qui arrivent avec espoir quand ils arrivent, et des gens qui viennent régulièrement mais se reposent ce jour-là.
Donc, tout d'abord, je vais essayer de pouvoir saisir la demande de quart.
Recommended Posts