Exemplo n.º 1
0
def _init_config(request):
    q = Config.all()
    if q.count(1) == 0:
        c = Config()
        c.varname = "dummy"
        c.value = "you can safely delete this after creating new var/vals"
        c.put()
        return HttpResponse("""Config initialized. You can now add new values 
            in the <a href="/_ah/admin">Datastore admin</a>.""")
    else:
        return HttpResponse("""Config does not need initialization. You can
            edit the config in the <a href="/_ah/admin">Datastore admin</a>."""
                            )
Exemplo n.º 2
0
def settings(request):
    if request.method == "GET":
        context = {
            'path1': '全局设置',
            'path2': '编辑',
            'config': SysConfig().sys_config
        }
        return render(request, 'common/settings.html', context)
    else:
        if not request.user.has_perm('auth.perm_common_settings_edit'):
            return JsonResponse({'code': 1, 'errmsg': '权限不足,无法修改!'})
        configs = request.POST.get('configs', None)
        try:
            if configs is None or len(json.loads(configs)) == 0:
                return JsonResponse({'code': 1, 'errmsg': '提交内容为空!'})
            with transaction.atomic():
                Config.objects.all().delete()
                Config.objects.bulk_create(
                    [Config(item=items['key'], value=items['value']) for items in json.loads(configs)])
        except Exception as e:
            return JsonResponse({'code': 1, 'errmsg': str(e)})
        return JsonResponse({'code': 0, 'result': '保存成功!'})