optionnally export id of fields to xml, this is used for user fields (#214)
This commit is contained in:
parent
d5cee39c2d
commit
ab79f9572d
|
@ -171,7 +171,7 @@ class UserFieldsFormDef(FormDef):
|
|||
def store(self):
|
||||
xml_export = self.export_to_xml()
|
||||
users_cfg = get_cfg('users', {})
|
||||
users_cfg['formdef'] = ET.tostring(xml_export)
|
||||
users_cfg['formdef'] = ET.tostring(xml_export, include_id=True)
|
||||
get_publisher().cfg['users'] = users_cfg
|
||||
get_publisher().write_cfg()
|
||||
|
||||
|
|
|
@ -126,9 +126,13 @@ class Field:
|
|||
def get_admin_attributes(self):
|
||||
return ['label', 'type']
|
||||
|
||||
def export_to_xml(self, charset):
|
||||
def export_to_xml(self, charset, include_id=False):
|
||||
field = ET.Element('field')
|
||||
for attribute in self.get_admin_attributes():
|
||||
if include_id:
|
||||
extra_fields = ['id']
|
||||
else:
|
||||
extra_fields = []
|
||||
for attribute in self.get_admin_attributes() + extra_fields:
|
||||
if hasattr(self, attribute) and getattr(self, attribute) is not None:
|
||||
el = ET.SubElement(field, attribute)
|
||||
val = getattr(self, attribute)
|
||||
|
|
|
@ -370,7 +370,9 @@ class FormDef(StorableObject):
|
|||
except KeyError:
|
||||
raise ValueError()
|
||||
field_o.init_with_xml(field, charset)
|
||||
field_o.id = str(i)
|
||||
if not field_o.id:
|
||||
# this assumes all fields will have id, or none of them
|
||||
field_o.id = str(i)
|
||||
formdef.fields.append(field_o)
|
||||
if tree.find('category') is not None:
|
||||
category = tree.find('category').text.encode(charset)
|
||||
|
|
Loading…
Reference in New Issue