當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。