appy.gen: added Ref.navigable: if True, referenced objects can appear within the portlet.

This commit is contained in:
Gaetan Delannay 2012-03-27 10:37:41 +02:00
parent 1e9e4df5a6
commit 5928996730
6 changed files with 67 additions and 47 deletions

View file

@ -1671,7 +1671,8 @@ class Ref(Type):
specificWritePermission=False, width=None, height=5,
maxChars=None, colspan=1, master=None, masterValue=None,
focus=False, historized=False, mapping=None, label=None,
queryable=False, queryFields=None, queryNbCols=1):
queryable=False, queryFields=None, queryNbCols=1,
navigable=False):
self.klass = klass
self.attribute = attribute
# May the user add new objects through this ref ?
@ -1737,6 +1738,8 @@ class Ref(Type):
self.queryFields = queryFields
# The search screen will have this number of columns
self.queryNbCols = queryNbCols
# Within the portlet, will referred elements appear ?
self.navigable = navigable
Type.__init__(self, validator, multiplicity, index, default, optional,
editDefault, show, page, group, layouts, move, indexed,
False, specificReadPermission, specificWritePermission,

View file

@ -737,6 +737,8 @@ class BaseMixin:
else:
phase = phases[typePhase]
phase.addPage(appyType, self, layoutType)
if (appyType.type == 'Ref') and appyType.navigable:
phase.addPageLinks(appyType, self)
# Remove phases that have no visible page
for i in range(len(res)-1, -1, -1):
if not res[i]['pages']:

View file

@ -199,7 +199,7 @@ class Page(ModelClass):
def showSubPages(self): pass
pages = gen.Ref(None, multiplicity=(0,None), add=True, link=False,
back=gen.Ref(attribute='parent', show=False),
show=showSubPages)
show=showSubPages, navigable=True)
Page.pages.klass = Page
setattr(Page, Page.pages.back.attribute, Page.pages.back)

View file

@ -18,7 +18,7 @@
</a>
</div>
</div>
<span><metal:phases use-macro="here/ui/portlet/macros/phases"/></span>
<metal:phases use-macro="here/ui/portlet/macros/phases"/>
</div>
<tal:comment replace="nothing">One section for every searchable root class.</tal:comment>
@ -99,58 +99,48 @@
This macro displays, within the portlet, the navigation tree for the
currently shown object, made of phases and contained pages.
</tal:comment>
<metal:phases define-macro="phases">
<table tal:define="phases contextObj/getAppyPhases|nothing;
<table metal:define-macro="phases"
tal:define="phases contextObj/getAppyPhases|nothing;
singlePhase python: len(phases) == 1;
page python: req.get('page', 'main')"
tal:condition="python: phases and not (singlePhase and len(phases[0]['pages'])==1)"
width="100%">
tal:condition="python: phases" width="100%">
<tal:phase repeat="phase phases">
<tal:comment replace="nothing">The box containing phase-related information</tal:comment>
<tr>
<td tal:define="label python:'%s_phase_%s' % (contextObj.meta_type, phase['name']);
singlePage python: len(phase['pages']) == 1;
status phase/phaseStatus;
phaseCss python: (status == 'Current') and ' phaseSelected' or '';
underCreation python: '/portal_factory' in context.absolute_url();
displayLink python: (status != 'Future') and not underCreation and singlePage"
phaseCss python: (status == 'Current') and ' phaseSelected' or '';"
tal:attributes="class python: not singlePhase and 'phase%s' % phaseCss or ''">
<div class="portletGroup" tal:condition="not: singlePhase">
<tal:comment replace="nothing">A single page in the phase</tal:comment>
<table tal:condition="displayLink" width="100%">
<tr tal:define="pageName python: phase['pages'][0]">
<td><a tal:attributes="href python: contextObj.getUrl(page=pageName)"
tal:content="structure python: _(label)"></a>
</td>
<td align="right">
<img title="Edit" style="cursor:pointer"
tal:attributes="onClick python: 'href: window.location=\'%s\'' % contextObj.getUrl(mode='edit', page=pageName);
src string: $appUrl/ui/edit.gif"
tal:condition="python: contextObj.allows('Modify portal content') and phase['pagesInfo'][pageName]['showOnEdit']"/>
</td>
<tal:comment replace="nothing">The title of the phase</tal:comment>
<div class="portletGroup" tal:condition="not: singlePhase"
tal:content="structure python: _(label)">
</div>
<tal:comment replace="nothing">The page(s) within the phase</tal:comment>
<table width="100%" cellpadding="0"
tal:define="singlePage python: len(phase['pages']) == 1">
<tal:page repeat="aPage phase/pages">
<tal:comment replace="nothing">1st line: page name and icons</tal:comment>
<tr valign="top" tal:condition="not: singlePage">
<td tal:attributes="class python: test(aPage == page, 'portletCurrent portletPage', 'portletPage')">
<a tal:attributes="href python: contextObj.getUrl(page=aPage)"
tal:content="structure python: _('%s_page_%s' % (contextObj.meta_type, aPage))">
</a>
</td>
<td align="right">
<img title="Edit" style="cursor:pointer"
tal:attributes="onClick python: 'href: window.location=\'%s\'' % contextObj.getUrl(mode='edit', page=aPage);
src string: $appUrl/ui/edit.gif"
tal:condition="python: contextObj.allows('Modify portal content') and phase['pagesInfo'][aPage]['showOnEdit']"/>
</td>
</tr>
<tal:comment replace="nothing">2nd line: links</tal:comment>
<tal:links define="links python: phase['pagesInfo'][aPage].get('links')" tal:condition="links">
<tr tal:repeat="link links">
<td><a tal:content="link/title" tal:attributes="href link/url"></a></td>
</tr>
</table>
<tal:comment replace="nothing">Several pages in the phase</tal:comment>
<span tal:condition="not: displayLink" tal:replace="structure python: _(label)"/>
</div>
<div class="portletMenu">
<table width="100%" cellpadding="0" tal:condition="python: len(phase['pages']) &gt; 1">
<tr tal:repeat="aPage phase/pages" valign="top">
<td tal:attributes="class python: test(aPage == page, 'portletCurrent portletPage', 'portletPage')">
<a tal:attributes="href python: contextObj.getUrl(page=aPage)"
tal:content="structure python: _('%s_page_%s' % (contextObj.meta_type, aPage))">
</a>
</td>
<td align="right">
<img title="Edit" style="cursor:pointer"
tal:attributes="onClick python: 'href: window.location=\'%s\'' % contextObj.getUrl(mode='edit', page=aPage);
src string: $appUrl/ui/edit.gif"
tal:condition="python: user.has_permission('Modify portal content', contextObj) and phase['pagesInfo'][aPage]['showOnEdit']"/>
</td>
</tr>
</table>
</div>
</tal:links>
</tal:page>
</table>
</td>
</tr>
<tal:comment replace="nothing">The down arrow pointing to the next phase (if any)</tal:comment>
@ -159,4 +149,3 @@
</tr>
</tal:phase>
</table>
</metal:phases>

View file

@ -114,6 +114,15 @@ class PhaseDescr(Descr):
self.previousPhase = None
self.nextPhase = None
def addPageLinks(self, appyType, obj):
'''If p_appyType is a navigable Ref, we must add, within self.pagesInfo,
those links.'''
if appyType.page.name in self.hiddenPages: return
infos = []
for obj in appyType.getValue(obj, type="zobjects"):
infos.append({'title': obj.title, 'url':obj.absolute_url()})
self.pagesInfo[appyType.page.name]['links'] = infos
def addPage(self, appyType, obj, layoutType):
'''Adds page-related information in the phase.'''
# If the page is already there, we have nothing more to do.

View file

@ -0,0 +1,17 @@
# ------------------------------------------------------------------------------
from appy.gen.wrappers import AbstractWrapper
# ------------------------------------------------------------------------------
class PageWrapper(AbstractWrapper):
def validate(self, new, errors):
'''Inter-field validation.'''
return self._callCustom('validate', new, errors)
def showSubPages(self):
'''Show the sub-pages.'''
if self.user.has_role('Manager'): return 'view'
def onEdit(self, created):
return self._callCustom('onEdit', created)
# ------------------------------------------------------------------------------