Python django.http.QueryDict() Examples
The following are 30
code examples of django.http.QueryDict().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.http
, or try the search function
.
Example #1
Source File: test_rest.py From scale with Apache License 2.0 | 6 votes |
def test_parse_bool_false(self): """Tests parsing a required bool parameter that is provided via GET.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test1': 'FALSE', 'test2': 'False', 'test3': 'false', 'test4': 'f', 'test5': '0', }) self.assertFalse(rest_util.parse_bool(request, 'test1')) self.assertFalse(rest_util.parse_bool(request, 'test2')) self.assertFalse(rest_util.parse_bool(request, 'test3')) self.assertFalse(rest_util.parse_bool(request, 'test4')) self.assertFalse(rest_util.parse_bool(request, 'test5'))
Example #2
Source File: order.py From Servo with BSD 2-Clause "Simplified" License | 6 votes |
def list_orders(request): """ orders/index """ args = request.GET.copy() default = {'state': Order.STATE_QUEUED} if len(args) < 2: # search form not submitted f = request.session.get("order_search_filter", default) args = QueryDict('', mutable=True) args.update(f) request.session['order_search_filter'] = args data = prepare_list_view(request, args) return render(request, "orders/index.html", data)
Example #3
Source File: views.py From GTDWeb with GNU General Public License v2.0 | 6 votes |
def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): """ Redirects the user to the login page, passing the given 'next' page """ resolved_url = resolve_url(login_url or settings.LOGIN_URL) login_url_parts = list(urlparse(resolved_url)) if redirect_field_name: querystring = QueryDict(login_url_parts[4], mutable=True) querystring[redirect_field_name] = next login_url_parts[4] = querystring.urlencode(safe='/') return HttpResponseRedirect(urlunparse(login_url_parts)) # 4 views for password reset: # - password_reset sends the mail # - password_reset_done shows a success message for the above # - password_reset_confirm checks the link the user clicked and # prompts for a new password # - password_reset_complete shows a success message for the above
Example #4
Source File: tests_views.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_ocpcpuview_success(self, mock_handler): """Test OCP cpu view report.""" mock_handler.return_value.execute_query.return_value = self.report_ocp_cpu params = { "group_by[node]": "*", "filter[resolution]": "monthly", "filter[time_scope_value]": "-1", "filter[time_scope_units]": "month", } user = User.objects.get(username=self.user_data["username"]) django_request = HttpRequest() if not django_request.META.get("HTTP_HOST"): django_request.META["HTTP_HOST"] = "testhost" qd = QueryDict(mutable=True) qd.update(params) django_request.GET = qd request = Request(django_request) request.user = user response = OCPCpuView().get(request) self.assertIsInstance(response, Response) self.assertEqual(response.status_code, status.HTTP_200_OK)
Example #5
Source File: tests_views.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_ocpmemview_success(self, mock_handler): """Test OCP memory view report.""" mock_handler.return_value.execute_query.return_value = self.report_ocp_mem params = { "group_by[node]": "*", "filter[resolution]": "monthly", "filter[time_scope_value]": "-1", "filter[time_scope_units]": "month", } user = User.objects.get(username=self.user_data["username"]) django_request = HttpRequest() if not django_request.META.get("HTTP_HOST"): django_request.META["HTTP_HOST"] = "testhost" qd = QueryDict(mutable=True) qd.update(params) django_request.GET = qd request = Request(django_request) request.user = user response = OCPMemoryView().get(request) self.assertIsInstance(response, Response) self.assertEqual(response.status_code, status.HTTP_200_OK)
Example #6
Source File: tests_views.py From koku with GNU Affero General Public License v3.0 | 6 votes |
def test_costview_with_units_success(self, mock_handler): """Test unit conversion succeeds in AzureCostView.""" mock_handler.return_value.execute_query.return_value = self.report params = { "group_by[subscription_guid]": "*", "filter[resolution]": "monthly", "filter[time_scope_value]": "-1", "filter[time_scope_units]": "month", "units": "byte", "SERVER_NAME": "", } user = User.objects.get(username=self.user_data["username"]) django_request = HttpRequest() qd = QueryDict(mutable=True) qd.update(params) django_request.GET = qd request = Request(django_request) request.user = user response = AzureCostView().get(request) self.assertIsInstance(response, Response)
Example #7
Source File: views.py From kobo-predict with BSD 2-Clause "Simplified" License | 6 votes |
def export_menu(request, username, id_string): req = request.REQUEST export_type = req.get('type', None) if export_type: lang = req.get('lang', None) hierarchy_in_labels = req.get('hierarchy_in_labels') group_sep = req.get('group_sep', '/') q = QueryDict('', mutable=True) q['lang'] = req.get('lang') q['hierarchy_in_labels'] = req.get('hierarchy_in_labels') q['group_sep'] = req.get('group_sep', '/') if export_type == "xlsx": url = reverse('formpack_xlsx_export', args=(username, id_string)) return redirect(url + '?' + q.urlencode()) if export_type == "csv": url = reverse('formpack_csv_export', args=(username, id_string)) return redirect(url + '?' + q.urlencode()) context = build_export_context(request, username, id_string) return render(request, 'survey_report/export_menu.html', context)
Example #8
Source File: views.py From bioforum with MIT License | 6 votes |
def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME): """ Redirect the user to the login page, passing the given 'next' page. """ resolved_url = resolve_url(login_url or settings.LOGIN_URL) login_url_parts = list(urlparse(resolved_url)) if redirect_field_name: querystring = QueryDict(login_url_parts[4], mutable=True) querystring[redirect_field_name] = next login_url_parts[4] = querystring.urlencode(safe='/') return HttpResponseRedirect(urlunparse(login_url_parts)) # 4 views for password reset: # - password_reset sends the mail # - password_reset_done shows a success message for the above # - password_reset_confirm checks the link the user clicked and # prompts for a new password # - password_reset_complete shows a success message for the above
Example #9
Source File: tests.py From django-simple-pagination with MIT License | 6 votes |
def test_get_querystring_for_page(self): request = self request = HttpRequest() dict = {u"querystring_key": 1, u"key": 2, u"page": 3} qdict = QueryDict('', mutable=True) qdict.update(dict) request.GET = qdict val = get_querystring_for_page(request=request, page_number=1, querystring_key="key", default_number=1) self.assertTrue(bool(val)) request.GET = {} val = get_querystring_for_page(request=request, page_number=1, querystring_key="key", default_number=1) self.assertFalse(bool(val))
Example #10
Source File: tests.py From django-simple-pagination with MIT License | 6 votes |
def test_get_querystring_for_page(self): request = self request = HttpRequest() dict = {u"querystring_key": 1, u"key": 2, u"page": 3} qdict = QueryDict('', mutable=True) qdict.update(dict) request.GET = qdict val = get_querystring_for_page(request=request, page_number=1, querystring_key="key", default_number=1) self.assertTrue(bool(val)) request.GET = {} val = get_querystring_for_page(request=request, page_number=1, querystring_key="key", default_number=1) self.assertFalse(bool(val))
Example #11
Source File: views.py From django-sudo with BSD 3-Clause "New" or "Revised" License | 6 votes |
def redirect_to_sudo(next_url, sudo_url=None): """ Redirects the user to the login page, passing the given 'next' page """ if sudo_url is None: sudo_url = URL try: # django 1.10 and greater can't resolve the string 'sudo.views.sudo' to a URL # https://docs.djangoproject.com/en/1.10/releases/1.10/#removed-features-1-10 sudo_url = import_string(sudo_url) except (ImportError, ImproperlyConfigured): pass # wasn't a dotted path sudo_url_parts = list(urlparse(resolve_url(sudo_url))) querystring = QueryDict(sudo_url_parts[4], mutable=True) querystring[REDIRECT_FIELD_NAME] = next_url sudo_url_parts[4] = querystring.urlencode(safe="/") return HttpResponseRedirect(urlunparse(sudo_url_parts))
Example #12
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_int_invalid(self): """Tests parsing a required int parameter that is not a valid number.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test': 'abc', }) self.assertRaises(BadParameter, rest_util.parse_int, request, 'test')
Example #13
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_list_post(self): """Tests parsing a required list of string parameters that are provided via POST.""" request = MagicMock(Request) request.data = QueryDict('', mutable=True) request.data.update({ 'test': ['value1', 'value2'] }) self.assertEqual(rest_util.parse_string_list(request, 'test'), ['value1', 'value2'])
Example #14
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_list_accepted_all(self): """Tests parsing a list of string parameters where all values are acceptable.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.setlist('test', ['value1', 'value2']) self.assertListEqual(rest_util.parse_string_list(request, 'test', accepted_values=['value1', 'value2']), ['value1', 'value2'])
Example #15
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_list_accepted_partial(self): """Tests parsing a list of string parameters where only some values are acceptable.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.setlist('test', ['value1', 'value2']) self.assertRaises(BadParameter, rest_util.parse_string_list, request, 'test', accepted_values=['value1'])
Example #16
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_list_accepted_none(self): """Tests parsing a list of string parameters where none of the values are acceptable.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.setlist('test', ['value1', 'value2']) self.assertRaises(BadParameter, rest_util.parse_string_list, request, 'test', accepted_values=['value'])
Example #17
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_list_optional(self): """Tests parsing an optional list of string parameters that are missing.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.setlist('test', ['value1']) self.assertListEqual(rest_util.parse_string_list(request, 'test2', required=False), [])
Example #18
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_list_missing(self): """Tests parsing a required list of string parameters that are missing.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.setlist('test', ['value1', 'value2']) self.assertRaises(BadParameter, rest_util.parse_string_list, request, 'test2')
Example #19
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_list(self): """Tests parsing a required list of string parameters that is provided via GET.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.setlist('test', ['value1', 'value2']) self.assertListEqual(rest_util.parse_string_list(request, 'test'), ['value1', 'value2'])
Example #20
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_post(self): """Tests parsing a required string parameter that is provided via POST.""" request = MagicMock(Request) request.data = QueryDict('', mutable=True) request.data.update({ 'test': 'value1', }) self.assertEqual(rest_util.parse_string(request, 'test'), 'value1')
Example #21
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_accepted_all(self): """Tests parsing a string parameter where the value is acceptable.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test': 'value1', }) self.assertEqual(rest_util.parse_string(request, 'test', accepted_values=['value1']), 'value1')
Example #22
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_accepted_none(self): """Tests parsing a string parameter where the value is not acceptable.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test': 'value1', }) self.assertRaises(BadParameter, rest_util.parse_string, request, 'test', accepted_values=['value'])
Example #23
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_default(self): """Tests parsing an optional string parameter that is provided via default value.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test': 'value1', }) self.assertEqual(rest_util.parse_string(request, 'test2', 'value2'), 'value2')
Example #24
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string_missing(self): """Tests parsing a required string parameter that is missing.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test': 'value1', }) self.assertRaises(BadParameter, rest_util.parse_string, request, 'test2')
Example #25
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_parse_string(self): """Tests parsing a required string parameter that is provided via GET.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test': 'value1', }) self.assertEqual(rest_util.parse_string(request, 'test'), 'value1')
Example #26
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_has_params_all(self): """Tests checking parameter presence when all are given.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test1': 'value1', 'test2': None, }) self.assertTrue(rest_util.has_params(request, 'test1', 'test2'))
Example #27
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_has_params_partial(self): """Tests checking parameter presence when some are given.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) request.query_params.update({ 'test1': 'value1', }) self.assertFalse(rest_util.has_params(request, 'test1', 'test2'))
Example #28
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_has_params_none(self): """Tests checking parameter presence when none are given.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) self.assertFalse(rest_util.has_params(request, None, None))
Example #29
Source File: test_rest.py From scale with Apache License 2.0 | 5 votes |
def test_has_params_empty(self): """Tests checking parameter presence when none are given.""" request = MagicMock(Request) request.query_params = QueryDict('', mutable=True) self.assertFalse(rest_util.has_params(request))
Example #30
Source File: account.py From Servo with BSD 2-Clause "Simplified" License | 5 votes |
def orders(request): """ This is basically like orders/index, but limited to the user First, filter by the provided search criteria, then check if we have a saved search filter then default to user id Always update saved search filter """ args = request.GET.copy() default = {'state': Order.STATE_OPEN} if len(args) < 2: f = request.session.get("account_search_filter", default) args = QueryDict('', mutable=True) args.update(f) # On the profile page, filter by the user, no matter what args.update({'followed_by': request.user.pk}) request.session['account_search_filter'] = args data = prepare_list_view(request, args) data['title'] = _("My Orders") del(data['form'].fields['assigned_to']) return render(request, "accounts/orders.html", data)