Skip to content

Commit

Permalink
Fixes #4500, collections depreciated (#4541)
Browse files Browse the repository at this point in the history
* Fixes #4500, collections depreciation

Collections will be removed as of Python 3.10, Added Compatibility for versions < 3.3.

* Added Depreciation Check for Python 3.3+

* Removed if/else, added try/except

* Remove unused 'sys' library (whoops)
  • Loading branch information
Metropass authored Sep 29, 2020
1 parent 771844b commit 264054c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions kitsune/wiki/widgets.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import collections

from django import forms
from django.template.loader import render_to_string

from kitsune.products.models import Topic
from kitsune.wiki.models import Document

try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable


class ProductTopicsAndSubtopicsWidget(forms.widgets.SelectMultiple):
"""A widget to render topics organized by product and with subtopics."""
Expand Down Expand Up @@ -35,7 +39,7 @@ def process_topic(self, value, topic):
topic.checked = True
elif (
not isinstance(value, str)
and isinstance(value, collections.Iterable)
and isinstance(value, Iterable)
and topic.id in value
):
topic.checked = True
Expand All @@ -49,7 +53,7 @@ class RelatedDocumentsWidget(forms.widgets.SelectMultiple):
def render(self, name, value, attrs=None, renderer=None):
if isinstance(value, int):
related_documents = Document.objects.filter(id__in=[value])
elif not isinstance(value, str) and isinstance(value, collections.Iterable):
elif not isinstance(value, str) and isinstance(value, Iterable):
related_documents = Document.objects.filter(id__in=value)
else:
related_documents = Document.objects.none()
Expand Down

0 comments on commit 264054c

Please sign in to comment.