Skip to content

Commit

Permalink
Merge branch 'master' into issue_571
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Howitz committed May 9, 2019
2 parents fe60d18 + 07e20d2 commit f39fcce
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 94 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Expand Up @@ -44,6 +44,9 @@ Fixes
Features
++++++++

- Add a flag for suppressing object events during file import
(`#42 <https://github.com/zopefoundation/Zope/issues/42>`_)

- Add a Configuration details tab to the Control_Panel

- Resurrect the Interfaces ZMI tab
Expand Down
12 changes: 8 additions & 4 deletions src/OFS/ObjectManager.py
Expand Up @@ -646,7 +646,8 @@ def manage_exportObject(
manage_importExportForm = DTMLFile('dtml/importExport', globals())

@security.protected(import_export_objects)
def manage_importObject(self, file, REQUEST=None, set_owner=1):
def manage_importObject(self, file, REQUEST=None, set_owner=1,
suppress_events=False):
"""Import an object from a file"""
dirname, file = os.path.split(file)
if dirname:
Expand All @@ -660,7 +661,8 @@ def manage_importObject(self, file, REQUEST=None, set_owner=1):
raise BadRequest('File does not exist: %s' % escape(file, True))

imported = self._importObjectFromFile(
filepath, verify=bool(REQUEST), set_owner=set_owner)
filepath, verify=bool(REQUEST), set_owner=set_owner,
suppress_events=suppress_events)
id = imported.id
if getattr(id, '__func__', None) is not None:
id = id()
Expand All @@ -674,7 +676,8 @@ def manage_importObject(self, file, REQUEST=None, set_owner=1):
update_menu=1
)

def _importObjectFromFile(self, filepath, verify=1, set_owner=1):
def _importObjectFromFile(self, filepath, verify=1, set_owner=1,
suppress_events=False):
# locate a valid connection
connection = self._p_jar
obj = self
Expand All @@ -688,7 +691,8 @@ def _importObjectFromFile(self, filepath, verify=1, set_owner=1):
id = ob.id
if getattr(id, '__func__', None) is not None:
id = id()
self._setObject(id, ob, set_owner=set_owner)
self._setObject(id, ob, set_owner=set_owner,
suppress_events=suppress_events)

# try to make ownership implicit if possible in the context
# that the object was imported into.
Expand Down
215 changes: 125 additions & 90 deletions src/OFS/dtml/importExport.dtml
Expand Up @@ -4,96 +4,131 @@

<main class="container-fluid">

<p class="form-help">
You can export Zope objects to a file in order to transfer
them to a different Zope installation. You can either choose
to download the export file to your local machine, or save it
in the <code>var</code> directory of your Zope installation
on the server.
<strong>Note:</strong>
Zope can export/import objects in a binary format (called
ZEXP). The ZEXP format is the officially supported export/import
format for moving data between <em>identical</em> Zope installations.
It is <em>not</em> a migration tool.
</p>

<form action="manage_exportObject" method="post" class="zmi-export">

<div class="form-group row">
<label for="id" class="col-sm-3 col-md-2">Export object id</label>
<div class="col-sm-9 col-md-10">
<input class="form-control" type="text" name="id" value="<dtml-if ids><dtml-var "ids[0]" html_quote></dtml-if>"/>
</div>
</div>

<div class="form-group row">
<label for="download" class="col-sm-3 col-md-2">Export to</label>
<div class="col-sm-9 col-md-10" id="download">
<div class="form-check">
<input class="form-check-input" type="radio" name="download:int" value="1" id="download_local" />
<label for="download_local" class="form-check-label">Download to local machine</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="download:int" value="0" id="download_server" checked />
<label for="download_server" class="form-check-label">Save to file on server</label>
</div>
</div>
</div>

<div class="zmi-controls">
<input class="btn btn-primary" type="submit" name="submit" value="Export" />
</div>

</form>

<hr />

<p class="form-help">
You may import Zope objects which have been previously
exported to a file, by placing the file in the &quot;import&quot;
directory of your Zope installation on the server. You should create
the &quot;import&quot; directory in the root of your Zope installation
if it does not yet exist.
<br />
Note that by default, you will become the owner of the objects
that you are importing. If you wish the imported objects to retain
their existing ownership information, select "retain existing
ownership information".
</p>

<form action="manage_importObject" method="post" class="zmi-import">


<div class="form-group row">
<label for="file" class="col-sm-3 col-md-2">Import file name</label>
<div class="col-sm-9 col-md-10">
<select class="form-control" id="file" name="file">
<dtml-in "list_imports()"
><option value="<dtml-var sequence-item>"><dtml-var sequence-item></option>
</dtml-in>
</select>
</div>
</div>

<div class="form-group row">
<label for="ownership" class="col-sm-3 col-md-2">Ownership</label>
<div class="col-sm-9 col-md-10" id="Ownership">
<div class="form-check">
<input type="radio" class="form-check-input" name="set_owner:int" value="1" id="owner_take" checked />
<label for="owner_take" class="form-check-label">Take ownership of imported objects</label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" name="set_owner:int" value="0" id="owner_retain" />
<label for="owner_retain" class="form-check-label">Retain existing ownership information</label>
</div>
</div>
</div>

<div class="zmi-controls">
<input class="btn btn-primary" type="submit" name="submit" value="Import" />
</div>

</form>
<p class="form-help">
You can export Zope objects to a file in order to transfer
them to a different Zope installation. You can either choose
to download the export file to your local machine, or save it
in the <code>var</code> directory of your Zope installation
on the server.
<strong>Note:</strong>
Zope can export/import objects in a binary format (called
ZEXP). The ZEXP format is the officially supported export/import
format for moving data between <em>identical</em> Zope installations.
It is <em>not</em> a migration tool.
</p>

<form action="manage_exportObject" method="post" class="zmi-export">

<div class="form-group row">
<label for="id" class="col-sm-3 col-md-2">Export object id</label>
<div class="col-sm-9 col-md-10">
<input class="form-control" type="text" name="id"
value="<dtml-if ids><dtml-var "ids[0]" html_quote></dtml-if>"/>
</div>
</div>

<div class="form-group row">
<label for="download" class="col-sm-3 col-md-2">Export to</label>
<div class="col-sm-9 col-md-10" id="download">
<div class="form-check">
<input class="form-check-input" type="radio" name="download:int"
value="1" id="download_local" />
<label for="download_local" class="form-check-label">
Download to local machine
</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="download:int"
value="0" id="download_server" checked />
<label for="download_server" class="form-check-label">
Save to file on server
</label>
</div>
</div>
</div>

<div class="zmi-controls">
<input class="btn btn-primary" type="submit" name="submit" value="Export" />
</div>

</form>

<hr />

<p class="form-help">
You may import Zope objects which have been previously
exported to a file, by placing the file in the &quot;import&quot;
directory of your Zope installation on the server. You should create
the &quot;import&quot; directory in the root of your Zope installation
if it does not yet exist.
<br />
Note that by default, you will become the owner of the objects
that you are importing. If you wish the imported objects to retain
their existing ownership information, select "retain existing
ownership information".
<br />
Suppressing events during an import will prevent e.g. the addition of
records for imported objects to a Catalog. Only select this if you are
aware of the consequences.
</p>

<form action="manage_importObject" method="post" class="zmi-import">


<div class="form-group row">
<label for="file" class="col-sm-3 col-md-2">Import file name</label>
<div class="col-sm-9 col-md-10">
<select class="form-control" id="file" name="file">
<dtml-in "list_imports()">
<option value="<dtml-var sequence-item>">
<dtml-var sequence-item>
</option>
</dtml-in>
</select>
</div>
</div>

<div class="form-group row">
<label for="ownership" class="col-sm-3 col-md-2">Ownership</label>
<div class="col-sm-9 col-md-10" id="Ownership">
<div class="form-check">
<input type="radio" class="form-check-input" name="set_owner:int"
value="1" id="owner_take" checked />
<label for="owner_take" class="form-check-label">
Take ownership of imported objects
</label>
</div>
<div class="form-check">
<input type="radio" class="form-check-input" name="set_owner:int"
value="0" id="owner_retain" />
<label for="owner_retain" class="form-check-label">
Retain existing ownership information
</label>
</div>
</div>
</div>

<div class="form-group row">
<label for="suppress_events" class="col-sm-3 col-md-2">
Suppress events
</label>
<div class="col-sm-9 col-md-10" id="Ownership">
<div class="form-check">
<input type="checkbox" class="form-check-input"
name="suppress_events:int"
value="1" id="suppress_events" />
<label for="suppress_events" class="form-check-label">
Suppress events during import. Dangerous, see comment above.
</label>
</div>
</div>
</div>

<div class="zmi-controls">
<input class="btn btn-primary" type="submit" name="submit" value="Import" />
</div>

</form>

</main>

Expand Down

0 comments on commit f39fcce

Please sign in to comment.