collect error informaiton when updating collection and show in view
This commit is contained in:
parent
8f19077602
commit
cedaf06606
4 changed files with 34 additions and 16 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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'<br />'.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'<br />'.join(adobj.processingErrors)
|
||||
client.updateMessage = message
|
||||
yield obj
|
||||
|
||||
def getDirectory(self, client):
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
<metal:block use-macro="view/concept_macros/conceptdata">
|
||||
<metal:fill tal:condition="item/editable"
|
||||
fill-slot="fields">
|
||||
<div class="error"
|
||||
tal:define="message view/message | request/message | nothing"
|
||||
tal:condition="message"
|
||||
tal:content="structure message" />
|
||||
<metal:block use-macro="view/concept_macros/conceptfields" />
|
||||
<form method="post">
|
||||
<input type="submit" name="update" value="Update Collection" />
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue