本文整理汇总了Python中django.utils.datastructures.MultiValueDict方法的典型用法代码示例。如果您正苦于以下问题:Python datastructures.MultiValueDict方法的具体用法?Python datastructures.MultiValueDict怎么用?Python datastructures.MultiValueDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.datastructures
的用法示例。
在下文中一共展示了datastructures.MultiValueDict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_value
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def get_value(self, data):
if isinstance(data, MultiValueDict):
regex = re.compile(r"^%s\.(.*)$" % re.escape(self.field_name))
ret = {}
for name, value in data.items():
match = regex.match(name)
if not match:
continue
key = match.groups()[0]
if value != '':
ret[key] = value
elif isinstance(data, dict):
ret = data.get(self.field_name, fields.empty)
else:
raise ValidationError("not a dict: " + str(type(data)))
if ret is fields.empty or len(ret) == 0:
return fields.empty
return ret
示例2: __init__
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def __init__(self):
# WARNING: The `WSGIRequest` subclass doesn't call `super`.
# Any variable assignment made here should also happen in
# `WSGIRequest.__init__()`.
self.GET = QueryDict(mutable=True)
self.POST = QueryDict(mutable=True)
self.COOKIES = {}
self.META = {}
self.FILES = MultiValueDict()
self.path = ''
self.path_info = ''
self.method = None
self.resolver_match = None
self._post_parse_error = False
self.content_type = None
self.content_params = None
示例3: test_get_4v4
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_get_4v4(self):
p1 = self.db.create_player(region=Region.EU, realm=1, bid=301)
p2 = self.db.create_player(region=Region.EU, realm=1, bid=302)
p3 = self.db.create_player(region=Region.EU, realm=1, bid=303)
p4 = self.db.create_player(region=Region.EU, realm=1, bid=304)
t = self.db.create_team(mode=Mode.TEAM_4V4, member0=p1, member1=p2, member2=p3, member3=p4)
qp = MultiValueDict()
qp.setlist('player',
[
'http://eu.battle.net/sc2/en/profile/304/1/xyz',
'http://eu.battle.net/sc2/en/profile/303/1/xyz',
'http://eu.battle.net/sc2/en/profile/302/1/xyz',
'http://eu.battle.net/sc2/en/profile/301/1/xyz',
])
qp['mode'] = 'team-4v4'
response = self.c.get('/team/id/', qp)
self.assertEqual(200, response.status_code)
data = json.loads(response.content.decode('utf-8'))
self.assertEqual(t.id, data['team_id'])
示例4: args_extract
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def args_extract(self, args, kwargs):
"""Extract data and files args, return mutable objects."""
# make popable (can't pop tuple of args)
args = list(args)
def getarg(name, num):
if args and len(args) > num:
return args.pop(num)
elif kwargs.get('files'):
return kwargs.pop('files')
return None
# First to not affect data = args.pop(0)
files = getarg('files', 1)
data = getarg('data', 0)
# make mutable if something
if files:
files = MultiValueDict(files)
if data:
data = MultiValueDict(data)
return data, files, args, kwargs
示例5: test_parses_empty_multivalue_dicts
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_parses_empty_multivalue_dicts(self):
empty = MultiValueDict({
'dob.year': [],
'dob.day': [],
'dob.month': [],
})
blank = MultiValueDict({
'dob.year': [''],
'dob.day': [''],
'dob.month': [''],
})
missing = MultiValueDict({})
for input_data in [empty, blank, missing]:
field = fields.DateOfBirthField(input_data, required=False)
self.assertParsesCorrectly(
field, self.empty_value, [None, None, None])
示例6: config_to_form
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def config_to_form(self, data: Dict[str, Any], points: Decimal) -> Dict[str, Any]:
"""
Convert a QuestionVersion.config value back to a corresponding request.POST style dict, so we can validate
JSON imports using existing for validators.
Will likely need to override this if .ConfigForm has validators that change the data as part of the cleaning.
"""
text = data['text']
formdata = MultiValueDict({k: [v] for k,v in data.items() if k != 'text'})
formdata['text_0'] = text[0]
formdata['text_1'] = text[1]
formdata['text_2'] = text[2]
formdata['points'] = points
return formdata
示例7: __init__
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def __init__(self, query_params=MultiValueDict(), method="GET"):
self.query_params = query_params
self.method = method
示例8: test_get_query_param_value_should_return_empty_if_not_root_serializer
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_get_query_param_value_should_return_empty_if_not_root_serializer(self):
serializer = FlexFieldsModelSerializer(
context={
"request": MockRequest(
method="GET", query_params=MultiValueDict({"expand": ["cat"]})
)
},
)
serializer.parent = "Another serializer here"
self.assertFalse(serializer._get_query_param_value("expand"), [])
示例9: test_get_omit_input_from_explicit_settings
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_get_omit_input_from_explicit_settings(self):
serializer = FlexFieldsModelSerializer(
omit=["fish"],
context={
"request": MockRequest(
method="GET", query_params=MultiValueDict({"omit": "cat,dog"})
)
},
)
self.assertEqual(serializer._flex_options["omit"], ["fish"])
示例10: test_set_omit_input_from_query_param
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_set_omit_input_from_query_param(self):
serializer = FlexFieldsModelSerializer(
context={
"request": MockRequest(
method="GET", query_params=MultiValueDict({"omit": ["cat,dog"]})
)
}
)
self.assertEqual(serializer._flex_options["omit"], ["cat", "dog"])
示例11: test_set_fields_input_from_explicit_settings
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_set_fields_input_from_explicit_settings(self):
serializer = FlexFieldsModelSerializer(
fields=["fish"],
context={
"request": MockRequest(
method="GET", query_params=MultiValueDict({"fields": "cat,dog"})
)
},
)
self.assertEqual(serializer._flex_options["fields"], ["fish"])
示例12: test_set_expand_input_from_explicit_setting
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_set_expand_input_from_explicit_setting(self):
serializer = FlexFieldsModelSerializer(
fields=["cat"],
context={
"request": MockRequest(
method="GET", query_params=MultiValueDict({"fields": "cat,dog"})
)
},
)
self.assertEqual(serializer._flex_options["fields"], ["cat"])
示例13: test_set_expand_input_from_query_param
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_set_expand_input_from_query_param(self):
serializer = FlexFieldsModelSerializer(
context={
"request": MockRequest(
method="GET", query_params=MultiValueDict({"expand": ["cat,dog"]})
)
}
)
self.assertEqual(serializer._flex_options["expand"], ["cat", "dog"])
示例14: test_get_expand_input_from_query_param_limit_to_list_permitted
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_get_expand_input_from_query_param_limit_to_list_permitted(self):
serializer = FlexFieldsModelSerializer(
context={
"request": MockRequest(
method="GET", query_params=MultiValueDict({"expand": ["cat,dog"]})
),
"permitted_expands": ["cat"],
}
)
self.assertEqual(serializer._flex_options["expand"], ["cat"])
示例15: test_parse_request_list_value
# 需要导入模块: from django.utils import datastructures [as 别名]
# 或者: from django.utils.datastructures import MultiValueDict [as 别名]
def test_parse_request_list_value(self):
test_params = [
{"abc": ["cat,dog,mouse"]},
{"abc": ["cat", "dog", "mouse"]},
{"abc[]": ["cat", "dog", "mouse"]},
]
for query_params in test_params:
serializer = FlexFieldsModelSerializer(context={})
serializer.context["request"] = MockRequest(
method="GET", query_params=MultiValueDict(query_params)
)
result = serializer._get_query_param_value("abc")
self.assertEqual(result, ["cat", "dog", "mouse"])