appy.gen: use new index 'getState' for indexing object states; reduced size of generated file config.py; optimized debug mode: class reload is not done automatically: a 'refresh' icon is available on view and edit views.
This commit is contained in:
parent
9258b76bdf
commit
b6dcc42038
10 changed files with 106 additions and 121 deletions
|
@ -79,10 +79,9 @@ class ToolMixin(BaseMixin):
|
|||
def _appy_getAllFields(self, contentType):
|
||||
'''Returns the (translated) names of fields of p_contentType.'''
|
||||
res = []
|
||||
for appyType in self.getProductConfig().attributes[contentType]:
|
||||
if appyType.name != 'title': # Will be included by default.
|
||||
label = '%s_%s' % (contentType, appyType.name)
|
||||
res.append((appyType.name, self.translate(label)))
|
||||
for appyType in self.getAllAppyTypes(className=contentType):
|
||||
if appyType.name == 'title': continue # Will be included by default.
|
||||
res.append((appyType.name, self.translate(appyType.labelId)))
|
||||
# Add object state
|
||||
res.append(('workflowState', self.translate('workflow_state')))
|
||||
return res
|
||||
|
@ -91,7 +90,7 @@ class ToolMixin(BaseMixin):
|
|||
'''Returns the (translated) names of fields that may be searched on
|
||||
objects of type p_contentType (=indexed fields).'''
|
||||
res = []
|
||||
for appyType in self.getProductConfig().attributes[contentType]:
|
||||
for appyType in self.getAllAppyTypes(className=contentType):
|
||||
if appyType.indexed:
|
||||
res.append((appyType.name, self.translate(appyType.labelId)))
|
||||
return res
|
||||
|
@ -343,26 +342,23 @@ class ToolMixin(BaseMixin):
|
|||
def getPublishedObject(self):
|
||||
'''Gets the currently published object, if its meta_class is among
|
||||
application classes.'''
|
||||
rq = self.REQUEST
|
||||
obj = rq['PUBLISHED']
|
||||
obj = self.REQUEST['PUBLISHED']
|
||||
parent = obj.getParentNode()
|
||||
if parent.id == 'skyn':
|
||||
obj = parent.getParentNode()
|
||||
if obj.meta_type in self.getProductConfig().attributes:
|
||||
return obj
|
||||
return None
|
||||
if parent.id == 'skyn': obj = parent.getParentNode()
|
||||
if obj.meta_type in self.getProductConfig().attributes: return obj
|
||||
|
||||
def getAppyClass(self, contentType):
|
||||
def getAppyClass(self, contentType, wrapper=False):
|
||||
'''Gets the Appy Python class that is related to p_contentType.'''
|
||||
# Retrieve first the Archetypes class corresponding to p_ContentType
|
||||
portalType = self.portal_types.get(contentType)
|
||||
if not portalType: return None
|
||||
if not portalType: return
|
||||
atClassName = portalType.getProperty('content_meta_type')
|
||||
appName = self.getProductConfig().PROJECTNAME
|
||||
exec 'from Products.%s.%s import %s as atClass' % \
|
||||
(appName, atClassName, atClassName)
|
||||
# Get then the Appy Python class
|
||||
return atClass.wrapperClass.__bases__[-1]
|
||||
if wrapper: return atClass.wrapperClass
|
||||
else: return atClass.wrapperClass.__bases__[-1]
|
||||
|
||||
def getCreateMeans(self, contentTypeOrAppyClass):
|
||||
'''Gets the different ways objects of p_contentTypeOrAppyClass (which
|
||||
|
@ -395,6 +391,8 @@ class ToolMixin(BaseMixin):
|
|||
'''This method checks if the currently logged user can trigger searches
|
||||
on a given p_rootClass. This is done by calling method "maySearch"
|
||||
on the class. If no such method exists, we return True.'''
|
||||
# When editign a form, one should avoid annoying the user with this.
|
||||
if self.REQUEST['ACTUAL_URL'].endswith('/edit'): return
|
||||
pythonClass = self.getAppyClass(rootClass)
|
||||
if 'maySearch' in pythonClass.__dict__:
|
||||
return pythonClass.maySearch(self.appy())
|
||||
|
|
|
@ -51,10 +51,7 @@ class BaseMixin:
|
|||
for appyType in self.getAppyTypes('edit', rq.get('page')):
|
||||
value = getattr(values, appyType.name, None)
|
||||
appyType.store(obj, value)
|
||||
if created:
|
||||
# Now we have a title for the object, so we derive a nice id
|
||||
obj.unmarkCreationFlag()
|
||||
obj._renameAfterCreation(check_auto_id=True)
|
||||
if created: obj.unmarkCreationFlag()
|
||||
if previousData:
|
||||
# Keep in history potential changes on historized fields
|
||||
self.historizeData(previousData)
|
||||
|
@ -499,7 +496,6 @@ class BaseMixin:
|
|||
'''Are we in debug mode ?'''
|
||||
for arg in sys.argv:
|
||||
if arg == 'debug-mode=on': return True
|
||||
return False
|
||||
|
||||
def getClass(self, reloaded=False):
|
||||
'''Returns the Appy class that dictates self's behaviour.'''
|
||||
|
@ -524,30 +520,34 @@ class BaseMixin:
|
|||
def getAppyType(self, name, asDict=False, className=None):
|
||||
'''Returns the Appy type named p_name. If no p_className is defined, the
|
||||
field is supposed to belong to self's class.'''
|
||||
className = className or self.__class__.__name__
|
||||
attrs = self.getProductConfig().attributesDict[className]
|
||||
appyType = attrs.get(name, None)
|
||||
if appyType and asDict: return appyType.__dict__
|
||||
return appyType
|
||||
if not className:
|
||||
klass = self.__class__.wrapperClass
|
||||
else:
|
||||
klass = self.getTool().getAppyClass(className, wrapper=True)
|
||||
res = getattr(klass, name, None)
|
||||
if res and asDict: return res.__dict__
|
||||
return res
|
||||
|
||||
def getAllAppyTypes(self, className=None):
|
||||
'''Returns the ordered list of all Appy types for self's class if
|
||||
p_className is not specified, or for p_className else.'''
|
||||
className = className or self.__class__.__name__
|
||||
return self.getProductConfig().attributes[className]
|
||||
if not className:
|
||||
klass = self.__class__.wrapperClass
|
||||
else:
|
||||
klass = self.getTool().getAppyClass(className, wrapper=True)
|
||||
return klass.__fields__
|
||||
|
||||
def getGroupedAppyTypes(self, layoutType, pageName):
|
||||
'''Returns the fields sorted by group. For every field, the appyType
|
||||
(dict version) is given.'''
|
||||
res = []
|
||||
groups = {} # The already encountered groups
|
||||
# In debug mode, reload the module containing self's class.
|
||||
debug = self.isDebug()
|
||||
if debug:
|
||||
# If param "refresh" is there, we must reload the Python class
|
||||
refresh = ('refresh' in self.REQUEST)
|
||||
if refresh:
|
||||
klass = self.getClass(reloaded=True)
|
||||
for appyType in self.getAllAppyTypes():
|
||||
if debug:
|
||||
appyType = appyType.reload(klass, self)
|
||||
if refresh: appyType = appyType.reload(klass, self)
|
||||
if appyType.page.name != pageName: continue
|
||||
if not appyType.isShowable(self, layoutType): continue
|
||||
if not appyType.group:
|
||||
|
@ -594,16 +594,17 @@ class BaseMixin:
|
|||
the result.'''
|
||||
res = []
|
||||
for name in fieldNames:
|
||||
appyType = self.getAppyType(name, asDict)
|
||||
if appyType: res.append(appyType)
|
||||
elif name == 'state':
|
||||
if name == 'state':
|
||||
# We do not return a appyType if the attribute is not a *real*
|
||||
# attribute, but the workfow state.
|
||||
res.append({'name': name, 'labelId': 'workflow_state',
|
||||
'filterable': False})
|
||||
else:
|
||||
self.appy().log('Field "%s", used as shownInfo in a Ref, ' \
|
||||
'was not found.' % name, type='warning')
|
||||
appyType = self.getAppyType(name, asDict)
|
||||
if appyType: res.append(appyType)
|
||||
else:
|
||||
self.appy().log('Field "%s", used as shownInfo in a Ref, ' \
|
||||
'was not found.' % name, type='warning')
|
||||
if addTitle and ('title' not in fieldNames):
|
||||
res.insert(0, self.getAppyType('title', asDict))
|
||||
return res
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue