Mark Lavin avatar Mark Lavin committed aabc63a

Adding unicode_literals and removing u prefixes from strings.

Comments (0)

Files changed (14)

selectable/__init__.py

 "Auto-complete selection widgets using Django and jQuery UI."
 
 
-__version__ = '0.7.0dev'
+__version__ = '0.7.0dev'

selectable/base.py

 "Base classes for lookup creation."
+from __future__ import unicode_literals
 
 import json
 import operator
     def _name(cls):
         app_name = cls.__module__.split('.')[-2].lower()
         class_name = cls.__name__.lower()
-        name = u'%s-%s' % (app_name, class_name)
+        name = '%s-%s' % (app_name, class_name)
         return name
     name = classmethod(_name)
 

selectable/decorators.py

 "Decorators for additional lookup functionality."
+from __future__ import unicode_literals
 
 from functools import wraps
 

selectable/forms/base.py

+from __future__ import unicode_literals
+
 from django import forms
 from django.conf import settings
 

selectable/forms/fields.py

+from __future__ import unicode_literals
+
 from django import forms
 from django.core.exceptions import ValidationError
 from django.core.validators import EMPTY_VALUES
     widget = AutoCompleteSelectWidget
 
     default_error_messages = {
-        'invalid_choice': _(u'Select a valid choice. That choice is not one of the available choices.'),
+        'invalid_choice': _('Select a valid choice. That choice is not one of the available choices.'),
     }
 
     def __init__(self, lookup_class, *args, **kwargs):
     widget = AutoCompleteSelectMultipleWidget
 
     default_error_messages = {
-        'invalid_choice': _(u'Select a valid choice. That choice is not one of the available choices.'),
+        'invalid_choice': _('Select a valid choice. That choice is not one of the available choices.'),
     }
 
     def __init__(self, lookup_class, *args, **kwargs):

selectable/forms/widgets.py

+from __future__ import unicode_literals
+
 import json
 
 from django import forms
 )
 
 
-STATIC_PREFIX = u'%sselectable/' % settings.STATIC_URL
+STATIC_PREFIX = '%sselectable/' % settings.STATIC_URL
 
 
 class SelectableMediaMixin(object):
 
     class Media(object):
         css = {
-            'all': (u'%scss/dj.selectable.css' % STATIC_PREFIX, )
+            'all': ('%scss/dj.selectable.css' % STATIC_PREFIX, )
         }
-        js = (u'%sjs/jquery.dj.selectable.js' % STATIC_PREFIX, )
+        js = ('%sjs/jquery.dj.selectable.js' % STATIC_PREFIX, )
 
 
 class AutoCompleteWidget(forms.TextInput, SelectableMediaMixin):
             self.qs['limit'] = self.limit
         if self.qs:
             url = '%s?%s' % (url, urlencode(self.qs))
-        if u'data-selectable-options' in attrs:
-            attrs[u'data-selectable-options'] = json.dumps(attrs[u'data-selectable-options'])
-        attrs[u'data-selectable-url'] = url
-        attrs[u'data-selectable-type'] = 'text'
-        attrs[u'data-selectable-allow-new'] = str(self.allow_new).lower()
+        if 'data-selectable-options' in attrs:
+            attrs['data-selectable-options'] = json.dumps(attrs['data-selectable-options'])
+        attrs['data-selectable-url'] = url
+        attrs['data-selectable-type'] = 'text'
+        attrs['data-selectable-allow-new'] = str(self.allow_new).lower()
         return attrs
 
 
                 limit=self.limit, query_params=query_params,
                 attrs=kwargs.get('attrs'),
             ),
-            forms.HiddenInput(attrs={u'data-selectable-type': 'hidden'})
+            forms.HiddenInput(attrs={'data-selectable-type': 'hidden'})
         ]
         super(AutoCompleteSelectWidget, self).__init__(widgets, *args, **kwargs)
 
 
     def build_attrs(self, extra_attrs=None, **kwargs):
         attrs = super(AutoComboboxWidget, self).build_attrs(extra_attrs, **kwargs)
-        attrs[u'data-selectable-type'] = 'combobox'
+        attrs['data-selectable-type'] = 'combobox'
         return attrs
 
 
                 limit=self.limit, query_params=query_params,
                 attrs=kwargs.get('attrs'),
             ),
-            forms.HiddenInput(attrs={u'data-selectable-type': 'hidden'})
+            forms.HiddenInput(attrs={'data-selectable-type': 'hidden'})
         ]
         super(AutoComboboxSelectWidget, self).__init__(widgets, *args, **kwargs)
 
             if v:
                 item = item or lookup.get_item(v)
                 input_attrs['title'] = lookup.get_item_value(item)
-            inputs.append(u'<input%s />' % flatatt(input_attrs))
-        return mark_safe(u'\n'.join(inputs))
+            inputs.append('<input%s />' % flatatt(input_attrs))
+        return mark_safe('\n'.join(inputs))
 
     def build_attrs(self, extra_attrs=None, **kwargs):
         attrs = super(LookupMultipleHiddenInput, self).build_attrs(extra_attrs, **kwargs)
-        attrs[u'data-selectable-type'] = 'hidden-multiple'
+        attrs['data-selectable-type'] = 'hidden-multiple'
         return attrs
 
 
         self.limit = kwargs.pop('limit', None)
         position = kwargs.pop('position', 'bottom')
         attrs = {
-            u'data-selectable-multiple': 'true',
-            u'data-selectable-position': position
+            'data-selectable-multiple': 'true',
+            'data-selectable-position': position
         }
         attrs.update(kwargs.get('attrs', {}))
         query_params = kwargs.pop('query_params', {})
     def render(self, name, value, attrs=None):
         if value and not hasattr(value, '__iter__'):
             value = [value]
-        value = [u'', value]
+        value = ['', value]
         return super(AutoCompleteSelectMultipleWidget, self).render(name, value, attrs)
 
 
         self.limit = kwargs.pop('limit', None)
         position = kwargs.pop('position', 'bottom')
         attrs = {
-            u'data-selectable-multiple': 'true',
-            u'data-selectable-position': position
+            'data-selectable-multiple': 'true',
+            'data-selectable-position': position
         }
         attrs.update(kwargs.get('attrs', {}))
         query_params = kwargs.pop('query_params', {})
     def render(self, name, value, attrs=None):
         if value and not hasattr(value, '__iter__'):
             value = [value]
-        value = [u'', value]
+        value = ['', value]
         return super(AutoComboboxSelectMultipleWidget, self).render(name, value, attrs)
 

selectable/models.py

+from __future__ import unicode_literals
+
 from django.conf import settings
 
 # Set default settings

selectable/registry.py

+from __future__ import unicode_literals
+
 import warnings
 
 from django.utils.encoding import force_unicode
 
     def validate(self, lookup):
         if not issubclass(lookup, LookupBase):
-            raise LookupInvalid(u'Registered lookups must inherit from the LookupBase class')
+            raise LookupInvalid('Registered lookups must inherit from the LookupBase class')
 
     def register(self, lookup):
         self.validate(lookup)
         name = force_unicode(lookup.name())
         if name in self._registry:
-            raise LookupAlreadyRegistered(u'The name %s is already registered' % name)
+            raise LookupAlreadyRegistered('The name %s is already registered' % name)
         self._registry[name] = lookup
 
     def unregister(self, lookup):
         self.validate(lookup)
         name = force_unicode(lookup.name())
         if name not in self._registry:
-           raise LookupNotRegistered(u'The name %s is not registered' % name)
+           raise LookupNotRegistered('The name %s is not registered' % name)
         del self._registry[name]
 
     def get(self, key):

selectable/templatetags/selectable_tags.py

-# -*- encoding: utf-8 -*-
+from __future__ import unicode_literals
+
 from django import template
 from django.conf import settings
 

selectable/tests/base.py

+from __future__ import unicode_literals
+
 import random
 import string
 from xml.dom.minidom import parseString
     urls = 'selectable.tests.urls'
 
     def get_random_string(self, length=10):
-        return u''.join(random.choice(string.ascii_letters) for x in xrange(length))
+        return ''.join(random.choice(string.ascii_letters) for x in xrange(length))
 
     def create_thing(self, data=None):
         data = data or {}

selectable/tests/forms.py

     def test_valid_data(self):
         data = self.get_valid_data()
         form = BaseLookupForm(data)
-        self.assertTrue(form.is_valid(), u"%s" % form.errors)
+        self.assertTrue(form.is_valid(), "%s" % form.errors)
 
     def test_invalid_limit(self):
         """
         if 'limit' in data:
             del data['limit']
         form = BaseLookupForm(data)
-        self.assertTrue(form.is_valid(), u"%s" % form.errors)
+        self.assertTrue(form.is_valid(), "%s" % form.errors)
         self.assertEqual(form.cleaned_data['limit'], settings.SELECTABLE_MAX_LIMIT)
 
     def test_no_max_set(self):
         settings.SELECTABLE_MAX_LIMIT = None
         data = self.get_valid_data()
         form = BaseLookupForm(data)
-        self.assertTrue(form.is_valid(), u"%s" % form.errors)
+        self.assertTrue(form.is_valid(), "%s" % form.errors)
         if 'limit' in data:
             self.assertTrue(form.cleaned_data['limit'], data['limit'])
 
         if 'limit' in data:
             del data['limit']
         form = BaseLookupForm(data)
-        self.assertTrue(form.is_valid(), u"%s" % form.errors)
+        self.assertTrue(form.is_valid(), "%s" % form.errors)
         self.assertFalse(form.cleaned_data.get('limit'))
 
     def test_over_limit(self):
         data = self.get_valid_data()
         data['limit'] = settings.SELECTABLE_MAX_LIMIT + 100
         form = BaseLookupForm(data)
-        self.assertTrue(form.is_valid(), u"%s" % form.errors)
+        self.assertTrue(form.is_valid(), "%s" % form.errors)
         self.assertEqual(form.cleaned_data['limit'], settings.SELECTABLE_MAX_LIMIT)

selectable/tests/functests.py

 """
 Larger functional tests for fields and widgets.
 """
+from __future__ import unicode_literals
 
 from django import forms
 
         data = {
             'name': self.get_random_string(),
             'thing_0': self.test_thing.name, # Text input
-            'thing_1': u'', # Hidden input
+            'thing_1': '', # Hidden input
         }
         form = OtherThingForm(data=data)
-        self.assertFalse(form.is_valid(), u'Form should not be valid')
+        self.assertFalse(form.is_valid(), 'Form should not be valid')
         self.assertFalse('name' in form.errors)
         self.assertTrue('thing' in form.errors)
 
     def test_invalid_form_missing_name(self):
         "Invalid form using an AutoCompleteSelectField."
         data = {
-            'name': u'',
+            'name': '',
             'thing_0': self.test_thing.name, # Text input
             'thing_1': self.test_thing.pk, # Hidden input
         }
         form = OtherThingForm(data=data)
-        self.assertFalse(form.is_valid(), u'Form should not be valid')
+        self.assertFalse(form.is_valid(), 'Form should not be valid')
         self.assertTrue('name' in form.errors)
         self.assertFalse('thing' in form.errors)
 
     def test_invalid_but_still_selected(self):
         "Invalid form should keep selected item."
         data = {
-            'name': u'',
+            'name': '',
             'thing_0': self.test_thing.name, # Text input
             'thing_1': self.test_thing.pk, # Hidden input
         }
         form = OtherThingForm(data=data)
-        self.assertFalse(form.is_valid(), u'Form should not be valid')
+        self.assertFalse(form.is_valid(), 'Form should not be valid')
         rendered_form = form.as_p()
         inputs = parsed_inputs(rendered_form)
         # Selected text should be populated
         data = {
             'name': self.get_random_string(),
             'thing_0': self.test_thing.name, # Text input
-            'thing_1': u'', # Hidden input missing
+            'thing_1': '', # Hidden input missing
         }
         form = SelectWidgetForm(data=data)
         self.assertFalse(form.is_valid())
         data = {
             'name': self.get_random_string(),
             'thing_0': self.test_thing.name, # Text input
-            'thing_1': u'XXX', # Hidden input doesn't match a PK
+            'thing_1': 'XXX', # Hidden input doesn't match a PK
         }
         form = SelectWidgetForm(data=data)
         self.assertFalse(form.is_valid())
         data = {
             'name': self.get_random_string(),
             'thing_0': self.test_thing.name, # Text input
-            'thing_1': u'', # Hidden input missing
+            'thing_1': '', # Hidden input missing
         }
         form = SelectWidgetForm(data=data)
         self.assertFalse(form.is_valid())
         data = {
             'name': self.get_random_string(),
             'thing_0': self.test_thing.name, # Text input
-            'thing_1': u'XXX', # Hidden input doesn't match a PK
+            'thing_1': 'XXX', # Hidden input doesn't match a PK
         }
         form = SelectWidgetForm(data=data)
         self.assertFalse(form.is_valid())
         "Valid form using an AutoCompleteSelectMultipleField."
         data = {
             'name': self.get_random_string(),
-            'things_0': u'', # Text input
+            'things_0': '', # Text input
             'things_1': [self.test_thing.pk, ], # Hidden inputs
         }
         form = ManyThingForm(data=data)
         "Saving data from a valid form."
         data = {
             'name': self.get_random_string(),
-            'things_0': u'', # Text input
+            'things_0': '', # Text input
             'things_1': [self.test_thing.pk, ], # Hidden inputs
         }
         form = ManyThingForm(data=data)
         "Valid form where many to many is not required."
         data = {
             'name': self.get_random_string(),
-            'things_0': u'', # Text input
+            'things_0': '', # Text input
             'things_1': [], # Hidden inputs
         }
         form = ManyThingForm(data=data)
         "Saving data when many to many is not required."
         data = {
             'name': self.get_random_string(),
-            'things_0': u'', # Text input
+            'things_0': '', # Text input
             'things_1': [], # Hidden inputs
         }
         form = ManyThingForm(data=data)

selectable/views.py

+from __future__ import unicode_literals
+
 from django.http import HttpResponse, Http404
 
 from selectable.registry import registry
 
     lookup_cls = registry.get(lookup_name)
     if lookup_cls is None:
-        raise Http404(u'Lookup %s not found' % lookup_name)
+        raise Http404('Lookup %s not found' % lookup_name)
 
     lookup = lookup_cls()
     return lookup.results(request)
     include_package_data=True,
     url='http://bitbucket.org/mlavin/django-selectable',
     license='BSD',
-    description=u' '.join(__import__('selectable').__doc__.splitlines()).strip(),
+    description=' '.join(__import__('selectable').__doc__.splitlines()).strip(),
     classifiers=[
         'Intended Audience :: Developers',
         'License :: OSI Approved :: BSD License',
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.