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