1- # -*- coding: utf-8 -*-
2- from __future__ import unicode_literals
3-
4- import json
51from base64 import b64encode
6-
7- try :
8- from collections import UserList
9- except ImportError : # Python 2
10- from UserList import UserList
11-
2+ from collections import UserList
3+ import json
124import warnings
135
14- from django import VERSION as DJANGO_VERSION
156from django .forms import forms
167from django .http import QueryDict
17- from django .utils import six
18- try :
19- from importlib import import_module
20- except ImportError :
21- from django .utils .importlib import import_module
228from django .utils .html import format_html , format_html_join , escape , conditional_escape
23- from django .utils .encoding import python_2_unicode_compatible , force_text
9+ from django .utils .encoding import force_text
2410from django .utils .module_loading import import_string
2511from django .utils .safestring import mark_safe , SafeText , SafeData
2612from django .core .exceptions import ValidationError , ImproperlyConfigured
@@ -35,7 +21,6 @@ class SafeTuple(SafeData, tuple):
3521 """
3622
3723
38- @python_2_unicode_compatible
3924class TupleErrorList (UserList , list ):
4025 """
4126 A list of errors, which in contrast to Django's ErrorList, can contain a tuple for each item.
@@ -209,12 +194,11 @@ def as_widget(self, widget=None, attrs=None, only_initial=False):
209194 if not widget :
210195 widget = self .field .widget
211196
212- if DJANGO_VERSION > (1 , 10 ):
213- # so that we can refer to the field when building the rendering context
214- widget ._field = self .field
215- # Make sure that NgWidgetMixin is not already part of the widget's bases so it doesn't get added twice.
216- if not isinstance (widget , NgWidgetMixin ):
217- widget .__class__ = type (widget .__class__ .__name__ , (NgWidgetMixin , widget .__class__ ), {})
197+ # so that we can refer to the field when building the rendering context
198+ widget ._field = self .field
199+ # Make sure that NgWidgetMixin is not already part of the widget's bases so it doesn't get added twice.
200+ if not isinstance (widget , NgWidgetMixin ):
201+ widget .__class__ = type (widget .__class__ .__name__ , (NgWidgetMixin , widget .__class__ ), {})
218202 return super (NgBoundField , self ).as_widget (widget , attrs , only_initial )
219203
220204 def build_widget_attrs (self , attrs , widget = None ):
@@ -297,15 +281,11 @@ def __init__(self, *args, **kwargs):
297281 try :
298282 form_name = self .form_name
299283 except AttributeError :
300- # if form_name is unset, then generate a pseudo unique name, based upon the class name
301- form_name = b64encode (six .b (self .__class__ .__name__ )).rstrip (six .b ('=' ))
302- if six .PY3 :
303- form_name = form_name .decode ('utf-8' )
284+ # if form_name is unset, generate a pseudo unique name, based upon the class name
285+ form_name = b64encode (self .__class__ .__name__ .encode ()).rstrip (b'=' ).decode ('utf-8' )
304286 self .form_name = kwargs .pop ('form_name' , form_name )
305287 error_class = kwargs .pop ('error_class' , TupleErrorList )
306288 kwargs .setdefault ('error_class' , error_class )
307- if DJANGO_VERSION < (1 , 11 ):
308- self .convert_widgets ()
309289 super (NgFormBaseMixin , self ).__init__ (* args , ** kwargs )
310290 if isinstance (self .data , QueryDict ):
311291 self .data = self .rectify_multipart_form_data (self .data .copy ())
@@ -364,19 +344,6 @@ def update_widget_attrs(self, bound_field, attrs):
364344 attrs .update ({'class' : widget_classes })
365345 return attrs
366346
367- def convert_widgets (self ):
368- """
369- During form initialization, some widgets have to be replaced by a counterpart suitable to
370- be rendered the AngularJS way.
371- """
372- warnings .warn ("Will be removed after dropping support for Django-1.10" , PendingDeprecationWarning )
373- widgets_module = getattr (self , 'widgets_module' , 'djng.widgets' )
374- for field in self .base_fields .values ():
375- if hasattr (field , 'get_converted_widget' ):
376- new_widget = field .get_converted_widget (widgets_module )
377- if new_widget :
378- field .widget = new_widget
379-
380347 def rectify_multipart_form_data (self , data ):
381348 """
382349 If a widget was converted and the Form data was submitted through a multipart request,
0 commit comments