X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FSliceAttributeTypes.py;h=6aa4baa280195169b4fa64cacd0d487908f6e7e6;hb=e370bd35f31ff32bdd302bdb37add7f9aeff04bd;hp=a3ed881459061e107e901e8358a7e87ade04249e;hpb=0cde91a55d0148022ac83bc4219cdefc66a56510;p=plcapi.git diff --git a/PLC/SliceAttributeTypes.py b/PLC/SliceAttributeTypes.py index a3ed881..6aa4baa 100644 --- a/PLC/SliceAttributeTypes.py +++ b/PLC/SliceAttributeTypes.py @@ -22,19 +22,25 @@ class SliceAttributeType(Row): 'min_role_id': Parameter(int, "Minimum (least powerful) role that can set or change this attribute"), } + # for Cache + class_key = 'name' + foreign_fields = ['description','min_role_id'] + foreign_xrefs = [] + def validate_name(self, name): if not len(name): raise PLCInvalidArgument, "Slice attribute type name must be set" conflicts = SliceAttributeTypes(self.api, [name]) - for attribute_type_id, attribute in conflicts.iteritems(): - if 'attribute_type_id' not in self or self['attribute_type_id'] != attribute_type_id: + for attribute in conflicts: + if 'attribute_type_id' not in self or \ + self['attribute_type_id'] != attribute['attribute_type_id']: raise PLCInvalidArgument, "Slice attribute type name already in use" return name def validate_min_role_id(self, role_id): - roles = Roles(self.api) + roles = [row['role_id'] for row in Roles(self.api)] if role_id not in roles: raise PLCInvalidArgument, "Invalid role" @@ -46,14 +52,14 @@ class SliceAttributeTypes(Table): database. """ - def __init__(self, api, attribute_type_filter = None): - Table.__init__(self, api, SliceAttributeType) + def __init__(self, api, attribute_type_filter = None, columns = None): + Table.__init__(self, api, SliceAttributeType, columns) sql = "SELECT %s FROM slice_attribute_types WHERE True" % \ - ", ".join(SliceAttributeType.fields) + ", ".join(self.columns) if attribute_type_filter is not None: - if isinstance(attribute_type_filter, list): + if isinstance(attribute_type_filter, (list, tuple, set)): # Separate the list into integers and strings ints = filter(lambda x: isinstance(x, (int, long)), attribute_type_filter) strs = filter(lambda x: isinstance(x, StringTypes), attribute_type_filter)