work in progress: allow linking to parents from other loops sites: allow selection of foreign types
This commit is contained in:
parent
bc8e42240e
commit
349dc89bb8
2 changed files with 33 additions and 8 deletions
|
@ -49,7 +49,7 @@ from zope.security import canAccess
|
|||
from zope.security.interfaces import ForbiddenAttribute, Unauthorized
|
||||
from zope.security.proxy import removeSecurityProxy
|
||||
from zope.traversing.browser import absoluteURL
|
||||
from zope.traversing.api import getName, getParent
|
||||
from zope.traversing.api import getName, getParent, traverse
|
||||
|
||||
from cybertools.ajax.dojo import dojoMacroTemplate
|
||||
from cybertools.browser.view import GenericView
|
||||
|
@ -70,7 +70,7 @@ from loops.organize.tracking import access
|
|||
from loops.resource import Resource
|
||||
from loops.security.common import checkPermission
|
||||
from loops.security.common import canAccessObject, canListObject, canWriteObject
|
||||
from loops.type import ITypeConcept
|
||||
from loops.type import ITypeConcept, LoopsTypeInfo
|
||||
from loops import util
|
||||
from loops.util import _, saveRequest
|
||||
from loops import version
|
||||
|
@ -531,11 +531,29 @@ class BaseView(GenericView, I18NView):
|
|||
def conceptTypes(self):
|
||||
return util.KeywordVocabulary(self.listTypes(('concept',), ('hidden',)))
|
||||
|
||||
def parentTypesFromOtherSites(self):
|
||||
result = []
|
||||
typeNames = self.typeOptions('parent_link_types') or []
|
||||
for path in self.typeOptions('parent_link_sites') or []:
|
||||
site = traverse(self.loopsRoot, path, None)
|
||||
if site is None:
|
||||
continue
|
||||
cm = site.getConceptManager()
|
||||
for tname in typeNames:
|
||||
t = cm.get(tname)
|
||||
if t is not None:
|
||||
type = LoopsTypeInfo(t)
|
||||
type.isForeignReference = True
|
||||
result.append(type)
|
||||
return result
|
||||
|
||||
def listTypesForSearch(self, include=None, exclude=None, sortOn='title'):
|
||||
types = [dict(token=t.tokenForSearch, title=t.title)
|
||||
for t in ITypeManager(self.context).listTypes(include, exclude)]
|
||||
if sortOn:
|
||||
types.sort(key=lambda x: x[sortOn])
|
||||
for t in self.parentTypesFromOtherSites():
|
||||
types.append(dict(token=t.tokenForSearch, title=t.title))
|
||||
return types
|
||||
|
||||
def typesForSearch(self):
|
||||
|
|
19
type.py
19
type.py
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2006 Helmut Merz helmutm@cy55.de
|
||||
# Copyright (c) 2013 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 @@
|
|||
|
||||
"""
|
||||
Type management stuff.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope import component, schema
|
||||
|
@ -28,7 +26,7 @@ from zope.interface import implements
|
|||
from zope.cachedescriptors.property import Lazy
|
||||
from zope.dottedname.resolve import resolve
|
||||
from zope.security.proxy import removeSecurityProxy
|
||||
from zope.traversing.api import getName
|
||||
from zope.traversing.api import getName, getPath
|
||||
|
||||
from cybertools.typology.type import BaseType, TypeManager
|
||||
from cybertools.typology.interfaces import ITypeManager
|
||||
|
@ -50,10 +48,15 @@ class LoopsType(BaseType):
|
|||
#document=Document)
|
||||
containerMapping = dict(concept='concepts', resource='resources')
|
||||
|
||||
isForeignReference = False
|
||||
|
||||
@Lazy
|
||||
def title(self):
|
||||
tp = self.typeProvider
|
||||
return tp is None and u'Unknown Type' or tp.title
|
||||
title = tp is None and u'Unknown Type' or tp.title
|
||||
if self.isForeignReference:
|
||||
title += (' (Site: %s)' % getName(self.root))
|
||||
return title
|
||||
|
||||
@Lazy
|
||||
def token(self):
|
||||
|
@ -64,7 +67,11 @@ class LoopsType(BaseType):
|
|||
def tokenForSearch(self):
|
||||
tp = self.typeProvider
|
||||
typeName = tp is None and 'unknown' or str(getName(tp))
|
||||
return ':'.join(('loops', self.qualifiers[0], typeName,))
|
||||
if self.isForeignReference:
|
||||
root = '/'.join(getPath(self.root))
|
||||
else:
|
||||
root = 'loops'
|
||||
return ':'.join((root, self.qualifiers[0], typeName,))
|
||||
|
||||
@Lazy
|
||||
def typeInterface(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue