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

View file

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

View file

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

View file

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

View file

@ -114,6 +114,15 @@ class PhaseDescr(Descr):
self.previousPhase = None self.previousPhase = None
self.nextPhase = 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): def addPage(self, appyType, obj, layoutType):
'''Adds page-related information in the phase.''' '''Adds page-related information in the phase.'''
# If the page is already there, we have nothing more to do. # 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)
# ------------------------------------------------------------------------------