本文整理汇总了Python中pyramid.response.FileResponse.headers['Content-Disposition']方法的典型用法代码示例。如果您正苦于以下问题:Python FileResponse.headers['Content-Disposition']方法的具体用法?Python FileResponse.headers['Content-Disposition']怎么用?Python FileResponse.headers['Content-Disposition']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.response.FileResponse
的用法示例。
在下文中一共展示了FileResponse.headers['Content-Disposition']方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: content
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def content(self):
filename = abspath(self.format)
response = FileResponse(filename)
response.headers['Content-type'] = 'application/octet-stream'
response.headers['Content-Disposition'] = 'attachment; filename="{0}";'.format(
basename(filename))
return response
示例2: get_artifact
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def get_artifact(self):
artifact = self.request.context
response = FileResponse(artifact.location,
request=self.request)
cdh = 'attachment; filename="{0}"'.format(artifact.name)
response.headers['Content-Disposition'] = cdh
return response
示例3: download_log
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def download_log(request):
sys_mgr = sysinfo.sys_mgr() # get sys manager
sys_mgr.rm_sys_log() # rm the exist tar log file
log_tar_file = sys_mgr.tar_sys_log()
response = FileResponse(log_tar_file, request=request, content_type='application/force-download')
response.headers['Content-Disposition'] = 'attachment; filename=%s' % (os.path.basename(log_tar_file))
return response
示例4: download
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def download(context, request):
path = open_file(context.filesystem_path).name
response = FileResponse(path=path, request=request,
content_type=context.mimetype)
response.headers['Content-Disposition'] = ('attachment; filename="%s"' %
context.filename)
return response
示例5: download
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def download(context, request):
path = open_file(context.filesystem_path).name
mimetype = context.mimetype or 'application/octet-stream'
response = FileResponse(path=path, request=request,
content_type=mimetype.encode('utf8'))
response.headers['Content-Disposition'] = ('inline; filename="%s"' %
context.filename.encode('utf8'))
return response
示例6: download_csv
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def download_csv(request):
global result_paths_dict
csv_ref=request.matchdict['csv_ref']
path = result_paths_dict[csv_ref]['csv']
response = FileResponse(
path,
request=request,
content_type='text/csv'
)
response.headers['Content-Disposition'] = ("attachment; filename="+os.path.basename(path))
return response
示例7: index
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def index(request):
if not request.GET.get('_method', None) == '_exec':
# show form page
queries = get_queries()
return render_to_response('msaf:templates/tools/report/index.mako',
{ 'queries': queries, 'markers': get_marker_list() },
request = request)
# parse form
#queryset = request.GET.get('queryset', '').strip()
#batchcode = request.GET.get('batchcode', '')
#marker_ids = [ int(x) for x in request.GET.getall('markers') ]
#allele_absolute_threshold = int(request.GET.get('allele_absolute_threshold', 100))
#allele_relative_threshold = float(request.GET.get('allele_relative_threshold', 0.33))
#sample_quality_threshold = float(request.GET.get('sample_quality_threshold', 0.50))
#marker_quality_threshold = float(request.GET.get('marker_quality_threshold', 0.10))
#location_level = int(request.GET.get('location_level', 4))
#spatial_differentiation = int(request.GET.get('spatial_differentiation', 4))
#temporal_differentiation = int(request.GET.get('temporal_differentiation', 0))
baseparams = parse_base_params( request.GET )
location_level = int(request.GET.get('location_level', 4))
spatial_differentiation = int(request.GET.get('spatial_differentiation', -1))
temporal_differentiation = int(request.GET.get('temporal_differentiation', 0))
detection_differentiation = int(request.GET.get('detection_differentiation', 0))
#report = generate_report( batchcode, queryset, location_level, threshold,
# template_file = request.get_resource('custom.report', '') )
if False:
report = generate_report_2( batchcode, queryset, marker_ids,
allele_absolute_threshold, allele_relative_threshold,
sample_quality_threshold, marker_quality_threshold,
location_level, spatial_differentiation, temporal_differentiation,
template_file = request.get_resource('custom.report', '') )
report = generate_report_3( baseparams,
location_level = location_level,
spatial_differentiation = spatial_differentiation,
temporal_differentiation = temporal_differentiation,
detection_differentiation = detection_differentiation,
template_file = request.get_resource('custom.report', '') )
response = FileResponse(report.fullpath)
response.headers['Content-Disposition'] = ("attachment; filename=report.pdf")
return response
示例8: mapprint
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def mapprint(request):
payload = request.json_body
output_file_name = MapPrint(payload).print_pdf()
response = FileResponse(
output_file_name,
request=request
)
response.headers['Content-Disposition'] = ('attachement; filename="{}"'
.format(output_file_name + '.pdf'))
response.headers['Content-Type'] = 'application/pdf'
if os.path.exists(output_file_name):
os.remove(output_file_name)
return response
示例9: download_conf
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def download_conf(request):
cfg_mgr = cfgmgr.cfg_mgr() # get cfg manager
# the tmp file name
t = datetime.today().strftime("%Y%m%d_%H%M%S")
request.storlever_tmp_file = "/tmp/storlever_conf_%s.tar.gz" % t
cfg_mgr.backup_to_file(request.storlever_tmp_file)
response = FileResponse(request.storlever_tmp_file,
request=request,
content_type='application/force-download')
response.headers['Content-Disposition'] = \
'attachment; filename=%s' % \
(os.path.basename(request.storlever_tmp_file))
request.add_finished_callback(remove_tmp_conf_file) # remove the temp file
return response
示例10: serve
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def serve(self, key, content_type=None, file_name=None, content=True):
storage=getUtility(IContentStorage, name='content')
body=storage.get(key)
f = tempfile.NamedTemporaryFile()
f.write(body)
f.seek(0,0)
mimeType=content_type
if mimeType == None and content:
mimeType == "application/octet-stream"
elif mimeType == None and not content:
if content.upper().find("</BODY"):
mimeType="text/html"
file_name+='.html'
else:
mimeType='text/plain'
file_name+=".txt"
response=FileResponse(f.name, request=self.request, content_type=mimeType)
# FIXME check file if it has been closed
if content:
response.headers['Content-Disposition'] = ("attachment; filename={}".format(file_name))
response.headers['Content-Description'] = 'File Transfer'
return response
示例11: download
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def download(request):
response = FileResponse('data.csv')
response.headers['Content-Disposition'] = ("attachment; filename=Data.csv")
return response
示例12: files_list_view
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def files_list_view(self):
if not 'password' in self.request.POST and self.check():
print self.request.POST
return HTTPFound(location='/login')
url = USB_LOCATION + get_url(self.request.matchdict['list'])
url_parsed = '/'
for i in range(len(url.split('/')) - 3):
url_parsed += url.split('/')[i + 1] + '/'
action = url.split('/')[-2]
filename = str(url_parsed.split('/')[-2])
if 'password' in self.request.POST:
if self.request.POST['password'] != '':
password = self.request.POST['password']
# print password
content = encrypt(self.request.POST['notecontent'], password)
write('/'.join(url.split('/')[:-2]), content)
return HTTPFound(location='/files' + url[:-1])
# return Response()
elif 'file' in self.request.POST:
filename = self.request.POST['file'].filename
print filename
input_file = self.request.POST['file'].file
upload(input_file, url, filename)
print '/files' + url
return HTTPFound(location='/files' + url)
elif 'dir_name' in self.request.POST:
dirname = self.request.POST['dir_name']
make_dir(dirname, url)
return HTTPFound(location='/files' + url)
elif 'note_name' in self.request.POST:
write(url + self.request.POST['note_name'], '')
return HTTPFound(location='/files' + url)
elif 'notecontent' in self.request.POST:
content = encrypt(self.request.POST['notecontent'], decrypt(self.request.session['enpass'], self.request.cookies['r']))
write('/'.join(url.split('/')[:-2]), content)
return HTTPFound(location='/files' + url)
elif action == 'edit':
content = decrypt(read(url_parsed[:-1]), decrypt(self.request.session['enpass'], self.request.cookies['r']))
re = { 'page_title' : 'Notes', 'edit' : True, 'contents' : content, 'url' : url }
re.update(self.get_header())
return re
elif action == 'rename':
# file_old = str(url_parsed.split('/')[-3])
file_old = '/'.join(url_parsed.split('/')[:-2])
if not is_file('/'.join(url_parsed.split('/')[:-2])) and not is_dir('/'.join(url_parsed.split('/')[:-2])):
print 'not filename'
return HTTPFound(location='/files')
rename(file_old, filename)
return HTTPFound('/files' + '/'.join(url.split('/')[:-4]))
elif is_file(url_parsed[:-1]):
if action == 'download':
re = FileResponse(url_parsed[:-1])
re.headers['Content-Disposition'] = 'attachment; filename="' + filename + '"'
re.headers['Content-Type'] = 'application/force-download'
# re.headers['filename'] = filename
re.headers['Accept-Ranges'] = 'bytes'
return re
elif action == 'delete':
delete(url_parsed[:-1])
return HTTPFound(self.request.url[:-7-len(filename.replace(' ', '%20'))])
elif is_dir(url[:-7]) and action == 'delete':
delete(url[:-7])
return HTTPFound(self.request.url[:-7-len(filename)])
elif not is_dir(url) or len(url.split('/')) < 5:
return HTTPFound(location='/files')
temp = [str(part) for part in list_dir(url)]
temp.sort(lambda x, y: cmp(x.lower(),y.lower()))
item_list = [ { 'url' : '/files/' + url[1:] + part if is_dir(url + part) else '/files/' + url[1:] + part + '/download', 'url_ren' : '/files/' + url[1:] + part, 'url_del' : '/files/' + url[1:] + part + '/delete', 'name' : part, 'is_file' : is_file(url + part), 'size' : size(url + part) } for part in temp ]
re = {'page_title': LINKS['files_list']['title'], 'list' : item_list, 'up_dir' : '/files/' + url_parsed[1:], 'url' : url, 'edit' : False }
re.update(self.get_header())
return re
示例13: download_view
# 需要导入模块: from pyramid.response import FileResponse [as 别名]
# 或者: from pyramid.response.FileResponse import headers['Content-Disposition'] [as 别名]
def download_view(request):
session = request.session
set_language(request)
lang = get_language(request)
if "fileName" in request.params or "filename" in request.params:
if "fileName" in request.params:
filename = request.params['fileName']
else:
filename = request.params['filename']
if "fileOption" in request.params:
if request.params['fileOption'] == 'collectionsheet':
filepath = os.path.join(config['homepath'], config['collection_table']['ordered'], filename)
response = FileResponse(filepath, request=request)
response.headers['Content-Disposition'] = ("attachment; filename=" + filename)
elif request.params['fileOption'] == 'versandanschreiben':
conn = pymysql.connect(host=config['host'], port=config['port'], user=config['user'],
passwd=config['pw'], db=config['db'])
cur = conn.cursor()
cur.execute("""SELECT concat_ws(' ', salutation, title, vorname, nachname) as `name`,
street, concat_ws(' ', zip, city) as city, country, postaladdress,
s.count, transactionKey
From users u
left join ShippingRequests sr ON sr.uid = u.uid
Left join Shippings s on sr.id = s.ShippingRequestId
left join RelUserInstitution ui on sr.ContactId = ui.uid
left Join Institution i on i.id = ui.institutionId
where transactionKey = '{0}'""".format(filename))
row = cur.fetchone()
send_to = str(row[4]).split('\n')
cur.close()
if lang == 'en':
filename = 'cover_letter.pdf'
else:
filename = 'versandanschreiben.pdf'
coverLetterName = os.path.join(config['homepath'], 'documents/download', filename)
c = canvas.Canvas(coverLetterName)
c.translate(0, 700)
c.drawImage(ImageReader(os.path.join(config['homepath'], 'static/images/logo.png')), 50, -100, 200, 200)
c.setFont("Helvetica-Bold", 14)
c.setFillColorRGB(0, 0, 0)
c.drawString(20, -150, messages['letter_sender'][lang])
c.drawString(20, -290, messages['letter_send_to'][lang])
c.setFont("Helvetica", 14)
c.drawString(20, -190, row[0])
c.drawString(20, -210, row[1])
c.drawString(20, -230, row[2])
c.drawString(20, -250, row[3])
i = 0
while i < len(send_to):
c.drawString(20, -330 - i * 20, send_to[i])
i += 1
c.setFont("Helvetica-Bold", 14)
c.drawString(20, -370 - i * 20, messages['letter_order_no'][lang].format(row[6]))
c.setFont("Helvetica", 14)
c.drawString(20, -410 - i * 20, messages['letter_no_samples'][lang].format(row[5]))
c.drawString(20, -450 - i * 20, messages['letter_body1'][lang])
c.drawString(20, -470 - i * 20, messages['letter_body2'][lang])
c.showPage()
c.save()
response = FileResponse(coverLetterName, request=request)
response.headers['Content-Disposition'] = ("attachment; filename=%s" % filename)
os.remove(coverLetterName)
elif request.params['fileOption'] == 'tk_ct': # -- called via link from viewsAdmin: sammelliste_view
if 'role' in session and session['role'] is not None and 2 in session['role']: # only TK allowed downl
response = FileResponse(
os.path.join(config['homepath'], config['collection_table']['filled'], filename),
request=request
)
response.headers['Content-Disposition'] = ("attachment; filename=" + filename)
else:
url = request.route_url('sammelliste')
return HTTPFound(location=url)
elif "newsUpload" in request.params:
# used in: filemanager.js, function: selectItem and in filemanager.class.php
filename = filename.split('?')[0].encode('utf-8') # workaround for ckeditor always sending a timestamp with the filename
response = FileResponse(
os.path.join(config['homepath'], config['news']['media_directory'], filename),
request=request
)
response.headers['Content-Disposition'] = ("attachment; filename=" + filename)
elif "news" in request.params:
response = FileResponse(
os.path.join(config['homepath'], config['news']['media_directory'], filename),
request=request
)
response.headers['Content-Disposition'] = ("attachment; filename=" + filename)
else:
response = FileResponse(
os.path.join(config['homepath'], 'documents/download', filename),
request=request
)
response.headers['Content-Disposition'] = ("attachment; filename=" + filename)
return response