def set(self, instance, value, **kw):  
ref = []<EOL>if api.is_uid(value):<EOL><INDENT>ref.append(value)<EOL><DEDENT>if u.is_dict(value):<EOL><INDENT>ref = ref.append(value.get("<STR_LIT>"))<EOL><DEDENT>if api.is_at_content(value):<EOL><INDENT>ref.append(value)<EOL><DEDENT>if u.is_list(value):<EOL><INDENT>for item in value:<EOL><INDENT>if api.is_uid(item):<EOL><INDENT>ref.append(item)<EOL><DEDENT>elif u.is_dict(item):<EOL><INDENT>uid = item.get('<STR_LIT>', None)<EOL>if uid:<EOL><INDENT>ref.append(uid)<EOL><DEDENT><DEDENT><DEDENT><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 uid reference field