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
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -159,8 +159,22 @@ class Extractor(Base):
|
||||||
self.count += 1
|
self.count += 1
|
||||||
yield elem
|
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,
|
def extractForParents(self, parents, predicates=None,
|
||||||
includeSubconcepts=False, includeResources=False):
|
includeSubconcepts=False, includeResources=False,):
|
||||||
concepts = set(parents)
|
concepts = set(parents)
|
||||||
for p in parents:
|
for p in parents:
|
||||||
self.collectConcepts(p, predicates, includeSubconcepts, concepts)
|
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
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -24,6 +24,7 @@ $Id$
|
||||||
|
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
from zope import component
|
from zope import component
|
||||||
from zope.interface import Interface, implements
|
from zope.interface import Interface, implements
|
||||||
from zope.app import zapi
|
from zope.app import zapi
|
||||||
|
@ -71,32 +72,51 @@ class ExportImport(object):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def export(self):
|
def export(self):
|
||||||
f = StringIO()
|
form = self.request.form
|
||||||
extractor = Extractor(self.context, self.resourceExportDirectory)
|
parents = predicates = None
|
||||||
parentIds = self.request.form.get('parents')
|
parentIds = form.get('parents')
|
||||||
if parentIds:
|
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:
|
else:
|
||||||
elements = extractor.extract()
|
elements = extractor.extract()
|
||||||
|
return self.download(elements)
|
||||||
|
|
||||||
|
def download(self, elements):
|
||||||
writer = component.getUtility(IWriter)
|
writer = component.getUtility(IWriter)
|
||||||
|
f = StringIO()
|
||||||
writer.write(elements, f)
|
writer.write(elements, f)
|
||||||
text = f.getvalue()
|
text = f.getvalue()
|
||||||
f.close()
|
f.close()
|
||||||
self.setDownloadHeader(self.request, text)
|
self.setDownloadHeader(self.request, text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def extractForParents(self, extractor, parentIds):
|
def parseDate(self, s):
|
||||||
form = self.request.form
|
try:
|
||||||
parentIds = [id for id in parentIds.splitlines() if id]
|
t = time.strptime(s, '%Y-%m-%d %H:%M:%S')
|
||||||
parents = [self.conceptManager.get(id) for id in parentIds]
|
except ValueError:
|
||||||
parents = [p for p in parents if p is not None]
|
try:
|
||||||
predicateIds = form.get('predicates')
|
t = time.strptime(s, '%Y-%m-%d %H:%M')
|
||||||
predicates = (predicateIds and [self.conceptManager[id]
|
except ValueError:
|
||||||
for id in parentIds] or None)
|
t = time.strptime(s, '%Y-%m-%d')
|
||||||
includeSubconcepts = form.get('include_subconcepts')
|
return int(time.mktime(t))
|
||||||
includeResources = form.get('include_resources')
|
|
||||||
return extractor.extractForParents(parents, predicates,
|
|
||||||
includeSubconcepts, includeResources)
|
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def conceptManager(self):
|
def conceptManager(self):
|
||||||
|
@ -129,4 +149,3 @@ class ExportImport(object):
|
||||||
response.setHeader('Content-Type', 'text/plain')
|
response.setHeader('Content-Type', 'text/plain')
|
||||||
response.setHeader('Content-Length', len(text))
|
response.setHeader('Content-Length', len(text))
|
||||||
|
|
||||||
|
|
||||||
|
|
8
external/exportimport.pt
vendored
8
external/exportimport.pt
vendored
|
@ -26,6 +26,14 @@
|
||||||
<div> </div>
|
<div> </div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<table>
|
<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>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<label for="parents">Parent concepts</label><br />
|
<label for="parents">Parent concepts</label><br />
|
||||||
|
|
Loading…
Add table
Reference in a new issue