From b39c5553eaad9d675cebf037402eb82db4d21671 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Tue, 9 Dec 2014 11:40:30 +0100 Subject: [PATCH] [shared] Improvements to the XmlMarshaller and bugfix: Mixin.xml returns appy.Object instances correctly marshalled. --- fields/pod.py | 4 +-- gen/mixins/__init__.py | 4 ++- shared/xml_parser.py | 60 ++++++++++++++++++------------------------ 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/fields/pod.py b/fields/pod.py index a1dc465..2f2e0c8 100644 --- a/fields/pod.py +++ b/fields/pod.py @@ -484,7 +484,7 @@ class Pod(Field): obj = obj.appy() template = template or self.template[0] format = format or 'odt' - # Security check. + # Security check if not noSecurity and not queryData: if self.showTemplate and not self.showTemplate(obj, template): raise Exception(self.UNAUTHORIZED) @@ -495,7 +495,7 @@ class Pod(Field): if frozen: fileName = self.getDownloadName(obj, template, format, False) return FileInfo(frozen, inDb=False, uploadName=fileName) - # We must call pod to compute a pod document from "template". + # We must call pod to compute a pod document from "template" tool = obj.tool diskFolder = tool.getDiskFolder() # Get the path to the pod template. diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index 416cbd5..af9121a 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -527,7 +527,9 @@ class BaseMixin: methodRes.startswith('' % partTag) elif hasattr(v, 'uploadName'): # The file is a Appy FileInfo instance. Read the file from disk. - filePath = v.getFilePath(self.instance) + if hasattr(self, 'instance'): + filePath = v.getFilePath(self.instance) + else: + filePath = v.fsPath f = file(filePath, 'rb') partNb = 1 while True: @@ -707,29 +706,22 @@ class XmlMarshaller: if fieldName == '_any': res.write(value) return - # Now, dump "normal" fields. + # Now, dump "normal" fields fieldTag = self.getTagName(fieldName) res.write('<'); res.write(fieldTag) # Dump the type of the field as an XML attribute - fType = None # No type will mean "unicode". - if fieldType == 'file': fType = 'file' - elif fieldType == 'ref': fType = 'list' - elif isinstance(fieldValue, bool): fType = 'bool' - elif isinstance(fieldValue, int): fType = 'int' - elif isinstance(fieldValue, float): fType = 'float' - elif isinstance(fieldValue, long): fType = 'long' - elif isinstance(fieldValue, tuple): fType = 'tuple' - elif self.isAList(fieldValue): fType = 'list' - elif self.isADict(fieldValue): fType = 'dict' - elif fieldValue.__class__.__name__ == 'DateTime': fType = 'DateTime' - elif self.isAnObject(fieldValue): fType = 'object' - if self.objectType != 'popo': - if fType: res.write(' type="%s"' % fType) - # Dump other attributes if needed - if fType in ('list', 'tuple'): - length = 0 - if fieldValue: length = len(fieldValue) - res.write(' count="%d"' % length) + fType = None # No type will mean "unicode" + className = fieldValue.__class__.__name__ + if fieldType == 'file': fType = 'file' + elif fieldType == 'ref': fType = 'list' + elif className in self.typesMap: fType = self.typesMap[className] + elif self.isAnObject(fieldValue): fType = 'object' + if fType: res.write(' type="%s"' % fType) + # Dump other attributes if needed + if fType in ('list', 'tuple'): + length = 0 + if fieldValue: length = len(fieldValue) + res.write(' count="%d"' % length) if fType == 'file': # Get the MIME type mimeType = None @@ -823,11 +815,9 @@ class XmlMarshaller: if field.name in self.fieldsToExclude: continue if (type(self.fieldsToMarshall) in sequenceTypes) \ 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.appy(), field.getValue(instance)) - self.dumpField(res, field.name, v, fieldType=fieldType) + self.dumpField(res, field.name, v) # Dump the object history if hasattr(instance.aq_base, 'workflow_history'): histTag = self.getTagName('history')