Skip to content

Instantly share code, notes, and snippets.

@lukasgraf
Last active December 19, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukasgraf/5949331 to your computer and use it in GitHub Desktop.
Save lukasgraf/5949331 to your computer and use it in GitHub Desktop.
UploadHeaders view
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
metal:use-macro="context/main_template/macros/master"
i18n:domain="opengever.maintenance">
<head>
<metal:head metal:fill-slot="head_slot">
<style>
table {
border-collapse: separate !important;
border-spacing: 1em 0px !important;
}
</style>
</metal:head>
</head>
<body>
<metal:main fill-slot="main">
<form enctype="multipart/form-data" method="post">
<input type="file" name="uploaded_file" id="uploaded_file" />
<br/>
<input type="hidden" value="1" name="submitted" />
<input type="submit" value="Save" class="submit-widget button-field context" name="save" id="save" />
</form>
</metal:main>
</body>
</html>
from five import grok
from pprint import pformat
from Products.CMFPlone.interfaces import IPloneSiteRoot
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
class UploadHeadersView(grok.View):
"""Simple view to display HTTP headers of a file upload request.
"""
form_template = ViewPageTemplateFile('upload_headers.pt')
grok.name('upload-headers')
grok.context(IPloneSiteRoot)
grok.require('cmf.ManagePortal')
def render(self):
if not self.request.form.get('submitted'):
html = self.form_template()
return html
else:
uploaded_file = self.request.form.get('uploaded_file')
response = ''
response += "ZPublisher.HTTPRequest.FileUpload headers: \n%s" % (
uploaded_file.headers.dict)
response += "\n\n\n\n\n\n"
response += "Full Request headers: \n%s" % (
pformat(self.request.__dict__))
return response
def update(self):
# disable Plone's editable border
self.request.set('disable_border', True)
super(UploadHeadersView, self).update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment