export/import of nodes basically OK
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1010 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
774a8526d0
commit
62c5514219
2 changed files with 139 additions and 0 deletions
60
browser/exportimport.pt
Normal file
60
browser/exportimport.pt
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
<tal:show condition="not:view/submit">
|
||||||
|
<html metal:use-macro="context/@@standard_macros/view">
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<metal:body fill-slot="body">
|
||||||
|
|
||||||
|
<h3>Export/Import loops View Nodes</h3>
|
||||||
|
|
||||||
|
<div tal:define="message view/message | request/message | nothing"
|
||||||
|
tal:condition="message"
|
||||||
|
tal:content="message">Message</div>
|
||||||
|
|
||||||
|
<div> </div>
|
||||||
|
<div>
|
||||||
|
This form allows you to export nodes to a
|
||||||
|
file and upload a file created by a content export.
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form action="." method="post"
|
||||||
|
tal:attributes="action string:${request/URL/-1}/export_nodes.html">
|
||||||
|
<input type="hidden" name="loops.action" value="export" />
|
||||||
|
<div> </div>
|
||||||
|
<h4>Export Nodes</h4>
|
||||||
|
<div> </div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="controls">
|
||||||
|
<input type="submit" name="loops.export" value="Export" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<form action="." method="post" enctype="multipart/form-data"
|
||||||
|
tal:attributes="action request/URL">
|
||||||
|
<input type="hidden" name="loops.action" value="upload" />
|
||||||
|
<div> </div>
|
||||||
|
<h4>Import Nodes</h4>
|
||||||
|
<div class="row">
|
||||||
|
<div class="label">
|
||||||
|
<label for="field.data"
|
||||||
|
title="The file to be uploaded.">File</label>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<input class="fileType" id="field.data" name="field.data"
|
||||||
|
size="20" type="file" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="controls">
|
||||||
|
<input type="submit" name="loops.upload" value="Upload" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</metal:body>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
</tal:show>
|
79
browser/external.py
Normal file
79
browser/external.py
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
view class(es) for import/export.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
from zope.interface import Interface, implements
|
||||||
|
from zope.app import zapi
|
||||||
|
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
|
||||||
|
from zope.cachedescriptors.property import Lazy
|
||||||
|
from zope.security.proxy import removeSecurityProxy
|
||||||
|
from cStringIO import StringIO
|
||||||
|
|
||||||
|
from loops.external import IExternalContentSource
|
||||||
|
from loops.external import ILoader, IExporter
|
||||||
|
|
||||||
|
|
||||||
|
class NodesExportImport(object):
|
||||||
|
""" View providing export and import functionality.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, context, request):
|
||||||
|
self.context = removeSecurityProxy(context)
|
||||||
|
self.request = request
|
||||||
|
self.message = u''
|
||||||
|
|
||||||
|
def submit(self):
|
||||||
|
action = self.request.get('loops.action', None)
|
||||||
|
if action:
|
||||||
|
method = getattr(self, action, None)
|
||||||
|
if method:
|
||||||
|
return method()
|
||||||
|
return False
|
||||||
|
|
||||||
|
def export(self):
|
||||||
|
f = StringIO()
|
||||||
|
exporter = IExporter(self.context)
|
||||||
|
exporter.dumpData(f, noclose=True)
|
||||||
|
text = f.getvalue()
|
||||||
|
f.close()
|
||||||
|
self.setDownloadHeader(self.request, text)
|
||||||
|
return text
|
||||||
|
|
||||||
|
def upload(self):
|
||||||
|
data = self.request.get('field.data', None)
|
||||||
|
if not data:
|
||||||
|
return False
|
||||||
|
importer = IExternalContentSource(self.context)
|
||||||
|
text = importer.getData(data)
|
||||||
|
loader = ILoader(self.context)
|
||||||
|
loader.load(text)
|
||||||
|
self.message = u'Content uploaded and imported.'
|
||||||
|
return False
|
||||||
|
|
||||||
|
def setDownloadHeader(self, request, text):
|
||||||
|
response = request.response
|
||||||
|
response.setHeader('Content-Disposition',
|
||||||
|
'attachment; filename=yeepacontent.dmp')
|
||||||
|
response.setHeader('Content-Type', 'text/plain')
|
||||||
|
response.setHeader('Content-Length', len(text))
|
||||||
|
|
Loading…
Add table
Reference in a new issue