def set(self, instance, value, **kw):  # noqa
        """Set the value of the uid reference field
        """
        ref = []
        # The value is an UID
        if api.is_uid(value):
            ref.append(value)

        # The value is a dictionary, get the UIDs.
        if u.is_dict(value):
            ref = ref.append(value.get("uid"))

        # The value is already an object
        if api.is_at_content(value):
            ref.append(value)

        # The value is a list
        if u.is_list(value):
            for item in value:
                # uid
                if api.is_uid(item):
                    ref.append(item)
                # dict (catalog query)
                elif u.is_dict(item):
                    # If there is UID of objects, just use it.
                    uid = item.get('uid', None)
                    if uid:
                        ref.append(uid)

        # Handle non multi valued fields
        if not self.multi_valued:
            if len(ref) > 1:
                raise ValueError("Multiple values given for single valued "
                                 "field {}".format(repr(self.field)))
            else:
                ref = ref[0]

        return self._set(instance, ref, **kw)
def set ( self , instance , value , ** kw ) : ref = [ ] if api . is_uid ( value ) : ref . append ( value ) if u . is_dict ( value ) : ref = ref . append ( value . get ( "uid" ) ) if api . is_at_content ( value ) : ref . append ( value ) if u . is_list ( value ) : for item in value : if api . is_uid ( item ) : ref . append ( item ) elif u . is_dict ( item ) : uid = item . get ( 'uid' , None ) if uid : ref . append ( uid ) if not self . multi_valued : if len ( ref ) > 1 : raise ValueError ( "Multiple values given for single valued " "field {}" . format ( repr ( self . field ) ) ) else : ref = ref [ 0 ] return self . _set ( instance , ref , ** kw )
Set the value of the uid reference field