From cedaf06606657122e5670e62343c88d0caab6bda Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Sun, 7 Oct 2012 15:33:16 +0200 Subject: [PATCH] collect error informaiton when updating collection and show in view --- integrator/browser.py | 6 +++--- integrator/collection.py | 19 ++++++++++++++----- integrator/collection_macros.pt | 4 ++++ integrator/office/base.py | 21 +++++++++++++-------- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/integrator/browser.py b/integrator/browser.py index 0ecf9bd..ad103ad 100644 --- a/integrator/browser.py +++ b/integrator/browser.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2008 Helmut Merz helmutm@cy55.de +# Copyright (c) 2012 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 @@ -18,8 +18,6 @@ """ View class(es) for integrating external objects. - -$Id$ """ from zope import interface, component @@ -44,5 +42,7 @@ class ExternalCollectionView(ConceptView): cta = adapted(self.context) if cta is not None: cta.update() + if cta.updateMessage is not None: + self.request.form['message'] = cta.updateMessage return True diff --git a/integrator/collection.py b/integrator/collection.py index a6a6670..33c1912 100644 --- a/integrator/collection.py +++ b/integrator/collection.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2009 Helmut Merz helmutm@cy55.de +# Copyright (c) 2012 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 @@ -19,8 +19,6 @@ """ Concept adapter(s) for external collections, e.g. a directory in the file system. - -$Id$ """ from datetime import datetime @@ -62,10 +60,12 @@ class ExternalCollectionAdapter(AdapterBase): implements(IExternalCollection) adapts(IConcept) - _adapterAttributes = ('context', '__parent__', 'exclude', 'newResources') + _adapterAttributes = AdapterBase._adapterAttributes + ( + 'exclude', 'newResources', 'updateMessage') _contextAttributes = list(IExternalCollection) + list(IConcept) newResources = None + updateMessage = None def getExclude(self): return getattr(self.context, '_exclude', None) or [] @@ -102,11 +102,15 @@ class ExternalCollectionAdapter(AdapterBase): directory = provider.getDirectory(self) adobj.storageParams=dict(subdirectory=directory) adobj.externalAddress = addr + # collect error information + if adobj.processingErrors: + message = self.updateMessage or u'' + message += u'
'.join(adobj.processingErrors) + self.updateMessage = message # force reindexing notify(ObjectModifiedEvent(obj)) else: new.append(addr) - #print '*** new', new if new: self.newResources = provider.createExtFileObjects(self, new) for r in self.newResources: @@ -206,6 +210,11 @@ class DirectoryCollectionProvider(object): ) adobj = adapted(obj) adobj.externalAddress = addr # must be set last + # collect error information + if adobj.processingErrors: + message = client.updateMessage or u'' + message += u'
'.join(adobj.processingErrors) + client.updateMessage = message yield obj def getDirectory(self, client): diff --git a/integrator/collection_macros.pt b/integrator/collection_macros.pt index 6df9ca0..8c3e898 100644 --- a/integrator/collection_macros.pt +++ b/integrator/collection_macros.pt @@ -7,6 +7,10 @@ +
diff --git a/integrator/office/base.py b/integrator/office/base.py index 92ed93b..d4d86e5 100644 --- a/integrator/office/base.py +++ b/integrator/office/base.py @@ -1,5 +1,5 @@ # -# Copyright (c) 2010 Helmut Merz helmutm@cy55.de +# Copyright (c) 2012 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 @@ -18,8 +18,6 @@ """ Resource adapter(s) for MS Office files. - -$Id$ """ from datetime import date, datetime, timedelta @@ -54,11 +52,16 @@ class OfficeFile(ExternalFileAdapter): implements(IOfficeFile) + _adapterAttributes = ExternalFileAdapter._adapterAttributes + ( + 'processingErrors',) + propertyMap = {u'Revision:': 'version'} propFileName = 'docProps/custom.xml' fileExtensions = ('.docm', '.docx', 'dotm', 'dotx', 'pptx', 'potx', 'ppsx', '.xlsm', '.xlsx', '.xltm', '.xltx') + processingErrors = [] + @Lazy def logger(self): return getLogger('loops.integrator.office.base.OfficeFile') @@ -136,7 +139,9 @@ class OfficeFile(ExternalFileAdapter): newZf.writestr(self.propFileName, etree.tostring(dom)) newZf.close() shutil.move(newFn, fn) - self.update(attributes) + errors = self.update(attributes) + if errors: + self.processingErrors = errors def update(self, attributes): # to be implemented by subclass @@ -146,10 +151,10 @@ class OfficeFile(ExternalFileAdapter): def parseDate(s): if not s: return None - tt = strptime(s, '%Y-%m-%dT%H:%M:%SZ') - #try: - # tt = strptime(s, '%Y-%m-%dT%H:%M:%SZ') - #except ValueError: + try: + tt = strptime(s, '%Y-%m-%dT%H:%M:%SZ') + except ValueError: + return None # try: # tt = strptime(s, '%d.%m.%y') # except ValueError: