def test_normalize_querydict(self): self.assertDictEqual( normalize_querydict(QueryDict('foo=1&bar=2&bar=3&baz=')), { 'foo': '1', 'bar': ['2', '3'], 'baz': '' })
def get(self, request, *args, **kwargs): # Parse initial data manually to avoid setting field values as lists initial_data = normalize_querydict(request.GET) form = self.model_form(instance=self.obj, initial=initial_data) return render( request, self.template_name, { 'obj': self.obj, 'obj_type': self.model._meta.verbose_name, 'form': form, 'return_url': self.get_return_url(request, self.obj), })
def get(self, request, *args, **kwargs): obj = self.alter_obj(self.get_object(kwargs), request, args, kwargs) initial_data = normalize_querydict(request.GET) form = self.model_form(instance=obj, initial=initial_data) return render( request, self.template_name, { 'obj': obj, 'obj_type': self.queryset.model._meta.verbose_name, 'form': form, 'return_url': self.get_return_url(request, obj), })
def get(self, request, module, name): script = self._get_script(name, module) form = script.as_form(initial=normalize_querydict(request.GET)) # Look for a pending JobResult (use the latest one by creation timestamp) script_content_type = ContentType.objects.get(app_label='extras', model='script') script.result = JobResult.objects.filter( obj_type=script_content_type, name=script.full_name, ).exclude( status__in=JobResultStatusChoices.TERMINAL_STATE_CHOICES).first() return render(request, 'extras/script.html', { 'module': module, 'script': script, 'form': form, })