def __init__(self, id, value=None, **kwargs): Item.__init__(self, id, **kwargs) default = None editable = True data_type = None null_ok = False attrs = getattr(type(self), "__item_attributes__") if attrs.has_key("default"): default = attrs["default"] if attrs.has_key("editable"): editable = attrs["editable"] if attrs.has_key("data_type"): data_type = attrs["data_type"] if attrs.has_key("null_ok"): null_ok = attrs["null_ok"] elif default is None: null_ok = True self.__default = default self.__value = default self.__editable = editable self.__data_type = data_type self.__null_ok = null_ok if value is None: self.reset() else: self.set_value(value)
def __init__(self, id, value=None, **kwargs): Item.__init__(self, id, **kwargs) default = None editable = True data_type = None null_ok = False attrs = getattr(type(self), '__item_attributes__') if attrs.has_key('default'): default = attrs['default'] if attrs.has_key('editable'): editable = attrs['editable'] if attrs.has_key('data_type'): data_type = attrs['data_type'] if attrs.has_key('null_ok'): null_ok = attrs['null_ok'] elif default is None: null_ok = True self.__default = default self.__value = default self.__editable = editable self.__data_type = data_type self.__null_ok = null_ok if value is None: self.reset() else: self.set_value(value)
def __setattr__(self, name, value): if name.startswith('_'): Item.__setattr__(self, name, value) else: dic = self.__items_dict if dic.has_key(name): dic[name].set_value(value) else: Item.__setattr__(self, name, value)
def __init__(self, id, items={}, not_set=False, **kwargs): Item.__init__(self, id, **kwargs) self.__items = [] self.__items_dict = {} self.__not_set = not_set if items: for id in items: self.add_item(items[id], id) if hasattr(type(self), '__items__'): items = getattr(type(self), '__items__') for id in items: self.add_item(items[id], id)
def __init__(self, *args, **kwargs): Item.__init__(self, *args, **kwargs) self.__items = {} attrs = getattr(type(self), '__item_attributes__') if attrs.has_key('xml_elm_name'): self.__xml_elm_name = attrs['xml_elm_name'] else: self.__xml_elm_name = None if self.__xml_elm_name is not None: if attrs.has_key('xml_attr_name'): self.__xml_attr_name = attrs['xml_attr_name'] else: self.__xml_attr_name = 'name'
def copy_from(self, other): changed = Item.copy_from(self, other) first, common, second = dict_diff(self.__items_dict, other.__items_dict) if first or second: changed = True for id in first: self.remove_item(id) for id in common: changed = self[id].copy_from(other[id]) or changed for id in second: self.add_item(other[id].copy()) return changed
def copy_from(self, other): changed = Item.copy_from(self, other) first, common, second = dict_diff(self.__items, other.__items) if first or second: changed = True for key in first: del self[key] for key in second: self[key] = _copy_instance(other.__items[key]) if issubclass(Dict.__elm_type__, Item): for key in common: changed = self.__items[key].copy_from(other.__items[key]) or changed else: for key in common: old = self.__items[key] new = other.__items[key] if old != new: self.__items[key] = new changed = True return changed
def copy_from(self, other): changed = Item.copy_from(self, other) return self.set_value(other.get_value()) or changed