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.security.interfaces import IAuthentication
|
||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||
from zope.app.security.interfaces import PrincipalLookupError
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.dottedname.resolve import resolve
|
||||
from zope.dublincore.interfaces import IZopeDublinCore
|
||||
|
@ -161,9 +162,11 @@ class BaseView(GenericView, I18NView):
|
|||
pau = component.getUtility(IAuthentication)
|
||||
creators = []
|
||||
for c in cr:
|
||||
principal = pau.getPrincipal(c)
|
||||
if principal is not None:
|
||||
try:
|
||||
principal = pau.getPrincipal(c)
|
||||
creators.append(principal.title)
|
||||
except PrincipalLookupError:
|
||||
creators.append(c)
|
||||
return ', '.join(creators)
|
||||
|
||||
@Lazy
|
||||
|
|
|
@ -94,6 +94,7 @@ class AdapterBase(object):
|
|||
|
||||
_adapterAttributes = ('context', '__parent__',)
|
||||
_contextAttributes = list(IConcept)
|
||||
_noexportAttributes = ()
|
||||
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
|
@ -105,7 +106,11 @@ class AdapterBase(object):
|
|||
|
||||
def __setattr__(self, attr, value):
|
||||
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:
|
||||
self.checkAttr(attr)
|
||||
setattr(self.context, '_' + attr, value)
|
||||
|
|
|
@ -48,6 +48,7 @@ class BlogPost(Compound):
|
|||
|
||||
_adapterAttributes = Compound._adapterAttributes + ('text', 'private', 'creator',)
|
||||
_contextAttributes = Compound._contextAttributes + ['date', 'privateComment']
|
||||
_noexportAttributes = ('creator', 'text', 'private')
|
||||
|
||||
defaultTextContentType = 'text/restructured'
|
||||
textContentType = defaultTextContentType
|
||||
|
|
4
external/annotation.py
vendored
4
external/annotation.py
vendored
|
@ -23,7 +23,7 @@ $Id$
|
|||
"""
|
||||
|
||||
from datetime import datetime
|
||||
from time import time
|
||||
import time
|
||||
from zope.component import adapts
|
||||
from zope.dublincore.interfaces import IZopeDublinCore
|
||||
from zope.interface import implements
|
||||
|
@ -47,7 +47,7 @@ class AnnotationsElement(Element):
|
|||
if dc is not None:
|
||||
for k, v in self.items():
|
||||
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)
|
||||
|
||||
|
||||
|
|
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
|
||||
#data = instance.applyTemplate(mode='export')
|
||||
data = instance.applyTemplate(mode='edit')
|
||||
noexp = getattr(aObj, '_noexportAttributes', ())
|
||||
for attr in noexp:
|
||||
if attr in data:
|
||||
del data[attr]
|
||||
if 'title' in data:
|
||||
del data['title']
|
||||
data['description'] = obj.description
|
||||
|
|
2
external/browser.py
vendored
2
external/browser.py
vendored
|
@ -89,7 +89,7 @@ class ExportImport(object):
|
|||
return False
|
||||
reader = component.getUtility(IReader)
|
||||
elements = reader.read(data)
|
||||
loader = Loader(self.context)
|
||||
loader = Loader(self.context, resourceImportDirectory)
|
||||
loader.load(elements)
|
||||
self.message = u'Content uploaded and imported.'
|
||||
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 loops.external.interfaces import IElement
|
||||
from loops.i18n.common import I18NValue
|
||||
|
||||
|
||||
class Element(dict):
|
||||
|
@ -192,6 +193,7 @@ elementTypes = dict(
|
|||
resource=ResourceElement,
|
||||
resourceRelation=ResourceRelationElement,
|
||||
node=NodeElement,
|
||||
I18NValue=I18NValue,
|
||||
)
|
||||
|
||||
toplevelElements = ('type', 'concept', 'resource', 'resourceRelation', 'node')
|
||||
|
|
|
@ -54,7 +54,7 @@ TypeInterfaceSourceList.typeInterfaces += (IPerson, IAddress)
|
|||
|
||||
def getPersonForUser(context, request=None, principal=None):
|
||||
if principal is None:
|
||||
principal = request.principal
|
||||
principal = getattr(request, 'principal', None)
|
||||
if principal is None:
|
||||
return None
|
||||
loops = context.getLoopsRoot()
|
||||
|
@ -83,6 +83,8 @@ class Person(AdapterBase, BasePerson):
|
|||
def setUserId(self, userId):
|
||||
if userId:
|
||||
principal = self.getPrincipalForUserId(userId)
|
||||
if principal is None:
|
||||
return
|
||||
person = getPersonForUser(self.context, principal=principal)
|
||||
if person is not None and person != self.context:
|
||||
raise ValueError(
|
||||
|
|
Loading…
Add table
Reference in a new issue