[gen] Possibility to define, programmatically, for a given class, the default view and edit pages, by defining, respectively, methods getDefaultViewPage and getDefaultEditPage; various bugfixes.
This commit is contained in:
parent
f843d5b7d6
commit
77331cd216
|
@ -33,11 +33,12 @@ class BaseMixin:
|
|||
field lies;
|
||||
* field is the Ref instance.
|
||||
'''
|
||||
if not rq.get('nav', '').startswith('ref.'): return (None,)*4
|
||||
rq = self.REQUEST
|
||||
if not rq.get('nav', '').startswith('ref.'): return None, None, None
|
||||
splitted = rq['nav'].split('.')
|
||||
initiator = self.tool.getObject(splitted[1])
|
||||
initiator = self.getTool().getObject(splitted[1])
|
||||
fieldName, page = splitted[2].split(':')
|
||||
return (initiator, page, self.getAppyType(fieldName))
|
||||
return initiator, page, initiator.getAppyType(fieldName)
|
||||
|
||||
def createOrUpdate(self, created, values,
|
||||
initiator=None, initiatorField=None):
|
||||
|
@ -134,7 +135,7 @@ class BaseMixin:
|
|||
splitted[-1] = splitted[-2] = str(int(splitted[-1])+1)
|
||||
urlParams['nav'] = '.'.join(splitted)
|
||||
# Check that the user can add objects through this Ref field
|
||||
initiatiorField.checkAdd(initiator)
|
||||
initiatorField.checkAdd(initiator)
|
||||
# Create a temp object in /temp_folder
|
||||
tool = self.getTool()
|
||||
id = tool.generateUid(className)
|
||||
|
@ -783,12 +784,15 @@ class BaseMixin:
|
|||
# Restrict the result to the current phase if required
|
||||
if currentOnly:
|
||||
rq = self.REQUEST
|
||||
page = rq.get('page', 'main')
|
||||
page = rq.get('page', None)
|
||||
if not page:
|
||||
if layoutType == 'edit': page = self.getDefaultEditPage()
|
||||
else: page = self.getDefaultViewPage()
|
||||
for phaseInfo in res:
|
||||
if page in phaseInfo['pages']:
|
||||
return phaseInfo
|
||||
# If I am here, it means that the page as defined in the request,
|
||||
# or 'main' by default, is not existing nor visible in any phase.
|
||||
# or the default page, is not existing nor visible in any phase.
|
||||
# In this case I find the first visible page among all phases.
|
||||
viewAttr = 'showOn%s' % layoutType.capitalize()
|
||||
for phase in res:
|
||||
|
@ -963,6 +967,20 @@ class BaseMixin:
|
|||
if hasattr(appyObj, 'mayNavigate'): return appyObj.mayNavigate()
|
||||
return True
|
||||
|
||||
def getDefaultViewPage(self):
|
||||
'''Which view page must be shown by default?'''
|
||||
appyObj = self.appy()
|
||||
if hasattr(appyObj, 'getDefaultViewPage'):
|
||||
return appyObj.getDefaultViewPage()
|
||||
return 'main'
|
||||
|
||||
def getDefaultEditPage(self):
|
||||
'''Which edit page must be shown by default?'''
|
||||
appyObj = self.appy()
|
||||
if hasattr(appyObj, 'getDefaultEditPage'):
|
||||
return appyObj.getDefaultEditPage()
|
||||
return 'main'
|
||||
|
||||
def mayAct(self):
|
||||
'''May the currently logged user see column "actions" for this
|
||||
object? This can be used for hiding the "edit" icon, for example:
|
||||
|
|
|
@ -6,12 +6,12 @@
|
|||
errors request/errors | python:{};
|
||||
layoutType python:'edit';
|
||||
layout python: contextObj.getPageLayout(layoutType);
|
||||
page request/page|python:'main';
|
||||
cssJs python: {};
|
||||
groupedWidgets python: contextObj.getGroupedAppyTypes(layoutType, page, cssJs=cssJs);
|
||||
phaseInfo python: contextObj.getAppyPhases(currentOnly=True, layoutType=layoutType);
|
||||
phase phaseInfo/name;
|
||||
confirmMsg request/confirmMsg | nothing;"
|
||||
page request/page|python:contextObj.getDefaultEditPage();
|
||||
confirmMsg request/confirmMsg | nothing;
|
||||
groupedWidgets python: contextObj.getGroupedAppyTypes(layoutType, page, cssJs=cssJs);"
|
||||
tal:on-error="structure python: tool.manageError(error)">
|
||||
|
||||
<tal:comment replace="nothing">Include type-specific CSS and JS.</tal:comment>
|
||||
|
@ -19,7 +19,6 @@
|
|||
tal:attributes="href string:$appUrl/ui/$cssFile"/>
|
||||
<script tal:repeat="jsFile cssJs/js" type="text/javascript"
|
||||
tal:attributes="src string:$appUrl/ui/$jsFile"></script>
|
||||
|
||||
<metal:prologue use-macro="context/ui/page/macros/prologue"/>
|
||||
<form id="appyEditForm" name="appyEditForm" method="post" enctype="multipart/form-data"
|
||||
tal:attributes="action python: contextObj.absolute_url()+'/do';
|
||||
|
|
|
@ -91,7 +91,7 @@
|
|||
<td id="field_title"
|
||||
tal:condition="python: widget['name'] == 'title'">
|
||||
<a tal:define="navInfo python:'search.%s.%s.%d.%d' % (className, searchName, repeat['obj'].number()+startNumber, totalNumber);"
|
||||
tal:content="obj/Title" tal:attributes="href python: obj.getUrl(nav=navInfo, page='main')"></a>
|
||||
tal:content="obj/Title" tal:attributes="href python: obj.getUrl(nav=navInfo, page=obj.getDefaultViewPage())"></a>
|
||||
</td>
|
||||
|
||||
<tal:comment replace="nothing">Workflow state</tal:comment>
|
||||
|
@ -123,7 +123,7 @@
|
|||
<tal:comment replace="nothing">Edit the element</tal:comment>
|
||||
<td>
|
||||
<a tal:define="navInfo python:'search.%s.%s.%d.%d' % (className, searchName, repeat['obj'].number()+startNumber, totalNumber);"
|
||||
tal:attributes="href python: obj.getUrl(mode='edit', page='main', nav=navInfo)"
|
||||
tal:attributes="href python: obj.getUrl(mode='edit', page=obj.getDefaultEditPage(), nav=navInfo)"
|
||||
tal:condition="obj/mayEdit">
|
||||
<img title="Edit" tal:attributes="src string: $appUrl/ui/edit.gif"/>
|
||||
</a></td>
|
||||
|
|
|
@ -3,13 +3,12 @@
|
|||
<metal:fill fill-slot="content"
|
||||
tal:define="contextObj python: context.getParentNode();
|
||||
dummy python: contextObj.allows('View', raiseError=True);
|
||||
portal_type python: context.portal_type.lower().replace(' ', '_');
|
||||
errors python: req.get('errors', {});
|
||||
layoutType python:'view';
|
||||
layout python: contextObj.getPageLayout(layoutType);
|
||||
phaseInfo python: contextObj.getAppyPhases(currentOnly=True, layoutType='view');
|
||||
page req/page|python:'main';
|
||||
phase phaseInfo/name;
|
||||
page req/page|python:contextObj.getDefaultViewPage();
|
||||
groupedWidgets python: contextObj.getGroupedAppyTypes(layoutType, page);"
|
||||
tal:on-error="structure python: tool.manageError(error)">
|
||||
<metal:prologue use-macro="context/ui/page/macros/prologue"/>
|
||||
|
|
Loading…
Reference in a new issue