make import work with real life data
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2480 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
fc3e3096c8
commit
a6a7c56fb0
8 changed files with 24 additions and 7 deletions
|
@ -28,6 +28,7 @@ from zope.app.form.browser.interfaces import ITerms
|
||||||
from zope.app.i18n.interfaces import ITranslationDomain
|
from zope.app.i18n.interfaces import ITranslationDomain
|
||||||
from zope.app.security.interfaces import IAuthentication
|
from zope.app.security.interfaces import IAuthentication
|
||||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||||
|
from zope.app.security.interfaces import PrincipalLookupError
|
||||||
from zope.cachedescriptors.property import Lazy
|
from zope.cachedescriptors.property import Lazy
|
||||||
from zope.dottedname.resolve import resolve
|
from zope.dottedname.resolve import resolve
|
||||||
from zope.dublincore.interfaces import IZopeDublinCore
|
from zope.dublincore.interfaces import IZopeDublinCore
|
||||||
|
@ -161,9 +162,11 @@ class BaseView(GenericView, I18NView):
|
||||||
pau = component.getUtility(IAuthentication)
|
pau = component.getUtility(IAuthentication)
|
||||||
creators = []
|
creators = []
|
||||||
for c in cr:
|
for c in cr:
|
||||||
principal = pau.getPrincipal(c)
|
try:
|
||||||
if principal is not None:
|
principal = pau.getPrincipal(c)
|
||||||
creators.append(principal.title)
|
creators.append(principal.title)
|
||||||
|
except PrincipalLookupError:
|
||||||
|
creators.append(c)
|
||||||
return ', '.join(creators)
|
return ', '.join(creators)
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
|
|
|
@ -94,6 +94,7 @@ class AdapterBase(object):
|
||||||
|
|
||||||
_adapterAttributes = ('context', '__parent__',)
|
_adapterAttributes = ('context', '__parent__',)
|
||||||
_contextAttributes = list(IConcept)
|
_contextAttributes = list(IConcept)
|
||||||
|
_noexportAttributes = ()
|
||||||
|
|
||||||
def __init__(self, context):
|
def __init__(self, context):
|
||||||
self.context = context
|
self.context = context
|
||||||
|
@ -105,7 +106,11 @@ class AdapterBase(object):
|
||||||
|
|
||||||
def __setattr__(self, attr, value):
|
def __setattr__(self, attr, value):
|
||||||
if attr in self._adapterAttributes:
|
if attr in self._adapterAttributes:
|
||||||
object.__setattr__(self, attr, value)
|
try:
|
||||||
|
object.__setattr__(self, attr, value)
|
||||||
|
except AttributeError:
|
||||||
|
print '***', self.context.__name__, attr, value
|
||||||
|
raise
|
||||||
else:
|
else:
|
||||||
self.checkAttr(attr)
|
self.checkAttr(attr)
|
||||||
setattr(self.context, '_' + attr, value)
|
setattr(self.context, '_' + attr, value)
|
||||||
|
|
|
@ -48,6 +48,7 @@ class BlogPost(Compound):
|
||||||
|
|
||||||
_adapterAttributes = Compound._adapterAttributes + ('text', 'private', 'creator',)
|
_adapterAttributes = Compound._adapterAttributes + ('text', 'private', 'creator',)
|
||||||
_contextAttributes = Compound._contextAttributes + ['date', 'privateComment']
|
_contextAttributes = Compound._contextAttributes + ['date', 'privateComment']
|
||||||
|
_noexportAttributes = ('creator', 'text', 'private')
|
||||||
|
|
||||||
defaultTextContentType = 'text/restructured'
|
defaultTextContentType = 'text/restructured'
|
||||||
textContentType = defaultTextContentType
|
textContentType = defaultTextContentType
|
||||||
|
|
4
external/annotation.py
vendored
4
external/annotation.py
vendored
|
@ -23,7 +23,7 @@ $Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from time import time
|
import time
|
||||||
from zope.component import adapts
|
from zope.component import adapts
|
||||||
from zope.dublincore.interfaces import IZopeDublinCore
|
from zope.dublincore.interfaces import IZopeDublinCore
|
||||||
from zope.interface import implements
|
from zope.interface import implements
|
||||||
|
@ -47,7 +47,7 @@ class AnnotationsElement(Element):
|
||||||
if dc is not None:
|
if dc is not None:
|
||||||
for k, v in self.items():
|
for k, v in self.items():
|
||||||
if k in ('created', 'modified'):
|
if k in ('created', 'modified'):
|
||||||
v = datetime(*time.strptime(u'%Y-%m-%dT%H:%M')[0:6])
|
v = datetime(*time.strptime(v, u'%Y-%m-%dT%H:%M')[0:6])
|
||||||
setattr(dc, k, v)
|
setattr(dc, k, v)
|
||||||
|
|
||||||
|
|
||||||
|
|
4
external/base.py
vendored
4
external/base.py
vendored
|
@ -192,6 +192,10 @@ class Extractor(Base):
|
||||||
# this should also convert object attributes like e.g. typeInterface
|
# this should also convert object attributes like e.g. typeInterface
|
||||||
#data = instance.applyTemplate(mode='export')
|
#data = instance.applyTemplate(mode='export')
|
||||||
data = instance.applyTemplate(mode='edit')
|
data = instance.applyTemplate(mode='edit')
|
||||||
|
noexp = getattr(aObj, '_noexportAttributes', ())
|
||||||
|
for attr in noexp:
|
||||||
|
if attr in data:
|
||||||
|
del data[attr]
|
||||||
if 'title' in data:
|
if 'title' in data:
|
||||||
del data['title']
|
del data['title']
|
||||||
data['description'] = obj.description
|
data['description'] = obj.description
|
||||||
|
|
2
external/browser.py
vendored
2
external/browser.py
vendored
|
@ -89,7 +89,7 @@ class ExportImport(object):
|
||||||
return False
|
return False
|
||||||
reader = component.getUtility(IReader)
|
reader = component.getUtility(IReader)
|
||||||
elements = reader.read(data)
|
elements = reader.read(data)
|
||||||
loader = Loader(self.context)
|
loader = Loader(self.context, resourceImportDirectory)
|
||||||
loader.load(elements)
|
loader.load(elements)
|
||||||
self.message = u'Content uploaded and imported.'
|
self.message = u'Content uploaded and imported.'
|
||||||
return False
|
return False
|
||||||
|
|
2
external/element.py
vendored
2
external/element.py
vendored
|
@ -30,6 +30,7 @@ from zope.interface import Interface, implements
|
||||||
from zope.traversing.api import getName, traverse
|
from zope.traversing.api import getName, traverse
|
||||||
|
|
||||||
from loops.external.interfaces import IElement
|
from loops.external.interfaces import IElement
|
||||||
|
from loops.i18n.common import I18NValue
|
||||||
|
|
||||||
|
|
||||||
class Element(dict):
|
class Element(dict):
|
||||||
|
@ -192,6 +193,7 @@ elementTypes = dict(
|
||||||
resource=ResourceElement,
|
resource=ResourceElement,
|
||||||
resourceRelation=ResourceRelationElement,
|
resourceRelation=ResourceRelationElement,
|
||||||
node=NodeElement,
|
node=NodeElement,
|
||||||
|
I18NValue=I18NValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
toplevelElements = ('type', 'concept', 'resource', 'resourceRelation', 'node')
|
toplevelElements = ('type', 'concept', 'resource', 'resourceRelation', 'node')
|
||||||
|
|
|
@ -54,7 +54,7 @@ TypeInterfaceSourceList.typeInterfaces += (IPerson, IAddress)
|
||||||
|
|
||||||
def getPersonForUser(context, request=None, principal=None):
|
def getPersonForUser(context, request=None, principal=None):
|
||||||
if principal is None:
|
if principal is None:
|
||||||
principal = request.principal
|
principal = getattr(request, 'principal', None)
|
||||||
if principal is None:
|
if principal is None:
|
||||||
return None
|
return None
|
||||||
loops = context.getLoopsRoot()
|
loops = context.getLoopsRoot()
|
||||||
|
@ -83,6 +83,8 @@ class Person(AdapterBase, BasePerson):
|
||||||
def setUserId(self, userId):
|
def setUserId(self, userId):
|
||||||
if userId:
|
if userId:
|
||||||
principal = self.getPrincipalForUserId(userId)
|
principal = self.getPrincipalForUserId(userId)
|
||||||
|
if principal is None:
|
||||||
|
return
|
||||||
person = getPersonForUser(self.context, principal=principal)
|
person = getPersonForUser(self.context, principal=principal)
|
||||||
if person is not None and person != self.context:
|
if person is not None and person != self.context:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
|
|
Loading…
Add table
Reference in a new issue