work in progress: select objects to export by date of last change
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3690 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
94b9143b30
commit
6e5e52a329
3 changed files with 61 additions and 20 deletions
18
external/base.py
vendored
18
external/base.py
vendored
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||
# Copyright (c) 2010 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
|
||||
|
@ -159,8 +159,22 @@ class Extractor(Base):
|
|||
self.count += 1
|
||||
yield elem
|
||||
|
||||
def extractChanged(self, changedSince, parents=None, predicates=None,
|
||||
includeSubconcepts=False, includeResources=False,):
|
||||
rm = self.context.getRecordManager()
|
||||
if rm is not None:
|
||||
changes = rm.get('changes')
|
||||
if not changes:
|
||||
return []
|
||||
tracks = changes.query(timeFrom=changedSince)
|
||||
# work in progress: TODO:
|
||||
# select objects,
|
||||
# check parents using predicates given,
|
||||
# include children and resources if corresponding flags are set.
|
||||
return []
|
||||
|
||||
def extractForParents(self, parents, predicates=None,
|
||||
includeSubconcepts=False, includeResources=False):
|
||||
includeSubconcepts=False, includeResources=False,):
|
||||
concepts = set(parents)
|
||||
for p in parents:
|
||||
self.collectConcepts(p, predicates, includeSubconcepts, concepts)
|
||||
|
|
55
external/browser.py
vendored
55
external/browser.py
vendored
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
|
||||
# Copyright (c) 2010 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
|
||||
|
@ -24,6 +24,7 @@ $Id$
|
|||
|
||||
from cStringIO import StringIO
|
||||
import os
|
||||
import time
|
||||
from zope import component
|
||||
from zope.interface import Interface, implements
|
||||
from zope.app import zapi
|
||||
|
@ -71,32 +72,51 @@ class ExportImport(object):
|
|||
return False
|
||||
|
||||
def export(self):
|
||||
f = StringIO()
|
||||
extractor = Extractor(self.context, self.resourceExportDirectory)
|
||||
parentIds = self.request.form.get('parents')
|
||||
form = self.request.form
|
||||
parents = predicates = None
|
||||
parentIds = form.get('parents')
|
||||
if parentIds:
|
||||
elements = self.extractForParents(extractor, parentIds)
|
||||
parentIds = [id for id in parentIds.splitlines() if id]
|
||||
parents = [self.conceptManager.get(id) for id in parentIds]
|
||||
parents = [p for p in parents if p is not None]
|
||||
predicateIds = form.get('predicates')
|
||||
if predicateIds:
|
||||
predicates = (predicateIds and [self.conceptManager[id]
|
||||
for id in predicateIds] or None)
|
||||
changed = form.get('changed')
|
||||
includeSubconcepts = form.get('include_subconcepts')
|
||||
includeResources = form.get('include_resources')
|
||||
extractor = Extractor(self.context, self.resourceExportDirectory)
|
||||
if changed:
|
||||
changed = self.parseDate(changed)
|
||||
if changed:
|
||||
elements = extractor.extractChanged(changed, parents, predicates,
|
||||
includeSubconcepts, includeResources)
|
||||
elif parents:
|
||||
elements = extractor.extractForParents(parents, predicates,
|
||||
includeSubconcepts, includeResources)
|
||||
else:
|
||||
elements = extractor.extract()
|
||||
return self.download(elements)
|
||||
|
||||
def download(self, elements):
|
||||
writer = component.getUtility(IWriter)
|
||||
f = StringIO()
|
||||
writer.write(elements, f)
|
||||
text = f.getvalue()
|
||||
f.close()
|
||||
self.setDownloadHeader(self.request, text)
|
||||
return text
|
||||
|
||||
def extractForParents(self, extractor, parentIds):
|
||||
form = self.request.form
|
||||
parentIds = [id for id in parentIds.splitlines() if id]
|
||||
parents = [self.conceptManager.get(id) for id in parentIds]
|
||||
parents = [p for p in parents if p is not None]
|
||||
predicateIds = form.get('predicates')
|
||||
predicates = (predicateIds and [self.conceptManager[id]
|
||||
for id in parentIds] or None)
|
||||
includeSubconcepts = form.get('include_subconcepts')
|
||||
includeResources = form.get('include_resources')
|
||||
return extractor.extractForParents(parents, predicates,
|
||||
includeSubconcepts, includeResources)
|
||||
def parseDate(self, s):
|
||||
try:
|
||||
t = time.strptime(s, '%Y-%m-%d %H:%M:%S')
|
||||
except ValueError:
|
||||
try:
|
||||
t = time.strptime(s, '%Y-%m-%d %H:%M')
|
||||
except ValueError:
|
||||
t = time.strptime(s, '%Y-%m-%d')
|
||||
return int(time.mktime(t))
|
||||
|
||||
@Lazy
|
||||
def conceptManager(self):
|
||||
|
@ -129,4 +149,3 @@ class ExportImport(object):
|
|||
response.setHeader('Content-Type', 'text/plain')
|
||||
response.setHeader('Content-Length', len(text))
|
||||
|
||||
|
||||
|
|
8
external/exportimport.pt
vendored
8
external/exportimport.pt
vendored
|
@ -26,6 +26,14 @@
|
|||
<div> </div>
|
||||
<div class="row">
|
||||
<table>
|
||||
<tr tal:condition="nothing">
|
||||
<td>
|
||||
<label for="changed">Export only objects changed since:<br />
|
||||
(YYYY-MM-DD[ HH:MM[:SS]])</label></td>
|
||||
<td colspan="3">
|
||||
<input type="text" name="changed" id="changed" />
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<label for="parents">Parent concepts</label><br />
|
||||
|
|
Loading…
Add table
Reference in a new issue