示例#1
0
文件: functions.py 项目: rokj/sellout
def load_user_config(user):
    try:
        c = UserConfig.objects.get(user=user)
    except UserConfig.DoesNotExist:
        # use defaults
        c = UserConfig(created_by=user,
                       user=user,
                       data=json.dumps(user_defaults))
        c.save()

    # parse json from the database (or defaults)
    return json.loads(c.data)
示例#2
0
文件: functions.py 项目: rokj/sellout
def save_user_config(user, data):
    # update or save settings
    try:
        c = UserConfig.objects.get(user=user)
        c.data = json.dumps(data)
        c.save()
    except UserConfig.DoesNotExist:
        c = UserConfig(created_by=user,
                       user=user,
                       data=json.dumps(data))
        c.save()
    
    # delete cache
    cache.delete(user_cache_key(user))