Sets a key to a value on the currently logged in users preferences

    :param key: Key to set
    :type key: str
    :param val: Value to set
    :type val: primitive
    :returns: json
166968
def post(request):
    
    data = request.POST or json.loads(request.body)['body']
    key = data.get('key', None)
    val = data.get('val', None)
    res = Result()
    if key is not None and val is not None:
        obj, created = UserPref.objects.get_or_create(user=request.user)
        if created:
            obj.data = json.dumps(DefaultPrefs.copy())
            obj.save()
        try:
            val = json.loads(val)
        except (TypeError, ValueError):
            pass
        obj.setKey(key, val)
        obj.save()
        res.append(obj.json())

    return JsonResponse(res.asDict())
745605
def set(self, key, value):
        ""
        # if key already in data, update indexes
        if not isinstance(value, dict):
            raise BadValueError(
                'The value {} is incorrect.'
                ' Values should be strings'.format(value))
        _value = deepcopy(value)
        if key in self.data:
            self.delete_from_index(key)
        self.data[key] = _value
        self.update_index(key, _value)
971278
def with_value(self, key, val):
        ''' 
        '''
        new_dict = dict(self._dict)
        new_dict[key] = val
        return AuthContext(new_dict)
1190300
def set(self, key, value, *, flags=None):
        
        self.append({
            "Verb": "set",
            "Key": key,
            "Value": encode_value(value, flags, base64=True).decode("utf-8"),
            "Flags": flags
        })
        return self
1269476
def setKey(self, key, value):
		
		data = self.getDictionary()
		data[key] = value
		self.setDictionary(data)
157936
def set(self, val, lifetime=None):
        
        cache.set(self.key,
                  (json.dumps(val) if self.serialize else val),
                  lifetime or settings.DEFAULT_CACHE_EXPIRE_TIME)
        return val
1072972
def set(self, key: str, value: Any) -> 'PygalleBaseClass':
        
        self.public()[key] = value
        return self
851456
def set(self, key, value, *args, **kwargs):
        
        if self.cfg.jsonpickle:
            value = jsonpickle.encode(value)
        return self.conn.set(key, value, *args, **kwargs)
225705
def set(self, key, value, **kwargs):
        '''
        
        '''
        return requests.put(
            '{}/{}/kv/{}'.format(
                self.master, pyconsul.__consul_api_version__, key),
            data=value,
            params=kwargs
        )
1204106
def Set(self, key, value):
        
        if not value == None: self.prefs[key] = value
        else:                 self.prefs.pop(key)

        self.Dump()
223156
def _set_key(self, key, value):
        

        if is_config_section(value):
            self.add_section(key, value)
            return

        if key not in self._tree or self.settings.key_setter is None:
            if is_config_item(value):
                self.add_item(key, value)
                return

            raise TypeError(
                'Section sections/items can only be replaced with sections/items, '
                'got {type}. To set value use ..[{name}].value = <new_value>'.format(
                    type=type(value),
                    name=key,
                )
            )

        if self.settings.key_setter is None:
            self._default_key_setter(key, value)
        else:
            self.settings.key_setter(subject=self._tree[key], value=value, default_key_setter=self._default_key_setter)
67460
def set_custom_values(self, key, values):
        
        for value in values:
            self.set_custom_value(key, value)
89090
def set(self, key, value):
        """"""
        key = "{0}{1}".format(self.prefix, key)

        value = json.dumps(value, cls=NumpyEncoder)
        self.redis.set(key, value)
907035
def set_(key, value, profile=None):
    '''
    
    '''
    conn = salt.utils.memcached.get_conn(profile)
    time = profile.get('expire', DEFAULT_EXPIRATION)
    return salt.utils.memcached.set_(conn, key, value, time=time)
68588
function(key, val) {
      var len = arguments.length;
      if (len === 1 && typeof key === 'string') {
        return this.getOption(key);
      }
      if (utils.isObject(key)) {
        this.visit('option', key);
        return this;
      }
      set(this.options, key, val);
      this.emit('option', key, val);
      return this;
    }
737184
async def set(self, key, value, param=None, expire_time=None, herd_timeout=None):
        
        identity = self._gen_identity(key, param)
        expected_expired_ts = int(time.time())
        if expire_time:
            expected_expired_ts += expire_time
        expected_expired_ts += herd_timeout or self.default_herd_timeout
        value = self._pack([value, expected_expired_ts])
        return await self.client.set(identity, value, ex=expire_time)
972368
def get(self, key, default=None):
        
        val = self._store.get(key)

        if val is None:
            return value(default)

        return val