def serialize_field(f, depth=2): """(f:Field) -> [str] """ _acc = [] field_localizable_modes = [] for loc in f.localizable: _acc.extend(serialize_loc(loc, depth+1, field_localizable_modes)) localizable_modes = " ".join( norm_sorted(field_localizable_modes, Field._modes)) display_modes = " ".join(f.modes) acc = [] ind = INDENT * depth if _acc: if localizable_modes: acc.append('%s<field name="%s" modes="%s" localizable="%s">' % ( ind, f.name, display_modes, localizable_modes)) else: acc.append('%s<field name="%s" modes="%s">' % ( ind, f.name, display_modes)) acc.extend(_acc) acc.append('%s</field>' % (ind)) else: if localizable_modes: acc.append('%s<field name="%s" modes="%s" localizable="%s" />' % ( ind, f.name, display_modes, localizable_modes)) else: acc.append('%s<field name="%s" modes="%s" />' % ( ind, f.name, display_modes)) return acc
def serialize_field(f, depth=2): """(f:Field) -> [str] """ _acc = [] field_localizable_modes = [] # @modes display_modes = " ".join(f.modes) if hasattr(f, "_SERIALIZE_modes"): display_modes = " ".join(f._SERIALIZE_modes) del f._SERIALIZE_modes # @localizable for loc in f.localizable: _acc.extend(serialize_loc(loc, depth + 1, field_localizable_modes)) localizable_modes = " ".join( norm_sorted(field_localizable_modes, Field._modes)) if hasattr(f, "_SERIALIZE_localizable_modes"): localizable_modes = " ".join( norm_sorted(f._SERIALIZE_localizable_modes, Field._modes)) del f._SERIALIZE_localizable_modes acc = [] ind = INDENT * depth if _acc: if localizable_modes: acc.append( '%s<field name="%s" displayable="%s" localizable="%s">' % (ind, f.name, display_modes, localizable_modes)) else: acc.append('%s<field name="%s" displayable="%s">' % (ind, f.name, display_modes)) acc.extend(_acc) acc.append('%s</field>' % (ind)) else: if localizable_modes: acc.append( '%s<field name="%s" displayable="%s" localizable="%s" />' % (ind, f.name, display_modes, localizable_modes)) else: acc.append('%s<field name="%s" displayable="%s" />' % (ind, f.name, display_modes)) return acc
def serialize_field(f, depth=2): """(f:Field) -> [str] """ _acc = [] field_localizable_modes = [] # @modes display_modes = " ".join(f.modes) if hasattr(f, "_SERIALIZE_modes"): display_modes = " ".join(f._SERIALIZE_modes) del f._SERIALIZE_modes # @localizable for loc in f.localizable: _acc.extend(serialize_loc(loc, depth+1, field_localizable_modes)) localizable_modes = " ".join( norm_sorted(field_localizable_modes, Field._modes)) if hasattr(f, "_SERIALIZE_localizable_modes"): localizable_modes = " ".join( norm_sorted(f._SERIALIZE_localizable_modes, Field._modes)) del f._SERIALIZE_localizable_modes acc = [] ind = INDENT * depth if _acc: if localizable_modes: acc.append('%s<field name="%s" displayable="%s" localizable="%s">' % ( ind, f.name, display_modes, localizable_modes)) else: acc.append('%s<field name="%s" displayable="%s">' % ( ind, f.name, display_modes)) acc.extend(_acc) acc.append('%s</field>' % (ind)) else: if localizable_modes: acc.append('%s<field name="%s" displayable="%s" localizable="%s" />' % ( ind, f.name, display_modes, localizable_modes)) else: acc.append('%s<field name="%s" displayable="%s" />' % ( ind, f.name, display_modes)) return acc