def read(self, fields=None, load='_classic_read'): """ Re-write to process dummy groups fields 1. determine required group fields 2. read regular fields and add group_ids if necessary 3. add reified group fields Methods: * fields_get * is_reified_group * super of read * _add_reified_groups """ print('Read') # 1 fields1 = fields or list(self.fields_get()) group_fields, other_fields = partition(is_reified_group, fields1) # 2 drop_group_ids = False if group_fields and fields: if 'group_ids' not in other_fields: other_fields.append('group_ids') drop_group_ids = True else: other_fields = fields res = super(security_role, self).read(other_fields, load=load) # 3 if group_fields: for values in res: self._add_reified_groups(group_fields, values) if drop_group_ids: values.pop('group_ids', None) return res
def default_get(self, fields): """ Re-write Methods: * is_reified_group * super of default_get * _add_reified_groups """ group_fields, fields = partition(is_reified_group, fields) fields1 = (fields + ['group_ids']) if group_fields else fields values = super(security_role, self).default_get(fields1) self._add_reified_groups(group_fields, values) return values
def read(self, fields=None, load='_classic_read'): # determine whether reified groups fields are required, and which ones fields1 = fields or self.fields_get().keys() group_fields, other_fields = partition(is_reified_group, fields1) # read regular fields (other_fields); add 'groups_id' if necessary drop_groups_id = False if group_fields and fields: if 'groups_id' not in other_fields: other_fields.append('groups_id') drop_groups_id = True else: other_fields = fields res = super(UsersView, self).read(other_fields, load=load) # post-process result to add reified group fields if group_fields: for values in res: self._add_reified_groups(group_fields, values) if drop_groups_id: values.pop('groups_id', None) return res
def default_get(self, fields): group_fields, fields = partition(is_reified_group, fields) fields1 = (fields + ['groups_id']) if group_fields else fields values = super(UsersView, self).default_get(fields1) self._add_reified_groups(group_fields, values) return values