Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
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))