def replace(self, configs): result = {'status': 0, 'msg': 'ok', 'data': []} # 清空并替换 try: with transaction.atomic(): self.purge() Config.objects.bulk_create( [Config(item=items['key'].strip(), value=str(items['value']).strip()) for items in json.loads(configs)]) except Exception as e: logger.error(traceback.format_exc()) result['status'] = 1 result['msg'] = str(e) finally: self.get_all_config() return result
def changeconfig(request): configs = request.POST.get('configs') result = {'status': 0, 'msg': 'ok', 'data': []} # 清空并替换 try: 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: result['status'] = 1 result['msg'] = str(e) # 返回结果 return HttpResponse(json.dumps(result), content_type='application/json')
def replace(self, configs): result = {'status': 0, 'msg': 'ok', 'data': []} # 清空并替换 try: 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: logger.error(traceback.format_exc()) result['status'] = 1 result['msg'] = str(e) else: # 删除并更新缓存 try: cache.delete('sys_config') except Exception: logger.error(traceback.format_exc()) finally: self.get_all_config() return result