当前位置: 首页>>代码示例>>Python>>正文


Python request.QueryDict方法代码示例

本文整理汇总了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) 
开发者ID:Cadasta,项目名称:cadasta-platform,代码行数:21,代码来源:test_widgets.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:22,代码来源:pages.py

示例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": "",
            },
        ) 
开发者ID:openfun,项目名称:richie,代码行数:27,代码来源:test_forms_search_courses.py

示例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)."]},
        ) 
开发者ID:openfun,项目名称:richie,代码行数:27,代码来源:test_forms_search_courses.py

示例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}) 
开发者ID:momosecurity,项目名称:aswan,代码行数:13,代码来源:views.py

示例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 
开发者ID:Palanaeum,项目名称:palanaeum,代码行数:8,代码来源:search.py

示例7: __init__

# 需要导入模块: from django.http import request [as 别名]
# 或者: from django.http.request import QueryDict [as 别名]
def __init__(self, get):
        self.GET = QueryDict(get) 
开发者ID:byro,项目名称:byro,代码行数:4,代码来源:test_common_templatetags.py

示例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') 
开发者ID:LexPredict,项目名称:lexpredict-contraxsuite,代码行数:37,代码来源:v1.py

示例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": ""}
        ) 
开发者ID:openfun,项目名称:richie,代码行数:9,代码来源:test_forms_search_items.py

示例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."]}
        ) 
开发者ID:openfun,项目名称:richie,代码行数:9,代码来源:test_forms_search_items.py

示例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()) 
开发者ID:openfun,项目名称:richie,代码行数:10,代码来源:test_forms_search_items.py

示例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."]},
        ) 
开发者ID:openfun,项目名称:richie,代码行数:10,代码来源:test_forms_search_items.py

示例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()) 
开发者ID:openfun,项目名称:richie,代码行数:10,代码来源:test_forms_search_items.py

示例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": ""}
        ) 
开发者ID:openfun,项目名称:richie,代码行数:14,代码来源:test_forms_search_items.py

示例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",
                                    }
                                }
                            ]
                        }
                    }
                },
            ),
        ) 
开发者ID:openfun,项目名称:richie,代码行数:32,代码来源:test_forms_search_items.py


注:本文中的django.http.request.QueryDict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。