im试图生成一份雇员列表的pdf文件,一切都还好,直到我尝试创建一个将同一部门中所有雇员分组的行跨度,然后出现错误,从视图中发送了一个3维数组,部门列表中的员工信息
我试图从视图中获取组的大小并将其发送到l2.6中,而我试图从l1 | length中获取它
<table style="border: 1px solid black;">
<tr style="border: 1px solid black;">
<th style="border: 1px solid black;"> Service</th>
<th style="border: 1px solid black;"> Nom et prenom</th>
<th style="border: 1px solid black;width: 160px;"> Conge 1</th>
<th style="border: 1px solid black;width: 160px;"> Conge 2</th>
<th style="border: 1px solid black;width: 160px;"> Conge 3</th>
<th style="border: 1px solid black;width: 160px;"> Conge 4</th>
<th style="border: 1px solid black;width: 180px;"> Total</th>
</tr>
{% for l1 in liste %}
{% for l2 in l1 reversed %}
<tr>
{% if l2.6 != 0%}
<td rowspan="{{l1|length}}" style="border: 1px solid black" >
{{ l2.0 }}
</td>
{% endif %}
<td style="border: 1px solid black" >
{{ l2.0 }}
</td>
<td style="border: 1px solid black;">
{{ l2.1 }}
</td>
<td style="border: 1px solid black;">
{{ l2.2 }}
</td>
<td style="border: 1px solid black;">
{{ l2.3 }}
</td>
<td style="border: 1px solid black;">
{{ l2.4 }}
</td>
<td style="border: 1px solid black;">
{{ l2.5 }}
</td>
</tr>
{% endfor %}
{% endfor %}
</table>
我收到此错误 / conge_service /
处的TypeError无序类型:NoneType()> float()
这是我的观点:
class conge_service(View):
def get(self, request, *args, **kwargs):
template = get_template('gp/pdf/conge_service.html')
annee = datetime.now().year;
nature = request.GET.get('n')
if nature == '0':
v_nature = 'de maladies'
else:
v_nature = 'administratifs'
v = request.GET.get('v')
if(v == '1'):
v_annee = int(annee)-1
v_tremestre = 'le quatrième'
else:
v_annee=annee
# trimestre 1 annee 2019
if(v == '2'):
v_tremestre = 'le premier'
# trimestre 2 annee 2019
if(v == '3'):
v_tremestre = 'le deuxième'
# trimestre 3 annee 2019
if(v == '4'):
v_tremestre = 'le troisième'
# trimestre 4 annee 2019
if(v == '5'):
v_tremestre = 'le quatrième'
liste = []
ss = Service.objects.all().prefetch_related()
for s in ss:
aa = Affectation.objects.filter(Q(date_disposition__isnull=True) & Q(Q(specialite__service_id = s.id) | Q(option__service_id = s.id))).prefetch_related()
personnel_service = []
x = 0
for a in aa:
personnel_liste = []
cc = Cessation.objects.filter(Q(personnel_id=a.personnel_id) & Q(nature_cessation=nature))
if v == '1' or v == '5':
s1 = str(v_annee)+"-09-01"
d = datetime.strptime(s1, "%Y-%m-%d").date()
cc = cc.filter(date_cessation__gt=d)
elif v == '3':
s1 = str(v_annee) + "-03-01"
d1 = datetime.strptime(s1, "%Y-%m-%d").date()
s2 = str(v_annee) + "-06-01"
d2 = datetime.strptime(s2, "%Y-%m-%d").date()
cc = cc.filter(Q(date_cessation__gt=d1) and Q(date_cessation__lte=d2))
elif v == '4':
s1 = str(v_annee) + "-06-01"
d1 = datetime.strptime(s1, "%Y-%m-%d").date()
s2 = str(v_annee) + "-09-01"
d2 = datetime.strptime(s2, "%Y-%m-%d").date()
cc = cc.filter(Q(date_cessation__gt=d1) and Q(date_cessation__lte=d2))
elif v == '2':
s1 = str(v_annee) + "-03-01"
d = datetime.strptime(s1, "%Y-%m-%d").date()
cc = cc.filter(date_cessation__month__lte=d)
nom_prenom = str(a.personnel.nom)+" "+str(a.personnel.prenom)
personnel_liste.insert(0, nom_prenom)
i = 1
for c in cc:
j = 0
if i < 5:
j = j + int(c.duree)
personnel_liste.insert(i, j)
i = i + 1
if i < 4:
for k in range (i,5):
personnel_liste.insert(k, 0)
personnel_liste.insert(5, personnel_liste[1] + personnel_liste[2] +personnel_liste[3] +personnel_liste[4])
personnel_liste.insert(6, 0)
personnel_service.append(personnel_liste)
x = x + 1
personnel_liste = []
personnel_liste.insert(0,s.value )
i1=0
i2=0
i3=0
i4=0
i5=0
for p in personnel_service:
i1 = i1 + p[1]
i2 = i2 + p[2]
i3 = i3 + p[3]
i4 = i4 + p[4]
i5 = i5 + p[5]
personnel_liste.insert(1,i1 )
personnel_liste.insert(2,i2 )
personnel_liste.insert(3,i3 )
personnel_liste.insert(4,i4 )
personnel_liste.insert(5,i5 )
personnel_liste.insert(6,x )
personnel_service.append(personnel_liste)
liste.append(personnel_service)
context = {
'annee':v_annee,
'tremestre':v_tremestre,
'nature':v_nature,
'liste':liste
}
html = template.render(context)
pdf = render_to_pdf('gp/pdf/conge_service.html', context)
if pdf:
response = HttpResponse(pdf, content_type='application/pdf')
n = random.randint(100, 100000)
filename = "statistique_%s.pdf" %n
content = "inline; filename='%s'" %(filename)
download = request.GET.get("download")
if download:
content = "attachment; filename='%s'" %(filename)
response['Content-Disposition'] = content
return response
return HttpResponse("Not found")
这是错误的回溯 内部的/home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/django/core/handlers/exception.py
response = get_response(request)
…
▶本地变量 _get_response中的/home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/django/core/handlers/base.py
response = self.process_exception_by_middleware(e, request)
…
▶本地变量 _get_response中的/home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/django/core/handlers/base.py
response = wrapped_callback(request, *callback_args, **callback_kwargs)
…
▶本地变量 /home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/django/views/generic/base.py在视图中
return self.dispatch(request, *args, **kwargs)
…
▶本地变量 /home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/django/views/generic/base.py发送中
return handler(request, *args, **kwargs)
…
▶本地变量 /home/kossay/PycharmProjects/gp/gp/views.py in
pdf = render_to_pdf('gp/pdf/conge_service.html', context)
…
▶本地变量 /home/kossay/PycharmProjects/gp/gp/utils.py in render_to_pdf
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
…
▶本地变量 /home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/xhtml2pdf/document.py in pisaDocument
doc.build(context.story)
…
▶本地变量 /home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/reportlab/platypus/doctemplate.py在构建中
self.handle_flowable(flowables)
…
▶本地变量 /home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/reportlab/platypus/doctemplate.py在handle_flowable中
(self._fIdent(f,60,frame),_fSizeString(f),self.page, self.frame.id,
…
▶本地变量 _fIdent中的/home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/reportlab/platypus/doctemplate.py
return f.identity(maxLen)
…
▶本地变量 /home/kossay/PycharmProjects/gp/venv/lib/python3.5/site-packages/reportlab/platypus/tables.py以身份标识
tallest = '(tallest row %d)' % int(max(rh))
…
▶本地变量