Index: quintagroup.transmogrifier.pfm2pfg/trunk/quintagroup/transmogrifier/pfm2pfg/importing.py
===================================================================
--- quintagroup.transmogrifier.pfm2pfg/trunk/quintagroup/transmogrifier/pfm2pfg/importing.py	(revision 323)
+++ quintagroup.transmogrifier.pfm2pfg/trunk/quintagroup/transmogrifier/pfm2pfg/importing.py	(revision 329)
@@ -17,13 +17,4 @@
 from quintagroup.transmogrifier.adapters.importing import ReferenceImporter
 from quintagroup.transmogrifier.xslt import XSLTSection
-
-def debug(obj, good=True):
-    type_name = obj.getPortalTypeName()
-    path = os.path.join(*obj.getPhysicalPath()[1:])
-    msg = 'type=%s, path=%s' % (type_name, path) 
-    if good:
-        logging.getLogger('pfm2pfg').info(msg)
-    else:
-        logging.getLogger('pfm2pfg').warning(msg)
 
 BOOL_FIELD_PROPS = ['enabled', 'required', 'hidden']
@@ -71,5 +62,6 @@
         self.context = context
         self.demarshaller = getComponent("atxml")
-        self.auto_added_fields = ['replyto', 'topic', 'comments']
+        self.auto_added_fgfields = ['replyto', 'topic', 'comments']
+        self.date_fields = {}
 
     def __call__(self, data):
@@ -77,5 +69,5 @@
         xml = data['data']
 
-        data['data'] = self.updateFormFolder(xml)
+        data['data'] = self.transformWithMinidom(xml)
 
         # update FormMailerAdapter and FormThanksPage objects
@@ -88,9 +80,15 @@
         return data
 
-    def updateFormFolder(self, xml):
+    def transformWithMinidom(self, xml):
         """ Do some extra transformations on xml document (that can be done by XSLT).
         """
         doc = minidom.parseString(xml)
         root = doc.documentElement
+
+        # get 'modification_date' and 'creation_date' for next usage when creating fields
+        for i in root.getElementsByTagName('xmp:CreateDate'):
+            self.date_fields['creation_date'] = i.firstChild.nodeValue.strip()
+        for i in root.getElementsByTagName('xmp:ModifyDate'):
+            self.date_fields['modification_date'] = i.firstChild.nodeValue.strip()
 
         # xxx: update button labels (those elements are now skiped by xslt)
@@ -136,21 +134,19 @@
     def updateMailer(self, xml):
         mailer = self.context['mailer']
-        transformed = self.transform(xml, 'FormMailerAdapter')
+        transformed = self.transformWithXSLT(xml, 'FormMailerAdapter')
         self.demarshaller.demarshall(mailer, transformed)
         mailer.indexObject()
-        debug(mailer)
         return transformed
 
     def updateResponsePage(self, xml):
         page = self.context['thank-you']
-        transformed = self.transform(xml, 'FormThanksPage')
+        transformed = self.transformWithXSLT(xml, 'FormThanksPage')
         self.demarshaller.demarshall(page, transformed)
         # override default value of description field
         page.getField('description').getMutator(page)('')
         page.indexObject()
-        debug(page)
         return transformed
 
-    def transform(self, xml, to):
+    def transformWithXSLT(self, xml, to):
         """ Apply XSLT transformations using XSLT transmogrifier section.
         """
@@ -172,8 +168,6 @@
         """ Walk trough xml tree and create fields in FormFolder.
         """
-        # get id of form folder for logging purposes
-        self.form_id = self.context.getId()
         # delete fields that were added on FormFolder creation
-        for oid in [i for i in self.auto_added_fields if i in self.context]:
+        for oid in [i for i in self.auto_added_fgfields if i in self.context]:
             self.context._delObject(oid)
 
@@ -206,12 +200,5 @@
             Use demarshalling adapter.
         """
-        # create path to field for logging
-        if context is self.context:
-            path = "%s/%s" % (self.form_id, field_id)
-        else:
-            path = "%s/%s/%s" % (self.form_id, context.getId(), field_id)
-
         if FIELD_MAP.get(type_name) is None:
-            debug(type_name, False)
             return
 
@@ -220,4 +207,7 @@
         else:
             type_name, options = FIELD_MAP[type_name], {}
+        # update options with 'creation_date' and 'modification_date', that are
+        # the same as in FormFolder (dates on fields must be the same)
+        options.update(self.date_fields)
 
         if field_id not in context.contentIds():
@@ -227,7 +217,5 @@
                 raise
             except:
-                debug('%s %s' % (type_name, field_id), False)
                 return
-            debug(field)
         else:
             field = context._getOb(field_id)
@@ -235,9 +223,8 @@
         try:
             IXMLDemarshaller(field).demarshall(field_node, **options)
-            debug(field)
         except ConflictError:
             raise
-        except:
-            debug("on updating %s %s" % (type_name, field_id), False)
+        except Exception, e:
+            return
 
     def createFieldset(self, title):
@@ -250,7 +237,5 @@
                 raise
             except:
-                debug('FieldsetFolder with id="%s"' % title, False)
                 return
-            debug(fieldset)
         else:
             fieldset = self.context._getOb(title)
@@ -266,9 +251,8 @@
     def __init__(self, context):
         self.context = context
-        self.date_fields = ['creation_date', 'modification_date']
 
     def demarshall(self, node, **kw):
         self.extractData(node)
-        # update data dictionary form extra arguments
+        # update data dictionary form keyword arguments
         for k, v in kw.items():
             self.data[k] = v
@@ -285,10 +269,4 @@
                 continue
             mutator(value)
-
-        # set creation and modification date equal to dates in form folder
-        form_folder = aq_parent(aq_inner(self.context))
-        for field in self.date_fields:
-            value = form_folder.getField(field).getAccessor(form_folder)()
-            self.context.getField(field).getMutator(self.context)(value)
 
         self.context.indexObject()
@@ -318,4 +296,10 @@
                 data[name] = str(value.text)
 
+        # get tales expressions
+        tales = tree.first.field.first.tales
+        for name in tales.getElementNames():
+            value = getattr(tales.first, name)
+            data["tales:"+name] = str(value.text)
+
         self.data = data
 
@@ -327,4 +311,15 @@
             self.data[new] = self.data.pop(old)
 
+    def entryIsDigit(self, key):
+        """ Formulator exports empty fields in xml as empty elements without
+            'type' attribute. That's is why we get in data dictionary for 
+            integer fields values that are empty strings. This method is 
+            used to check whether integer field has integer value.
+        """
+        if key in self.data and isinstance(self.data[key], int):
+            return True
+        else:
+            return False
+
 class StringFieldDemarshaller(BaseFieldDemarshaller):
     """ Demarshaller of StringField and other fields of this kind.
@@ -333,6 +328,8 @@
     def modifyData(self):
         self.renameEntry('default', 'fgDefault')
-        self.renameEntry('max_length', 'fgmaxlength')
-        self.renameEntry('display_width', 'fgsize')
+        if self.entryIsDigit('display_maxwidth'):
+            self.renameEntry('display_maxwidth', 'fgmaxlength')
+        if self.entryIsDigit('display_width'):
+            self.renameEntry('display_width', 'fgsize')
 
 class TextFieldDemarshaller(BaseFieldDemarshaller):
@@ -342,6 +339,8 @@
     def modifyData(self):
         self.renameEntry('default', 'fgDefault')
-        self.renameEntry('max_length', 'fgmaxlength')
-        self.renameEntry('height', 'fgRows')
+        if self.entryIsDigit('max_length'):
+            self.renameEntry('max_length', 'fgmaxlength')
+        if self.entryIsDigit('height'):
+            self.renameEntry('height', 'fgRows')
 
 class LabelFieldDemarshaller(BaseFieldDemarshaller):
@@ -352,12 +351,18 @@
         self.renameEntry('default', 'fgDefault')
 
-class IntegerFieldDemarshaller(StringFieldDemarshaller):
+class IntegerFieldDemarshaller(BaseFieldDemarshaller):
     """ Demarshaller of IntegerField.
     """
 
     def modifyData(self):
-        super(IntegerFieldDemarshaller, self).modifyData()
-        self.renameEntry('start', 'minval')
-        self.renameEntry('end', 'maxval')
+        self.renameEntry('default', 'fgDefault')
+        if self.entryIsDigit('display_maxwidth'):
+            self.renameEntry('display_maxwidth', 'fgmaxlength')
+        if self.entryIsDigit('display_width'):
+            self.renameEntry('display_width', 'fgsize')
+        if self.entryIsDigit('start'):
+            self.renameEntry('start', 'minval')
+        if self.entryIsDigit('end'):
+            self.renameEntry('end', 'maxval')
 
 class DateTimeFieldDemarshaller(BaseFieldDemarshaller):
@@ -373,5 +378,4 @@
         # date_only is boolean flag
         self.data['fgShowHM'] = not bool(self.data['date_only'])
-        del self.data['date_only']
         if 'start_datetime' in self.data:
             self.data['start_datetime'] = self.data['start_datetime'].year()
@@ -387,5 +391,6 @@
     def modifyData(self):
         self.renameEntry('default', 'fgDefault')
-        self.renameEntry('height', 'fgRows')
+        if self.entryIsDigit('height'):
+            self.renameEntry('height', 'fgRows')
 
 class BooleanFieldDemarshaller(BaseFieldDemarshaller):
@@ -404,8 +409,13 @@
     def modifyData(self):
         self.renameEntry('default', 'fgDefault')
-        self.data['items'] = ['|'.join(i) for i in self.data['items']]
+        l = []
+        for i in self.data['items']:
+            i = list(i)
+            i.reverse()
+            l.append(i)
+        self.data['items'] = ['|'.join(i) for i in l]
         self.renameEntry('items', 'fgVocabulary')
 
-class MultiSelectFieldDemarshaller(LinesFieldDemarshaller):
+class MultiSelectFieldDemarshaller(SelectionFieldDemarshaller):
     """ Demarshaller of MultiSelectField.
     """
@@ -413,6 +423,6 @@
     def modifyData(self):
         super(MultiSelectFieldDemarshaller, self).modifyData()
-        self.data['items'] = ['|'.join(i) for i in self.data['items']]
-        self.renameEntry('items', 'fgVocabulary')
+        if self.entryIsDigit('size'):
+            self.renameEntry('size', 'fgRows')
 
 
