本文整理汇总了Python中django.http.request.QueryDict.getlist方法的典型用法代码示例。如果您正苦于以下问题:Python QueryDict.getlist方法的具体用法?Python QueryDict.getlist怎么用?Python QueryDict.getlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.request.QueryDict
的用法示例。
在下文中一共展示了QueryDict.getlist方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put_data
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import getlist [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 getlist [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
示例3: data_create
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import getlist [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
示例4: update_urlmaps_groups
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import getlist [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
示例5: delete_assets
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import getlist [as 别名]
def delete_assets(request):
response = BaseResponse()
try:
delete_dict = QueryDict(request.body, encoding='utf-8')
id_list = delete_dict.getlist('id_list')
models.Asset.objects.filter(id__in=id_list).delete()
response.message = '删除成功'
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 getlist [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: put_data
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import getlist [as 别名]
def put_data(request):
response = BaseResponse()
try:
response.error = []
put_dict = QueryDict(request.body, encoding='utf-8')
user_id = put_dict.get('user_id')
user_name = put_dict.get('user_name')
user_phone = put_dict.get('user_phone')
user_email = put_dict.get('user_email')
user_department = put_dict.get('user_department')
user_group_list = put_dict.getlist('user_group')
user_roles_list = put_dict.getlist('user_roles')
update_data = user_models.UserProfile.objects.get(id=user_id)
try:
groups_list = user_models.UserGroup.objects.filter(id__in=user_group_list)
except:
groups_list = []
try:
roles_list = user_models.Roles.objects.filter(id__in=user_roles_list)
except:
roles_list = []
update_data.username = user_name
update_data.phone = user_phone
update_data.email = user_email
update_data.department = user_department
update_data.user_groups.clear()
update_data.roles.clear()
update_data.user_groups.add(*groups_list)
update_data.roles.add(*roles_list)
update_data.save()
except Exception as e:
print(Exception,e)
response.status = False
response.message = str(e)
return response
示例8: data_update
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import getlist [as 别名]
def data_update(request):
response = BaseResponse()
try:
put_data = QueryDict(request.body, encoding='utf-8')
obj_id = put_data.get('role_id')
role_name = put_data.get('role_name')
role_memo = put_data.get('role_memo')
permission_list = put_data.getlist('permission_list')
update_data = USER_CENTER_MODELS.Roles.objects.get(id=obj_id)
update_data.name = role_name
update_data.memo = role_memo
update_data.save()
update_data.permissions.clear()
for obj_id in permission_list:
update_data.permissions.add(obj_id)
except Exception as e:
print(Exception, e)
response.status = False
response.message = str(e)
return response
示例9: UrlHelper
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import getlist [as 别名]
class UrlHelper(object):
def __init__(self, full_path):
# If full_path is an UrlHelper instance, extract the full path from it
if type(full_path) is UrlHelper:
full_path = full_path.get_full_path()
# parse the path
r = urlparse.urlparse(full_path)
self.path = r.path
self.fragment = r.fragment
self.query_dict = QueryDict(smart_bytes(r.query), mutable=True)
def get_query_string(self, **kwargs):
return self.query_dict.urlencode(**kwargs)
def get_query_data(self):
return self.query_dict
def update_query_data(self, **kwargs):
for key, val in kwargs.iteritems():
if hasattr(val, '__iter__'):
self.query_dict.setlist(key, val)
else:
self.query_dict[key] = val
def get_path(self):
return self.path
def get_full_path(self, **kwargs):
query_string = self.get_query_string(**kwargs)
if query_string:
query_string = '?%s' % query_string
fragment = self.fragment and '#%s' % iri_to_uri(self.fragment) or ''
return '%s%s%s' % (
iri_to_uri(self.get_path()),
query_string,
fragment
)
def get_full_quoted_path(self, **kwargs):
return urllib.quote_plus(self.get_full_path(**kwargs), safe='/')
def overload_params(self, **kwargs):
for key, val in kwargs.iteritems():
uniques = set(self.query_dict.getlist(key))
uniques.add(val)
self.query_dict.setlist(key, list(uniques))
def del_param(self, param):
try:
del self.query_dict[param]
except KeyError:
pass # Fail silently
def del_params(self, *params, **kwargs):
if not params and not kwargs:
self.query = {}
return
if params:
for param in params:
self.del_param(param)
if kwargs:
for key, val in kwargs.iteritems():
to_keep = [x for x in self.query_dict.getlist(key)
if not x.startswith(val)]
self.query_dict.setlist(key, to_keep)
def toggle_params(self, **params):
for param, value in params.items():
value = unicode(value)
if value in self.query_dict.getlist(param):
self.del_params(**{param: value})
else:
self.overload_params(**{param: value})
@property
def hash(self):
md5 = hashlib.md5()
md5.update(self.get_full_path())
return md5.hexdigest()
@property
def query(self):
return self.get_query_data()
@query.setter
def query(self, value):
if type(value) is dict:
self.query_dict = QueryDict(b'', mutable=True)
self.update_query_data(**value)
else:
self.query_dict = QueryDict(smart_bytes(value), mutable=True)
@property
def query_string(self):
return self.get_query_string()
@query_string.setter
def query_string(self, value):
#.........这里部分代码省略.........