[gen] Performance improvements.

This commit is contained in:
Gaetan Delannay 2014-09-23 12:47:44 +02:00
parent 2f30730d3b
commit 701eae1b19
5 changed files with 21 additions and 26 deletions

View file

@ -61,32 +61,28 @@ class Page:
res = Page(pageData[0], phase=pageData[1]) res = Page(pageData[0], phase=pageData[1])
return res return res
def isShowable(self, obj, layoutType, elem='page'): def isShowable(self, obj, elem='page'):
'''Must this page be shown for p_obj? "Show value" can be True, False '''Must this page be shown for p_obj? The method can return True, False
or 'view' (page is available only in "view" mode). or 'view' (page is available only in "view" mode).
If p_elem is not "page", this method returns the fact that a If p_elem is not "page", this method returns the fact that a
sub-element is viewable or not (buttons "save", "cancel", etc).''' sub-element is viewable or not (buttons "save", "cancel", etc).'''
# Define what attribute to test for "showability". # Define what attribute to test for "showability".
showAttr = 'show' attr = (elem == 'page') and 'show' or ('show%s' % elem.capitalize())
if elem != 'page':
showAttr = 'show%s' % elem.capitalize()
# Get the value of the show attribute as identified above. # Get the value of the show attribute as identified above.
show = getattr(self, showAttr) res = getattr(self, attr)
if callable(show): if callable(res): res = res(obj.appy())
show = show(obj.appy())
# Show value can be 'view', for example. Thanks to p_layoutType,
# convert show value to a real final boolean value.
res = show
if res == 'view': res = layoutType == 'view'
return res return res
def getInfo(self, obj, layoutType): def getInfo(self, obj, layoutType):
'''Gets information about this page, for p_obj, as an object.''' '''Gets information about this page, for p_obj, as an object.'''
res = Object() res = Object()
for elem in Page.subElements: for elem in Page.subElements:
setattr(res, 'show%s' % elem.capitalize(), \ showable = self.isShowable(obj, elem)
self.isShowable(obj, layoutType, elem=elem)) # "showable" can be True, False or "view"
if layoutType == 'edit': showable = showable==True
else: showable = bool(showable)
setattr(res, 'show%s' % elem.capitalize(), showable)
return res return res
def getLabel(self, zobj): def getLabel(self, zobj):

View file

@ -136,14 +136,13 @@ class Phase:
if (field.page.name in self.pages) or \ if (field.page.name in self.pages) or \
(field.page.name in self.hiddenPages): return (field.page.name in self.hiddenPages): return
# Add the page only if it must be shown. # Add the page only if it must be shown.
isShowableOnView = field.page.isShowable(obj, 'view') showable = field.page.isShowable(obj)
isShowableOnEdit = field.page.isShowable(obj, 'edit') if showable:
if isShowableOnView or isShowableOnEdit: # The page must be added
# The page must be added.
self.pages.append(field.page.name) self.pages.append(field.page.name)
# Create the dict about page information and add it in self.pageInfo # Create the dict about page information and add it in self.pageInfo
pageInfo = Object(page=field.page, showOnView=isShowableOnView, pageInfo = Object(page=field.page, showOnView=bool(showable),
showOnEdit=isShowableOnEdit, links=None) showOnEdit=showable==True, links=None)
pageInfo.update(field.page.getInfo(obj, layoutType)) pageInfo.update(field.page.getInfo(obj, layoutType))
self.pagesInfo[field.page.name] = pageInfo self.pagesInfo[field.page.name] = pageInfo
else: else:

View file

@ -25,7 +25,7 @@ msgstr "Kommentar"
#. Default: "Manager" #. Default: "Manager"
msgid "role_Manager" msgid "role_Manager"
msgstr "" msgstr "Systemmanager"
#. Default: "Anonymous" #. Default: "Anonymous"
msgid "role_Anonymous" msgid "role_Anonymous"
@ -37,7 +37,7 @@ msgstr ""
#. Default: "Owner" #. Default: "Owner"
msgid "role_Owner" msgid "role_Owner"
msgstr "" msgstr "Eigentümer"
#. Default: "Title" #. Default: "Title"
msgid "appy_title" msgid "appy_title"
@ -45,7 +45,7 @@ msgstr "Titel"
#. Default: "Ok" #. Default: "Ok"
msgid "appy_ok" msgid "appy_ok"
msgstr "" msgstr "OK"
#. Default: "Data change" #. Default: "Data change"
msgid "data_change" msgid "data_change"

View file

@ -37,7 +37,7 @@ msgstr ""
#. Default: "Owner" #. Default: "Owner"
msgid "role_Owner" msgid "role_Owner"
msgstr "" msgstr "Proprietario"
#. Default: "Title" #. Default: "Title"
msgid "appy_title" msgid "appy_title"

View file

@ -70,8 +70,8 @@ class AbstractWrapper(object):
</tr> </tr>
</table> </table>
<!-- Object phases and pages --> <!-- Object phases and pages -->
<x var="phases=zobj.getAppyPhases()" <x if="zobj.mayNavigate()" var2="phases=zobj.getAppyPhases()">
if="phases and zobj.mayNavigate()">:phases[0].pxAllPhases</x>''') <x if="phases">:phases[0].pxAllPhases</x></x>''')
# The template PX for all pages. # The template PX for all pages.
pxTemplate = Px(''' pxTemplate = Px('''