Added method 'unlink' on any appy class, for unlinking objects from references. Bugfixes in display of workflow state in columns.

This commit is contained in:
Gaetan Delannay 2011-01-19 20:51:43 +01:00
parent defdc08dce
commit 38f71be89a
4 changed files with 34 additions and 9 deletions

View file

@ -482,7 +482,7 @@ class ToolMixin(BaseMixin):
(p_usage can be "ref" or "search")?''' (p_usage can be "ref" or "search")?'''
if (',' in className) or (name == 'workflowState'): return False if (',' in className) or (name == 'workflowState'): return False
appyType = self.getAppyType(name, className=className) appyType = self.getAppyType(name, className=className)
return appyType.isSortable(usage=usage) if appyType: return appyType.isSortable(usage=usage)
def _searchValueIsEmpty(self, key): def _searchValueIsEmpty(self, key):
'''Returns True if request value in key p_key can be considered as '''Returns True if request value in key p_key can be considered as

View file

@ -509,7 +509,7 @@ class BaseMixin:
for name in fieldNames: for name in fieldNames:
appyType = self.getAppyType(name, asDict) appyType = self.getAppyType(name, asDict)
if appyType: res.append(appyType) if appyType: res.append(appyType)
elif name == 'workflowState': elif name == 'state':
# We do not return a appyType if the attribute is not a *real* # We do not return a appyType if the attribute is not a *real*
# attribute, but the workfow state. # attribute, but the workfow state.
res.append({'name': name, 'labelId': 'workflow_state', res.append({'name': name, 'labelId': 'workflow_state',
@ -1044,7 +1044,7 @@ class BaseMixin:
params = '' params = ''
return '%s%s' % (base, params) return '%s%s' % (base, params)
def getLanguage(self): def getUserLanguage(self):
'''Gets the language (code) of the current user.''' '''Gets the language (code) of the current user.'''
# Try first the "LANGUAGE" key from the request # Try first the "LANGUAGE" key from the request
res = self.REQUEST.get('LANGUAGE', None) res = self.REQUEST.get('LANGUAGE', None)
@ -1076,7 +1076,7 @@ class BaseMixin:
else: else:
# We will get the translation from a Translation object. # We will get the translation from a Translation object.
# In what language must we get the translation? # In what language must we get the translation?
if not language: language = self.getLanguage() if not language: language = self.getUserLanguage()
tool = self.getTool() tool = self.getTool()
try: try:
translation = getattr(tool, language).appy() translation = getattr(tool, language).appy()

View file

@ -78,7 +78,8 @@
ref field according to the field that corresponds to this column. ref field according to the field that corresponds to this column.
</tal:comment> </tal:comment>
<metal:sortIcons define-macro="sortIcons" <metal:sortIcons define-macro="sortIcons"
tal:define="ajaxBaseCall python: navBaseCall.replace('**v**', '\'%s\',\'SortReference\', {\'sortKey\':\'%s\', \'reverse\':\'**v**\'}' % (startNumber, widget['name']))" tal:condition="python: canWrite and tool.isSortable(widget['name'], objs[0].meta_type, 'ref')"> tal:define="ajaxBaseCall python: navBaseCall.replace('**v**', '\'%s\',\'SortReference\', {\'sortKey\':\'%s\', \'reverse\':\'**v**\'}' % (startNumber, widget['name']))"
tal:condition="python: canWrite and tool.isSortable(widget['name'], objs[0].meta_type, 'ref')">
<img style="cursor:pointer" <img style="cursor:pointer"
tal:attributes="src string:$portal_url/skyn/sortAsc.png; tal:attributes="src string:$portal_url/skyn/sortAsc.png;
onClick python: ajaxBaseCall.replace('**v**', 'False')"/> onClick python: ajaxBaseCall.replace('**v**', 'False')"/>
@ -198,10 +199,10 @@
<tal:title condition="python: widget['name'] == 'title'"> <tal:title condition="python: widget['name'] == 'title'">
<metal:showObjectTitle use-macro="portal/skyn/widgets/ref/macros/objectTitle"/> <metal:showObjectTitle use-macro="portal/skyn/widgets/ref/macros/objectTitle"/>
</tal:title> </tal:title>
<tal:state condition="python: widget['name'] == 'workflowState'" <tal:state condition="python: widget['name'] == 'state'"
content="python: tool.translate(obj.getWorkflowLabel())"> content="python: tool.translate(obj.getWorkflowLabel())">
</tal:state> </tal:state>
<tal:other condition="python: widget['name'] not in ('title', 'workflowState')"> <tal:other condition="python: widget['name'] not in ('title', 'state')">
<tal:field define="contextObj python:obj; <tal:field define="contextObj python:obj;
layoutType python: 'cell'; layoutType python: 'cell';
innerRef python:True"> innerRef python:True">

View file

@ -89,8 +89,8 @@ class AbstractWrapper:
fields = property(get_fields) fields = property(get_fields)
def link(self, fieldName, obj): def link(self, fieldName, obj):
'''This method links p_obj to this one through reference field '''This method links p_obj (which can be a list of objects) to this one
p_fieldName. p_obj can also be a list or tuple of objects.''' through reference field p_fieldName.'''
postfix = 'et%s%s' % (fieldName[0].upper(), fieldName[1:]) postfix = 'et%s%s' % (fieldName[0].upper(), fieldName[1:])
# Update the Archetypes reference field # Update the Archetypes reference field
exec 'objs = self.o.g%s()' % postfix exec 'objs = self.o.g%s()' % postfix
@ -111,6 +111,30 @@ class AbstractWrapper:
else: else:
sorted.append(obj.o.UID()) sorted.append(obj.o.UID())
def unlink(self, fieldName, obj):
'''This method unlinks p_obj (which can be a list of objects) from this
one through reference field p_fieldName.'''
postfix = 'et%s%s' % (fieldName[0].upper(), fieldName[1:])
# Update the Archetypes reference field.
exec 'objs = self.o.g%s()' % postfix
if not objs: return
# Remove p_obj from existing objects
if type(obj) in sequenceTypes:
for o in obj:
if o.o in objs: objs.remove(o.o)
else:
if obj.o in objs: objs.remove(obj.o)
exec 'self.o.s%s(objs)' % postfix
# Update the ordered list of references
sorted = self.o._appy_getSortedField(fieldName)
if type(obj) in sequenceTypes:
for o in obj:
if o.o.UID() in sorted:
sorted.remove(o.o.UID())
else:
if obj.o.UID() in sorted:
sorted.remove(obj.o.UID())
def sort(self, fieldName, sortKey='title', reverse=False): def sort(self, fieldName, sortKey='title', reverse=False):
'''Sorts referred elements linked to p_self via p_fieldName according '''Sorts referred elements linked to p_self via p_fieldName according
to a given p_sortKey which must be an attribute set on referred to a given p_sortKey which must be an attribute set on referred