improve representation of individual link objects
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3771 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
269df6b860
commit
31179360ce
3 changed files with 70 additions and 30 deletions
|
@ -57,63 +57,78 @@ actions.register('editPortalLink', 'portlet', DialogAction,
|
|||
dialogName='editPortalLink',
|
||||
)
|
||||
|
||||
class PortalPage(ConceptView):
|
||||
""" A query view linking to pages on other loops sites.
|
||||
"""
|
||||
|
||||
class Base(ConceptView):
|
||||
|
||||
@Lazy
|
||||
def site_macros(self):
|
||||
return site_macros.macros
|
||||
|
||||
@Lazy
|
||||
def root(self):
|
||||
return getRoot(self.context)
|
||||
|
||||
|
||||
class PortalPage(Base):
|
||||
""" A query view linking to pages on other loops sites.
|
||||
"""
|
||||
|
||||
@property
|
||||
def macro(self):
|
||||
return self.site_macros['portal_page']
|
||||
|
||||
@Lazy
|
||||
def root(self):
|
||||
return getRoot(self.context)
|
||||
|
||||
@Lazy
|
||||
def portalLinks(self):
|
||||
result = []
|
||||
for c in self.context.getChildren():
|
||||
link = adapted(c)
|
||||
if ILink.providedBy(link):
|
||||
site = traverse(self.root, link.site)
|
||||
path = link.path or 'home'
|
||||
target = traverse(site, 'views/' + path)
|
||||
if canAccess(target, 'title'):
|
||||
siteInfo = SiteDetails(target, self.request)
|
||||
siteInfo.title = link.title
|
||||
if link.description:
|
||||
siteInfo.description = link.description
|
||||
if link.url:
|
||||
siteInfo.url = link.url
|
||||
result.append(siteInfo)
|
||||
info = PortalLink(c, self.request).targetInfo
|
||||
if info is not None:
|
||||
result.append(info)
|
||||
return result
|
||||
|
||||
|
||||
class SiteDetails(BaseView):
|
||||
class LinkInfo(Base):
|
||||
|
||||
pass
|
||||
|
||||
|
||||
# old loops_sites.html view
|
||||
class PortalLink(Base):
|
||||
|
||||
class SitesListing(ConceptView):
|
||||
@property
|
||||
def macro(self):
|
||||
return self.site_macros['portal_link']
|
||||
|
||||
@Lazy
|
||||
def site_macros(self):
|
||||
return site_macros.macros
|
||||
def targetInfo(self):
|
||||
link = self.adapted
|
||||
if not ILink.providedBy(link):
|
||||
return None
|
||||
site = traverse(self.root, link.site, None)
|
||||
if site is None:
|
||||
return None
|
||||
path = link.path or 'home'
|
||||
target = traverse(site, 'views/' + path, None)
|
||||
if target is None:
|
||||
return None
|
||||
if not canAccess(target, 'title'):
|
||||
return None
|
||||
info = LinkInfo(target, self.request)
|
||||
info.title = link.title
|
||||
if link.description:
|
||||
info.description = link.description
|
||||
if link.url:
|
||||
info.url = link.url
|
||||
return info
|
||||
|
||||
|
||||
# old loops_sites.html view
|
||||
|
||||
class SitesListing(Base):
|
||||
|
||||
@property
|
||||
def macro(self):
|
||||
return self.site_macros['sites_listing']
|
||||
|
||||
@Lazy
|
||||
def root(self):
|
||||
return getRoot(self.context)
|
||||
|
||||
@Lazy
|
||||
def sites(self):
|
||||
result = []
|
||||
|
@ -121,6 +136,6 @@ class SitesListing(ConceptView):
|
|||
for p in paths:
|
||||
s = traverse(self.root, p)
|
||||
if canAccess(s, 'title'):
|
||||
result.append(SiteDetails(s, self.request))
|
||||
result.append(LinkInfo(s, self.request))
|
||||
return result
|
||||
|
||||
|
|
|
@ -23,6 +23,14 @@
|
|||
factory="loops.system.site.browser.PortalPage"
|
||||
permission="zope.View" />
|
||||
|
||||
<zope:adapter
|
||||
name="portal_link.html"
|
||||
for="loops.interfaces.IConcept
|
||||
zope.publisher.interfaces.browser.IBrowserRequest"
|
||||
provides="zope.interface.Interface"
|
||||
factory="loops.system.site.browser.PortalLink"
|
||||
permission="zope.View" />
|
||||
|
||||
<zope:adapter
|
||||
name="loops_sites.html"
|
||||
for="loops.interfaces.IConcept
|
||||
|
|
|
@ -19,6 +19,23 @@
|
|||
</metal:work>
|
||||
|
||||
|
||||
<metal:work define-macro="portal_link"
|
||||
tal:define="info nocall:item/targetInfo">
|
||||
<metal:title use-macro="view/concept_macros/concepttitle" />
|
||||
<metal:block use-macro="view/concept_macros/conceptfields" />
|
||||
<tal:target condition="nocall:info">
|
||||
<h3 i18n:translate="">Link Target</h3>
|
||||
<div>
|
||||
<a tal:attributes="href info/url"
|
||||
tal:content="info/title" /></div>
|
||||
<div tal:condition="info/description"
|
||||
tal:content="structure info/renderedDescription" />
|
||||
</tal:target>
|
||||
</metal:work>
|
||||
|
||||
|
||||
<!-- obsolete, replaced by portal_page -->
|
||||
|
||||
<metal:work define-macro="sites_listing">
|
||||
<h2 i18n:translate="">loops Sites</h2>
|
||||
<ul>
|
||||
|
|
Loading…
Add table
Reference in a new issue