def put(self, request): data = QueryDict(request.body) pk = data.get('id') status = data.get('status') vhosts_object = vhosts_Confd.objects.get(pk=pk) if vhosts_Confd.objects.filter(pk=pk, vhosts_value__startswith='192'): if status == '0': vhosts_object.vhosts_value = vhosts_object.vhosts_value + ' down' vhosts_object.vhosts_status = 1 create_vhost(vhosts_object.vhosts_key, vhosts_object.vhosts_value) vhosts_object.save() ret = {'code': 0, 'result': '修改成功!'} elif status == '1': value = vhosts_object.vhosts_value.split(' ')[0] vhosts_object.vhosts_status = 0 vhosts_object.vhosts_value = value create_vhost(vhosts_object.vhosts_key, value) vhosts_object.save() ret = {'code': 0, 'result': '修改成功!'} else: ret = {'code': 1, 'result': '修改失败!'} else: ret = {'code': 1, 'result': '该字段没有此功能!'} return JsonResponse(ret, safe=True)
def post(self, request): webdata = request.POST.dict() vhosts_object = vhosts_Confd.objects.get(pk=webdata['id']) try: if create_vhost(webdata['vhosts_key'], webdata['vhosts_value']): vhosts_object.vhosts_value = webdata['vhosts_value'] vhosts_object.save() return HttpResponseRedirect(reverse('confd:vhost_list')) else: ret = {'code': 1, 'result': '修改失败!'} except: ret = {'code': 1, 'result': '修改失败!'} return JsonResponse(ret, safe=True)
def post(self, request): webdata = request.POST.dict() project_name = webdata.get('project_name') project = project_Confd.objects.filter(pk=project_name).values('project_url')[0] webdata['vhosts_key'] = project['project_url'] + '/' + webdata['vhosts_key'] forms = VhostForm(webdata) if forms.is_valid(): try: if create_vhost(webdata['vhosts_key'],webdata['vhosts_value']): forms.save() return HttpResponseRedirect(reverse('confd:vhost_list')) else: ret = {'code': 1, 'result': '添加失败!'} except: ret = {'code': 1, 'result': '添加失败!'} else: ret = {'code': 1, 'result': '添加失败!'} return JsonResponse(ret, safe=True)