Optimized performance while rendering references and computed fields and allowed computed fields to be shown asynchronously.

This commit is contained in:
Gaetan Delannay 2010-09-17 09:27:14 +02:00
parent 7d3ac9112b
commit 88cd4f7c46
6 changed files with 72 additions and 40 deletions

View file

@ -300,25 +300,14 @@ class AbstractMixin:
'''Returns the method named p_methodName.'''
return getattr(self, methodName, None)
def getFieldValue(self, name, useParamValue=False, value=None,
formatted=True):
'''Returns the value of field named p_name for this object (p_self).
def getFieldValue(self, name):
'''Returns the database value of field named p_name for p_self.'''
return self.getAppyType(name).getValue(self)
If p_useParamValue is True, the method uses p_value instead of the
real field value (useful for rendering a value from the object
history, for example).
If p_formatted is False, it will return the true database
(or default) value. Else, it will produce a nice, string and
potentially translated value.'''
appyType = self.getAppyType(name)
# Which value will we use ?
if not useParamValue:
value = appyType.getValue(self)
# Return the value as is if it is None or forMasterId
if not formatted: return value
# Return the formatted value else
return appyType.getFormattedValue(self, value)
def getFormattedFieldValue(self, name, value):
'''Gets a nice, string representation of p_value which is a value from
field named p_name.'''
return self.getAppyType(name).getFormattedValue(self, value)
def _appy_getRefs(self, fieldName, ploneObjects=False,
noListIfSingleObj=False, startNumber=None):

View file

@ -22,7 +22,7 @@ class ModelClass:
_appy_notinit = ('id', 'type', 'pythonType', 'slaves', 'phase', 'pageShow',
'isSelect', 'hasLabel', 'hasDescr', 'hasHelp',
'master_css', 'layouts', 'required', 'filterable',
'validable', 'backd', 'isBack')
'validable', 'backd', 'isBack', 'sync')
@classmethod
def _appy_addField(klass, fieldName, fieldType, classDescr):

View file

@ -157,6 +157,12 @@
}
askAjaxChunk(hookId, 'GET', objectUrl, 'widgets/ref', 'viewContent',params);
}
function askComputedField(hookId, objectUrl, fieldName) {
// Sends an Ajax request for getting the content of a computed field
var params = {'fieldName': fieldName};
askAjaxChunk(hookId, 'GET', objectUrl, 'widgets/computed', 'viewContent',
params);
}
// Function used by checkbox widgets for having radio-button-like behaviour
function toggleCheckbox(visibleCheckbox, hiddenBoolean) {
@ -455,7 +461,7 @@
</tr>
<tr tal:repeat="change event/changes/items" valign="top">
<td tal:content="python: tool.translate(change[1][1])"></td>
<td tal:define="appyValue python: contextObj.getFieldValue(change[0], useParamValue=True, value=change[1][0]);
<td tal:define="appyValue python: contextObj.getFormattedFieldValue(change[0], change[1][0]);
appyType python:contextObj.getAppyType(change[0], asDict=True);
severalValues python: (appyType['multiplicity'][1] &gt; 1) or (appyType['multiplicity'][1] == None)">
<span tal:condition="not: severalValues" tal:replace="appyValue"></span>

View file

@ -1,7 +1,26 @@
<tal:comment replace="nothing">View macro for a Computed.</tal:comment>
<metal:view define-macro="view">
<span tal:condition="widget/plainText" tal:replace="value"/>
<span tal:condition="not: widget/plainText" tal:replace="structure value"/>
<tal:sync condition="sync">
<span tal:condition="widget/plainText" tal:replace="value"/>
<span tal:condition="not: widget/plainText" tal:replace="structure value"/>
</tal:sync>
<tal:async condition="not: sync">
<div tal:define= "ajaxHookId python: contextObj.UID() + name"
tal:attributes = "id ajaxHookId">
<script language="javascript"
tal:content="python: 'askComputedField(\'%s\',\'%s\',\'%s\')' % (ajaxHookId, contextObj.absolute_url(), name)">
</script>
</div>
</tal:async>
</metal:view>
<tal:comment replace="nothing">Ajax-called view content of a non sync Computed field.</tal:comment>
<metal:view define-macro="viewContent"
tal:define="name request/fieldName;
widget python: contextObj.getAppyType(name, asDict=True);
value python: contextObj.getFieldValue(name);
sync python:True">
<metal:call use-macro="portal/skyn/widgets/computed/macros/view"/>
</metal:view>
<tal:comment replace="nothing">Edit macro for a Computed.</tal:comment>

View file

@ -54,8 +54,9 @@
tal:define="contextMacro python: portal.skyn.widgets;
layout python: widget['layouts'][layoutType];
name widget/name;
value python: contextObj.getFieldValue(name);
rawValue python: contextObj.getFieldValue(name, formatted=False);
sync python: widget['sync'][layoutType];
rawValue python: sync and contextObj.getFieldValue(name) or None;
value python: sync and contextObj.getFormattedFieldValue(name, rawValue) or None;
requestValue python: request.get(name, None);
inRequest python: request.has_key(name);
errors errors | python: ();