diff --git a/safesite/export.py b/safesite/export.py index ea6fe65e..9784f896 100644 --- a/safesite/export.py +++ b/safesite/export.py @@ -256,7 +256,7 @@ def exportdoc(a,id): import re ILLEGAL_CHARACTERS_RE = re.compile(r'[\000-\010]|[\013-\014]|[\016-\037]') -def exportxlsx(a,objs): +def exportxlsx(a,objs,pic=1): if a =='yh': wb = load_workbook(dirname + 'safesite/exportemp/yhdc.xlsx') sheet = wb.active @@ -265,7 +265,11 @@ def exportxlsx(a,objs): row_height = 70 #查询数据 yhobjs = objs.order_by('-troubleid') - if yhobjs.count()>100: + if yhobjs.count()>1000: + res = HttpResponse() + res.write('数量超过1000,请查询后导出!') + return res + if pic==1 and yhobjs.count()>100: res = HttpResponse() res.write('数量超过100,请查询后导出!') return res @@ -308,22 +312,23 @@ def exportxlsx(a,objs): sheet['r'+str(i+4)] = ILLEGAL_CHARACTERS_RE.sub(r'', v['zgms']) sheet['s'+str(i+4)] = v['shr__name'] sheet['t'+str(i+4)] = v['fcr__name'] - if v['yhtp']: - try: - img = Image(dirname + v['yhtp'][0]) - if img.format!='mpo': - img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 - sheet.add_image(img, 'u'+str(i+4)) - except: - pass - if v['zghtp']: - try: - img = Image(dirname + v['zghtp'][0]) - if img.format!='mpo': - img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 - sheet.add_image(img, 'w'+str(i+4)) - except: - pass + if pic==1: + if v['yhtp']: + try: + img = Image(dirname + v['yhtp'][0]) + if img.format!='mpo': + img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 + sheet.add_image(img, 'u'+str(i+4)) + except: + pass + if v['zghtp']: + try: + img = Image(dirname + v['zghtp'][0]) + if img.format!='mpo': + img.width, img.height = (90, 90) #这两个属性分别是对应添加图片的宽高 + sheet.add_image(img, 'w'+str(i+4)) + except: + pass nowtime = datetime.now().strftime('%Y%m%d%H%M%S') sheet['b1'] = nowtime filename = 'YHS' + nowtime diff --git a/safesite/templates/trouble.html b/safesite/templates/trouble.html index e3f7d43e..11f7d8a3 100644 --- a/safesite/templates/trouble.html +++ b/safesite/templates/trouble.html @@ -31,6 +31,9 @@ {% if request|has_permission:'b_trouble_exportxls' %} 导出Excel {% endif %} + {% if request|has_permission:'b_trouble_exportxls' %} + 导出无图Excel + {% endif %}