From 12836a40dcd8506781774f572357545f21cc4d17 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 9 Dec 2014 09:27:40 +0100 Subject: [PATCH] [gen] Ref field: param 'shownInfo' can now be a method. --- fields/file.py | 2 +- fields/ref.py | 36 +++++++++++++++++++++--------------- fields/string.py | 2 +- shared/xml_parser.py | 3 ++- 4 files changed, 25 insertions(+), 18 deletions(-) diff --git a/fields/file.py b/fields/file.py index a702266..53a6200 100644 --- a/fields/file.py +++ b/fields/file.py @@ -60,7 +60,7 @@ class FileInfo: getting the content of a Pod field, a temporary file may be generated and you will get a FileInfo that represents it. ''' - BYTES = 5000 + BYTES = 50000 def __init__(self, fsPath, inDb=True, uploadName=None): '''p_fsPath is the path of the file on disk. diff --git a/fields/ref.py b/fields/ref.py index 9dd7ccc..1468c65 100644 --- a/fields/ref.py +++ b/fields/ref.py @@ -250,7 +250,7 @@ class Ref(Field): + field.getAttribute(obj, 'shownInfo'), dir)">
@@ -397,7 +397,7 @@ class Ref(Field): # Simplified widget showing minimal info about tied objects. pxViewMinimal = Px(''' - :', '.join(infos) or _('no_ref')''') # PX that displays referred objects through this field. In mode link="list", @@ -465,7 +465,7 @@ class Ref(Field):
-
@@ -483,7 +483,7 @@ class Ref(Field): @@ -508,7 +508,7 @@ class Ref(Field): name=":widgetName" size=":field.sheight" multiple="multiple" onchange=":field.getOnChange(ztool, 'search', className)"> ''') @@ -518,7 +518,7 @@ class Ref(Field): unlinkElement=None, insert=None, beforeLink=None, afterLink=None, afterUnlink=None, back=None, show=True, page='main', group=None, layouts=None, showHeaders=False, - shownInfo=(), select=None, maxPerPage=30, move=0, + shownInfo=None, select=None, maxPerPage=30, move=0, indexed=False, searchable=False, specificReadPermission=False, specificWritePermission=False, width=None, height=5, maxChars=None, colspan=1, master=None, masterValue=None, @@ -616,10 +616,16 @@ class Ref(Field): # When displaying a tabular list of referenced objects, must we show # the table headers? self.showHeaders = showHeaders - # When displaying referenced object(s), we will display its title + all - # other fields whose names are listed in the following attribute. - self.shownInfo = list(shownInfo) - if not self.shownInfo: self.shownInfo.append('title') + # "shownInfo" is a tuple or list (or a method producing) containing + # the names of the fields that will be shown when displaying tables of + # tied objects. Field "title" should be present: by default it is a + # clickable link to the "view" page of every tied object. + if shownInfo == None: + self.shownInfo = ['title'] + elif isinstance(shownInfo, tuple): + self.shownInfo = list(shownInfo) + else: + self.shownInfo = shownInfo # If a method is defined in this field "select", it will be used to # return the list of possible tied objects. Be careful: this method can # receive, in its first argument ("self"), the tool instead of an @@ -1265,15 +1271,15 @@ class Ref(Field): obj.appy().create(self.name) xhtmlToText = re.compile('<.*?>', re.S) - def getReferenceLabel(self, refObject, unlimited=False): + def getReferenceLabel(self, obj, refObject, unlimited=False): '''p_self must have link=True. I need to display, on an edit view, the p_refObject in the listbox that will allow the user to choose which object(s) to link through the Ref. The information to display may - only be the object title or more if self.shownInfo is used.''' + only be the object title or more if "shownInfo" is used.''' res = '' - for fieldName in self.shownInfo: - refType = refObject.o.getAppyType(fieldName) - value = getattr(refObject, fieldName) + for name in self.getAttribute(obj, 'shownInfo'): + refType = refObject.o.getAppyType(name) + value = getattr(refObject, name) value = refType.getShownValue(refObject.o, value) if refType.type == 'String': if refType.format == 2: diff --git a/fields/string.py b/fields/string.py index a02f41d..8600fc0 100644 --- a/fields/string.py +++ b/fields/string.py @@ -911,7 +911,7 @@ class String(Field): from DateTime import DateTime obj.modified = DateTime() obj.reindex() - obj.log('Ajax-edited %s%s on %s.' % (self.name, part, obj.id)) + obj.log('ajax-edited %s%s on %s.' % (self.name, part, obj.id)) def getIndexType(self): '''Index type varies depending on String parameters.''' diff --git a/shared/xml_parser.py b/shared/xml_parser.py index 12010a7..9964910 100644 --- a/shared/xml_parser.py +++ b/shared/xml_parser.py @@ -825,7 +825,8 @@ class XmlMarshaller: and (field.name not in self.fieldsToMarshall): continue # Determine field type and value fieldType = (field.type == 'File') and 'file' or 'basic' - v = field.getXmlValue(instance, field.getValue(instance)) + v = field.getXmlValue(instance.appy(), + field.getValue(instance)) self.dumpField(res, field.name, v, fieldType=fieldType) # Dump the object history if hasattr(instance.aq_base, 'workflow_history'):