Skip to content

Commit

Permalink
fix source export charter
Browse files Browse the repository at this point in the history
  • Loading branch information
guohongze committed May 10, 2019
1 parent 7e7b2c6 commit b088e3d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 44 deletions.
54 changes: 10 additions & 44 deletions branches/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from accounts.permission import permission_verify
import csv
import datetime
from cmdb.api import str2gb
from cmdb.api import str2gb, str2gbk


@login_required()
Expand Down Expand Up @@ -74,61 +74,27 @@ def resource_edit(request, resource_id):
}
return render(request, 'branches/resource_base.html', results)


@login_required
@permission_verify()
def resource_export(request):
export = request.GET.get("export", '')
resource_id_list = request.GET.getlist("id", '')
if export == "part":
if resource_id_list:
resource_find = []
for resource_id in resource_id_list:
resource_item = Resource.objects.get(id=resource_id)
if resource_item:
resource_find.append(resource_item)

if export == "all":
resource_find = Resource.objects.all()

response = HttpResponse(content_type='text/csv')
now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
file_name = 'adminset_resource_' + now + '.csv'
response['Content-Disposition'] = "attachment; filename="+file_name
writer = csv.writer(response)
writer.writerow([str2gb(u'资源名称'), str2gb(u'资源规格'), str2gb(u'预算金额'), str2gb(u'合同金额'),
str2gb(u'合同编号'), str2gb(u'合同开始'), str2gb(u'合同结束'), str2gb(u'供应商名'),
str2gb(u'服务电话'), str2gb(u'所属机构'), str2gb(u'备注说明')])
for p in resource_find:
writer.writerow([str2gb(p.name), str2gb(p.spec), str2gb(p.budget), str2gb(p.paid), str2gb(p.contract),
str2gb(p.contract_start),str2gb(p.contract_end), str2gb(p.suppier), str2gb(p.service_phone),
str2gb(p.branch), str2gb(p.description)])
return response


@login_required
@permission_verify()
def resource_export(request):
resource = Resource.objects.all()
resource_find = Resource.objects.all()
response = HttpResponse(content_type='text/csv')
now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
file_name = 'adminset_resource_' + now + '.csv'
response['Content-Disposition'] = "attachment; filename=" + file_name
writer = csv.writer(response)
writer.writerow([str2gb('行政区域'), str2gb('分支机构'), str2gb('资源编码'), str2gb('资源名称'), str2gb('资源规格'),
str2gb('预算资金'), str2gb('合同资金'), str2gb('合同编号'), str2gb('合同开始'), str2gb('合同结束'),
str2gb('供应商名'), str2gb('服务电话'), str2gb('客户经理'), str2gb('联系电话'),
str2gb('备注说明')])
for r in resource:
str2gb('供应商名'), str2gb('服务电话'), str2gb('客户经理'), str2gb('联系电话'),])
for r in resource_find:
br_name = ""
if r.branch:
br = Branch.objects.get(name=r.branch)
else:
br = None

writer.writerow([str2gb(br.region.name if br else br), str2gb(r.branch.name if r.branch else None), r.sn,
str2gb(r.name), str2gb(r.spec),str2gb(r.budget), str2gb(r.paid), str2gb(r.contract),
if br.region:
br_name = br.region.name
writer.writerow([str2gb(br_name), str2gbk(r.branch.name if r.branch else None), str2gb(r.sn),
str2gb(r.name), str2gb(r.spec), str2gb(r.budget), str2gb(r.paid), str2gb(r.contract),
str2gb(r.contract_start), str2gb(r.contract_end),
str2gb(r.supplier), str2gb(r.service_phone), str2gb(r.owner if r.owner else None),
str2gb(r.owner.phone if r.owner else None),
str2gb(r.description)])
str2gb(r.owner.phone if r.owner else None),])
return response
8 changes: 8 additions & 0 deletions cmdb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ def str2gb(args):
"""
return str(args).encode('gb2312')

def str2gbk(args):
"""
:参数 args:
:返回: GB2312编码
"""
return str(args).encode('gbk')



def str2gb2utf8(args):
"""
Expand Down

0 comments on commit b088e3d

Please sign in to comment.