本文整理汇总了Python中django.http.request.QueryDict方法的典型用法代码示例。如果您正苦于以下问题:Python request.QueryDict方法的具体用法?Python request.QueryDict怎么用?Python request.QueryDict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.request
的用法示例。
在下文中一共展示了request.QueryDict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_value_from_datadict
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_value_from_datadict(self):
formset = formset_factory(ContactsForm)
widget = widgets.ContactsWidget(attrs={'formset': formset})
data = {
'contacts-TOTAL_FORMS': '2',
'contacts-INITIAL_FORMS': '1',
'contacts-MIN_NUM_FORMS': '0',
'contacts-MAX_NUM_FORMS': '1000',
'contacts-0-name': 'Ringo',
'contacts-0-email': 'ringo@beatles.uk',
'contacts-0-tel': '555-555',
'contacts-1-name': '',
'contacts-1-email': '',
'contacts-1-tel': ''
}
q_dict = QueryDict('', mutable=True)
q_dict.update(data)
value = widget.value_from_datadict(q_dict, {}, 'contacts')
assert isinstance(value, formset)
示例2: get
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def get(self, request, *args, **kwargs):
page = self.get_page()
post_data, timestamp = self.request.session.get(self.session_key,
(None, None))
if not isinstance(post_data, str):
post_data = ''
form = self.get_form(page, QueryDict(post_data))
if not form.is_valid():
return self.error_response(page)
form.save(commit=False)
try:
preview_mode = request.GET.get('mode', page.default_preview_mode)
except IndexError:
raise PermissionDenied
return page.make_preview_request(request, preview_mode)
示例3: test_forms_courses_empty_querystring
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_forms_courses_empty_querystring(self, *_):
"""The empty query string should be a valid search form."""
form = CourseSearchForm(data=QueryDict())
self.assertTrue(form.is_valid())
self.assertEqual(
form.cleaned_data,
{
"availability": [],
"languages": [],
"levels": [],
"levels_include": "",
"limit": None,
"new": [],
"offset": None,
"organizations": [],
"organizations_include": "",
"persons": [],
"persons_include": "",
"query": "",
"scope": "",
"subjects": [],
"subjects_include": "",
},
)
示例4: test_forms_courses_query_between_3_and_100_characters_long
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_forms_courses_query_between_3_and_100_characters_long(self, *_):
"""The `query` param should be between 3 and 100 characters long."""
form = CourseSearchForm(data=QueryDict(query_string="query=aa"))
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors,
{"query": ["Ensure this value has at least 3 characters (it has 2)."]},
)
form = CourseSearchForm(data=QueryDict(query_string="query=aaa"))
self.assertTrue(form.is_valid())
form = CourseSearchForm(
data=QueryDict(query_string="query={:s}".format("a" * 100))
)
self.assertTrue(form.is_valid())
form = CourseSearchForm(
data=QueryDict(query_string="query={:s}".format("a" * 101))
)
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors,
{"query": ["Ensure this value has at most 100 characters (it has 101)."]},
)
示例5: delete
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def delete(self, request):
request.DELETE = QueryDict(request.body)
entity_id = request.DELETE.get('entity_id')
if not entity_id:
return self.render_json_response({
'state': False,
'error': 'entity_id is required!'
}, status=400)
group = GroupPermission.objects.get_by_id(entity_id)
group.delete()
return self.render_json_response({'state': True})
示例6: init_from_get_params
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def init_from_get_params(self, get_params: QueryDict) -> bool:
"""
Initialize this filter using data passed in GET request.
Return bool indicating if this search filter is used.
"""
raise NotImplementedError
示例7: __init__
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def __init__(self, get):
self.GET = QueryDict(get)
示例8: send_clusters_to_project
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def send_clusters_to_project(self, request, **kwargs):
"""
Send clusters to another Project\n
Params:
- cluster_ids: list[int]
- project_id: int
"""
project = self.get_object()
# via API
if isinstance(request.data, QueryDict):
cluster_ids = [int(i) for i in request.data.getlist('cluster_ids')]
# via swagger
else:
cluster_ids = request.data['cluster_ids']
project_clustering = project.projectclustering_set.last()
if not project_clustering:
raise APIException('Project Clustering object not found')
reassigned_cluster_ids = project_clustering.metadata.get('reassigned_cluster_ids', [])
already_reassigned_clusters = set(cluster_ids) & set(reassigned_cluster_ids)
if already_reassigned_clusters:
raise APIException('Cluster(s) id=({}) is/are already reassigned to another project'
.format(', '.join(str(i) for i in already_reassigned_clusters)))
new_project_id = int(request.data['project_id'])
call_task(
ReassignProjectClusterDocuments,
project_clustering_id=project_clustering.id,
cluster_ids=cluster_ids,
project_id=project.id,
new_project_id=new_project_id,
user_id=request.user.id)
return Response('OK')
示例9: test_forms_items_empty_querystring
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_forms_items_empty_querystring(self, *_):
"""The empty query string should be a valid search form."""
form = ItemSearchForm(data=QueryDict())
self.assertTrue(form.is_valid())
self.assertEqual(
form.cleaned_data, {"limit": None, "offset": None, "query": "", "scope": ""}
)
示例10: test_forms_items_limit_greater_than_1
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_forms_items_limit_greater_than_1(self, *_):
"""The `limit` param should be greater than 1."""
form = ItemSearchForm(data=QueryDict(query_string="limit=0"))
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors, {"limit": ["Ensure this value is greater than or equal to 1."]}
)
示例11: test_forms_items_limit_integer
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_forms_items_limit_integer(self, *_):
"""The `limit` param should be an integer."""
form = ItemSearchForm(data=QueryDict(query_string="limit=a"))
self.assertFalse(form.is_valid())
self.assertEqual(form.errors, {"limit": ["Enter a whole number."]})
form = ItemSearchForm(data=QueryDict(query_string="limit=1"))
self.assertTrue(form.is_valid())
示例12: test_forms_items_offset_greater_than_0
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_forms_items_offset_greater_than_0(self, *_):
"""The `offset` param should be greater than 0."""
form = ItemSearchForm(data=QueryDict(query_string="offset=-1"))
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors,
{"offset": ["Ensure this value is greater than or equal to 0."]},
)
示例13: test_forms_items_offset_integer
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_forms_items_offset_integer(self, *_):
"""The `offset` param should be an integer."""
form = ItemSearchForm(data=QueryDict(query_string="offset=a"))
self.assertFalse(form.is_valid())
self.assertEqual(form.errors, {"offset": ["Enter a whole number."]})
form = ItemSearchForm(data=QueryDict(query_string="offset=1"))
self.assertTrue(form.is_valid())
示例14: test_forms_items_single_values_in_querystring
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_forms_items_single_values_in_querystring(self, *_):
"""
The fields from filter definitions should be normalized as lists. The fields defined
on the form should be single values (limit, offset and query).
"""
form = ItemSearchForm(
data=QueryDict(query_string=("limit=9&offset=3&query=maths"))
)
self.assertTrue(form.is_valid())
self.assertEqual(
form.cleaned_data, {"limit": 9, "offset": 3, "query": "maths", "scope": ""}
)
示例15: test_forms_items_build_es_query_search_by_match_text
# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def test_forms_items_build_es_query_search_by_match_text(self, *_):
"""
Happy path: build a query that filters items by matching text
"""
form = ItemSearchForm(
data=QueryDict(query_string="limit=20&offset=2&query=some%20phrase%20terms")
)
self.assertTrue(form.is_valid())
self.assertEqual(
form.build_es_query(),
(
20,
2,
{
"query": {
"bool": {
"must": [
{
"multi_match": {
"analyzer": "english",
"fields": ["title.*"],
"query": "some phrase " "terms",
}
}
]
}
}
},
),
)