本文整理汇总了Python中django.http.request.QueryDict.get方法的典型用法代码示例。如果您正苦于以下问题:Python QueryDict.get方法的具体用法?Python QueryDict.get怎么用?Python QueryDict.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.request.QueryDict
的用法示例。
在下文中一共展示了QueryDict.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put_data
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def put_data(request):
response = BaseResponse()
try:
post_dict = QueryDict(request.body, encoding='utf-8')
obj_id = post_dict.get('obj_id', None)
add_business_parent_id = post_dict.get('add_business_parent_id', None)
add_business_name = post_dict.get('add_business_name')
add_business_admin_list = post_dict.getlist('add_business_admin_list', [])
add_business_contact_list = post_dict.getlist('add_business_contact_list', [])
add_business_memo = post_dict.get('add_business_memo')
edit_data_to_db = models.BusinessUnit.objects.get(id=obj_id)
# 如果业务线包含子类,不允许更换至其他父级分组
if not edit_data_to_db.parent_level.all():
edit_data_to_db.parent_unit_id = add_business_parent_id
else:
response.message = "this is text."
edit_data_to_db.name = add_business_name
edit_data_to_db.memo = add_business_memo
edit_data_to_db.save()
edit_data_to_db.manager.clear()
edit_data_to_db.contact.clear()
for obj_id in add_business_admin_list:
edit_data_to_db.manager.add(user_center_models.UserGroup.objects.get(id=obj_id))
for obj_id in add_business_contact_list:
edit_data_to_db.contact.add(user_center_models.UserGroup.objects.get(id=obj_id))
except Exception as e:
response.status = False
response.message = str(e)
return response
示例2: add_data
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def add_data(request):
response = BaseResponse()
try:
response.error = []
post_dict = QueryDict(request.body, encoding='utf-8')
idc_name = post_dict.get('idc_name')
idc_floor = post_dict.get('idc_floor')
idc_phone = post_dict.get('idc_phone')
idc_address = post_dict.get('idc_address')
add_to_db = CMDB_MODELS.IDC(
name=idc_name,
floor=idc_floor,
phone=idc_phone,
idc_address = idc_address,
)
add_to_db.save()
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response
示例3: update_urlmaps_groups
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def update_urlmaps_groups(request):
response = BaseResponse()
try:
response.error = {}
post_dict = QueryDict(request.body, encoding='utf-8')
urlmaps_id = post_dict.get('urlmaps_id')
instance_list = post_dict.getlist('instance_list')
group_type = post_dict.get('group_type')
urlmaps_obj = repository_models.UrlConfigHandler.objects.get(id=urlmaps_id)
if group_type == 'cloud':
urlmaps_obj.cloud.clear()
for instance_id in instance_list:
urlmaps_obj.cloud.add(CMDB_MODELS.Asset.objects.get(id=instance_id))
elif group_type == 'forward':
urlmaps_obj.forward.clear()
for instance_id in instance_list:
urlmaps_obj.forward.add(CMDB_MODELS.Asset.objects.get(id=instance_id))
elif group_type == 'docker':
urlmaps_obj.docker.clear()
for instance_id in instance_list:
urlmaps_obj.docker.add(CMDB_MODELS.DockerInstance.objects.get(id=instance_id))
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response
示例4: add_server_group
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def add_server_group(request):
response = BaseResponse()
try:
response.error = {}
print(request.body)
post_dict = QueryDict(request.body, encoding='utf-8')
add_group_app_id = post_dict.get('add_group_app_id')
add_group_name = post_dict.get('add_group_name')
add_group_yaml_path = post_dict.get('add_group_yaml_path')
add_group_type = post_dict.get('add_group_type')
add_to_db = repository_models.AppGroups(
name=add_group_name,
yaml_path=add_group_yaml_path,
# app_id = repository_models.Applications.objects.get(id=add_group_app_id)
group_type=add_group_type,
)
add_to_db.save()
add_to_db.app_id.add(repository_models.Applications.objects.get(id=add_group_app_id))
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response
示例5: add_data
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def add_data(self, request):
response = BaseResponse()
try:
post_dict = QueryDict(request.body, encoding='utf-8')
add_business_parent_id = post_dict.get('add_business_parent_id', None)
add_business_name = post_dict.get('add_business_name')
add_business_admin_list = post_dict.getlist('add_business_admin_list', [])
add_business_contact_list = post_dict.getlist('add_business_contact_list', [])
add_business_memo = post_dict.get('add_business_memo')
add_data_to_db = models.BusinessUnit(
parent_unit_id=add_business_parent_id,
name=add_business_name,
memo=add_business_memo
)
add_data_to_db.save()
for obj_id in add_business_admin_list:
add_data_to_db.manager.add(user_center_models.UserGroup.objects.get(id=obj_id))
for obj_id in add_business_contact_list:
add_data_to_db.contact.add(user_center_models.UserGroup.objects.get(id=obj_id))
except Exception as e:
response.status = False
response.message = str(e)
return response
示例6: add_mission
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def add_mission(request):
response = BaseResponse()
post_dict = QueryDict(request.body, encoding='utf-8')
mission_name = post_dict.get('mission_name')
mission_type = post_dict.get('mission_type')
project_name = post_dict.get('project_name')
app_list = post_dict.getlist('app_list')
print(post_dict)
try:
# create mission project.
mission_project = repository_models.MissionProject(
name = project_name
)
mission_project.save()
# create mission app
for app_id in app_list:
mission_app = repository_models.MissionApp(
name=repository_models.Applications.objects.get(id=app_id).name
)
mission_app.save()
# create app ip first.
get_app_instances = repository_models.AppInstances.objects.filter(group_id__name='production', group_id__app_id__id=app_id, group_id__app_id__project_id__name=project_name).values()
for instance_obj in get_app_instances:
mission_appinstance = repository_models.MissionAppInstance(
ip = instance_obj.get('ip')
)
mission_appinstance.save()
mission_app.ip.add(mission_appinstance)
mission_project.app.add(mission_app)
# create mission
mission_create = repository_models.Mission(
name = mission_name,
mission_type = mission_type,
)
mission_create.save()
mission_create.project.add(mission_project)
response.data = {'mission_id': mission_create.id}
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response
示例7: data_create
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def data_create(request):
response = BaseResponse()
try:
post_data = QueryDict(request.body, encoding='utf-8')
role_name = post_data.get('role_name')
role_memo = post_data.get('role_memo')
permission_list = post_data.getlist('permission_list')
# 创建role
data_obj = USER_CENTER_MODELS.Roles(
name=role_name,
memo=role_memo,
)
data_obj.save()
# 关联permission
for obj_id in permission_list:
data_obj.permissions.add(obj_id)
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response
示例8: get
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def get(self, request, *args, **kwargs):
args_dict = request.GET.copy()
args_dict.update({
"test_suite_pk": kwargs["pk"],
"measure_name": kwargs["mname"]
})
cmd = [
settings.PYTHON_EXE,
os.path.join(settings.BASE_DIR, "bin", "plot_png.py"),
args_dict.urlencode(safe='/%')
]
print "Plot png: %s" % cmd[-1]
result = subprocess.check_output(cmd, env=os.environ.copy()).strip()
qdict = QueryDict(result)
fname = qdict.get("fname")
alarm = qdict.get("alarm")
if fname and fname != "":
f = open(fname, 'rb')
response = HttpResponse(f.read(), 'image/png')
f.close()
m_path = reverse(
'appmonitor:measure', args=[kwargs["pk"], kwargs["mname"]]
)
response.set_cookie("alarm_state", alarm, path=m_path)
return response
else:
f = open('appmonitor/static/appmonitor/nodata.png', 'rb')
response = HttpResponse(f.read(), 'image/png')
f.close()
return response
示例9: delete_server_instance
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def delete_server_instance(request):
response = BaseResponse()
try:
response.error = {}
post_dict = QueryDict(request.body, encoding='utf-8')
group_id = post_dict.get('group_id')
docker_id = post_dict.get('docker_id')
add_to_db = repository_models.AppGroups.objects.get(id=group_id)
add_to_db.docker.remove(CMDB_MODELS.DockerInstance.objects.get(id=docker_id))
except Exception as e:
response.status = False
response.message = str(e)
return response
示例10: asset_data_create
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def asset_data_create(request):
response = BaseResponse()
try:
asset_data = QueryDict(request.body, encoding='utf-8')
new_asset_num = asset_num.asset_num_builder()
asset_sn = asset_data.get('sn')
try:
Memory = int(asset_data.get('Memory'))
except:
Memory = None
try:
DeviceSize = int(asset_data.get('DeviceSize'))
except:
DeviceSize = None
try:
cpu_count = int(asset_data.get('cpu_count'))
except:
cpu_count = None
if not asset_sn:
asset_sn = new_asset_num
# 创建asset obj
asset_obj = models.Asset(
device_type_id = asset_data.get('device_type_id'),
asset_num = new_asset_num,
sn = asset_sn,
idc_id = asset_data.get('idc_id'),
business_unit_id = asset_data.get('business_unit_id'),
)
asset_obj.save()
# 创建server obj
server_obj = models.Server(
asset_id = asset_obj.id,
hostname = asset_data.get('hostname'),
ipaddress = asset_data.get('ipaddress'),
manage_ip = asset_data.get('manage_ip'),
Memory = Memory,
DeviceSize = DeviceSize,
cpu_count = cpu_count,
)
server_obj.save()
response.message = '获取成功'
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response
示例11: ws_connect
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def ws_connect(message):
query = QueryDict(message.content['query_string'])
page = query.get('page')
email_hash = get_email_hash(query.get('user'))
Group("presence").add(message.reply_channel)
presence = cache.get(PRESENCE_CACHE_KEY, dict())
if page in presence:
presence[page].append(email_hash)
else:
presence[page] = [email_hash]
cache.set(PRESENCE_CACHE_KEY, presence, PRESENCE_CACHE_TIMEOUT)
Group("presence").send({
"text": json.dumps(presence),
})
示例12: update_yaml_conf
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def update_yaml_conf(self, request):
response = BaseResponse()
try:
response.error = {}
post_dict = QueryDict(request.body, encoding='utf-8')
update_group_id = post_dict.get('group_id')
yaml_conf_data = post_dict.get('yaml_conf_data')
get_yaml_from_db = repository_models.DockerYamlConf.objects.get(group_id__id=update_group_id)
get_yaml_from_db.yaml_data = json.dumps(self.__yaml_to_json(yaml_conf_data))
get_yaml_from_db.save()
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response
示例13: put_data
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def put_data(request):
response = BaseResponse()
try:
response.error = []
put_dict = QueryDict(request.body, encoding='utf-8')
user_id = put_dict.get('group_id')
group_name = put_dict.get('group_name')
update_data = user_models.UserGroup.objects.get(id=user_id)
update_data.name = group_name
update_data.save()
except Exception as e:
print(Exception,e)
response.status = False
response.message = str(e)
return response
示例14: add_server_instance
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def add_server_instance(request):
response = BaseResponse()
try:
response.error = {}
post_dict = QueryDict(request.body, encoding='utf-8')
print(post_dict)
add_instance_group_id = post_dict.get('add_instance_group_id')
add_instance_id = post_dict.get('add_instance_id')
add_to_db = repository_models.AppGroups.objects.get(id=add_instance_group_id)
add_to_db.instance.add(CMDB_MODELS.Asset.objects.get(id=add_instance_id))
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response
示例15: update_server_instance
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import get [as 别名]
def update_server_instance(request):
response = BaseResponse()
try:
response.error = {}
post_dict = QueryDict(request.body, encoding='utf-8')
docker_group_id = post_dict.get('docker_group_id')
new_docker_id = post_dict.get('new_docker_id')
old_docker_id = post_dict.get('old_docker_id')
get_group_from_db = repository_models.AppGroups.objects.get(id=docker_group_id)
get_group_from_db.docker.remove(CMDB_MODELS.DockerInstance.objects.get(id=old_docker_id))
get_group_from_db.docker.add(CMDB_MODELS.DockerInstance.objects.get(id=new_docker_id))
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response