Example #1
0
def get_config_value(key):
    item = get_config_item(key)
    if not item:
        return

    value = cache.get(CACHE_KEY_PREFIX + key)
    if value:
        return value

    obj = get_object_or_none(Item, key=key)
    if obj:
        if obj.type == TYPE_STR:
            value = smart_str(obj.value)
        elif obj.type == TYPE_UNICODE:
            value = smart_unicode(obj.value)
        elif obj.type == TYPE_INT:
            value = int(obj.value)
        elif obj.type == TYPE_FLOAT:
            value = float(obj.value)
        elif obj.type == TYPE_BOOL:
            value = obj.value == 'True'

    if value is None:
        value = item[1]

    cache.set(CACHE_KEY_PREFIX + key, value)
    return value
Example #2
0
def get_login_by_token(token):
    u"""
    通过 token 获取有效的 Login实例
    :param token: token
    :return: Login
    """
    if token and len(token) == 32:
        login = get_object_or_none(Login, token=token)
        if login and login.is_active:
            return login
Example #3
0
def set_config_value(key, value):
    cache.set(CACHE_KEY_PREFIX + key, value)
    value_type = get_value_type(value)
    obj = get_object_or_none(Item, key=key)
    if obj:
        obj.value = value
        obj.type = value_type
        obj.save()
        return obj
    else:
        return Item.objects.create(key=key, value=value, type=value_type)
Example #4
0
def get_auth_by_openid(openid):
    return get_object_or_none(Auth, openid=openid)
Example #5
0
def delete_config(key):
    cache.delete(CACHE_KEY_PREFIX + key)
    obj = get_object_or_none(Item, key=key)
    if obj:
        obj.delete()