optionnally import id of fields to xml, this is used for user fields

(really) fix #214 http://dev.entrouvert.org/issues/214
This commit is contained in:
Thomas NOËL 2011-08-02 15:59:51 +00:00
parent 43ade21318
commit b3eff836a3
3 changed files with 9 additions and 4 deletions

View File

@ -152,7 +152,7 @@ class UserFieldsFormDef(FormDef):
except:
pass
else:
obj = FormDef.import_from_xml_tree(tree)
obj = FormDef.import_from_xml_tree(tree, include_id=True)
self.fields = obj.fields
else:
# compatibility with older location

View File

@ -158,7 +158,7 @@ class Field:
el.text = str(val)
return field
def init_with_xml(self, elem, charset):
def init_with_xml(self, elem, charset, include_id=False):
for attribute in self.get_admin_attributes():
el = elem.find(attribute)
if el is None:
@ -185,6 +185,11 @@ class Field:
setattr(self, attribute, int(el.text.encode(charset)))
else:
setattr(self, attribute, el.text.encode(charset))
if include_id:
try:
self.id = elem.find('id').text.encode(charset)
except:
pass
def get_rst_view_value(self, value, indent=''):
return indent + self.get_view_value(value)

View File

@ -357,7 +357,7 @@ class FormDef(StorableObject):
return cls.import_from_xml_tree(tree)
import_from_xml = classmethod(import_from_xml)
def import_from_xml_tree(cls, tree):
def import_from_xml_tree(cls, tree, include_id=False):
charset = get_publisher().site_charset
formdef = cls()
if tree.find('name') is None or not tree.find('name').text:
@ -370,7 +370,7 @@ class FormDef(StorableObject):
field_o = fields.get_field_class_by_type(field.findtext('type'))()
except KeyError:
raise ValueError()
field_o.init_with_xml(field, charset)
field_o.init_with_xml(field, charset, include_id=include_id)
if not field_o.id:
# this assumes all fields will have id, or none of them
field_o.id = str(i)