test: Use django_stubs_ext.QuerySetAny for isinstance() checks
mypy complains if QuerySet is used because it uses a parameterized generic type.
This commit is contained in:
parent
7ad74c99e4
commit
68eb685382
|
@ -11,9 +11,10 @@ from django.core.serializers.json import Serializer
|
|||
from django.http import HttpResponse
|
||||
from django.utils.encoding import smart_str
|
||||
from django.db.models import Field
|
||||
from django.db.models.query import QuerySet
|
||||
from django.db.models.signals import post_save, post_delete, m2m_changed
|
||||
|
||||
from django_stubs_ext import QuerySetAny
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
||||
|
@ -145,7 +146,7 @@ class AdminJsonSerializer(Serializer):
|
|||
field_value = None
|
||||
else:
|
||||
field_value = field
|
||||
if isinstance(field_value, QuerySet) or isinstance(field_value, list):
|
||||
if isinstance(field_value, QuerySetAny) or isinstance(field_value, list):
|
||||
self._current[name] = dict([ (rel.pk, self.expand_related(rel, name)) for rel in field_value ])
|
||||
else:
|
||||
if hasattr(field_value, "_meta"):
|
||||
|
|
|
@ -13,11 +13,11 @@ from email.utils import parseaddr
|
|||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ObjectDoesNotExist, ValidationError
|
||||
from django.db.models.query import QuerySet
|
||||
from django.forms.utils import ErrorList
|
||||
from django.db.models import Q
|
||||
#from django.forms.widgets import RadioFieldRenderer
|
||||
from django.core.validators import validate_email
|
||||
from django_stubs_ext import QuerySetAny
|
||||
|
||||
import debug # pyflakes:ignore
|
||||
|
||||
|
@ -203,7 +203,7 @@ class SearchLiaisonForm(forms.Form):
|
|||
class CustomModelMultipleChoiceField(forms.ModelMultipleChoiceField):
|
||||
'''If value is a QuerySet, return it as is (for use in widget.render)'''
|
||||
def prepare_value(self, value):
|
||||
if isinstance(value, QuerySet):
|
||||
if isinstance(value, QuerySetAny):
|
||||
return value
|
||||
if (hasattr(value, '__iter__') and
|
||||
not isinstance(value, str) and
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
|
||||
|
||||
from django.urls import reverse as urlreverse
|
||||
from django.db.models.query import QuerySet
|
||||
from django.forms.widgets import Widget
|
||||
from django.utils.safestring import mark_safe
|
||||
from django.utils.html import conditional_escape
|
||||
|
||||
from django_stubs_ext import QuerySetAny
|
||||
|
||||
|
||||
class ButtonWidget(Widget):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -34,7 +35,7 @@ class ShowAttachmentsWidget(Widget):
|
|||
html = '<div id="id_%s">' % name
|
||||
html += '<span class="d-none showAttachmentsEmpty form-control widget">No files attached</span>'
|
||||
html += '<div class="attachedFiles form-control widget">'
|
||||
if value and isinstance(value, QuerySet):
|
||||
if value and isinstance(value, QuerySetAny):
|
||||
for attachment in value:
|
||||
html += '<a class="initialAttach" href="%s">%s</a> ' % (conditional_escape(attachment.document.get_href()), conditional_escape(attachment.document.title))
|
||||
html += '<a class="btn btn-primary btn-sm" href="{}">Edit</a> '.format(urlreverse("ietf.liaisons.views.liaison_edit_attachment", kwargs={'object_id':attachment.statement.pk,'doc_id':attachment.document.pk}))
|
||||
|
@ -43,4 +44,4 @@ class ShowAttachmentsWidget(Widget):
|
|||
else:
|
||||
html += 'No files attached'
|
||||
html += '</div></div>'
|
||||
return mark_safe(html)
|
||||
return mark_safe(html)
|
||||
|
|
Loading…
Reference in a new issue