def set(self, instance, value, **kw):  
ref = []<EOL>if api.is_uid(value):<EOL><INDENT>ref.append(api.get_object_by_uid(value))<EOL><DEDENT>if api.is_at_content(value):<EOL><INDENT>ref.append(value)<EOL><DEDENT>if u.is_dict(value):<EOL><INDENT>results = api.search(portal_type=self.allowed_types, **value)<EOL>ref = map(api.get_object, results)<EOL><DEDENT>if u.is_list(value):<EOL><INDENT>for item in value:<EOL><INDENT>if api.is_uid(item):<EOL><INDENT>ref.append(api.get_object_by_uid(item))<EOL>continue<EOL><DEDENT>if api.is_at_content(item):<EOL><INDENT>ref.append(api.get_object(item))<EOL>continue<EOL><DEDENT>if api.is_path(item):<EOL><INDENT>ref.append(api.get_object_by_path(item))<EOL>continue<EOL><DEDENT>if u.is_dict(item):<EOL><INDENT>uid = item.get('<STR_LIT>', None)<EOL>if uid:<EOL><INDENT>obj = api.get_object_by_uid(uid)<EOL>ref.append(obj)<EOL><DEDENT>else:<EOL><INDENT>results = api.search(portal_type=self.allowed_types, **item)<EOL>objs = map(api.get_object, results)<EOL>ref.extend(objs)<EOL><DEDENT>continue<EOL><DEDENT>if isinstance(item, basestring):<EOL><INDENT>results = api.search(portal_type=self.allowed_types, title=item)<EOL>objs = map(api.get_object, results)<EOL>ref.extend(objs)<EOL>continue<EOL><DEDENT><DEDENT><DEDENT>if api.is_path(value):<EOL><INDENT>ref.append(api.get_object_by_path(value))<EOL><DEDENT>if not self.multi_valued:<EOL><INDENT>if len(ref) > <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>".format(repr(self.field)))<EOL><DEDENT>else:<EOL><INDENT>ref = ref[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>return self._set(instance, ref, **kw)<EOL>
Set the value of the refernce field