1. Sławek Ehlert
  2. django-selectable-select2

Commits

Sławek Ehlert  committed d8c50c0

use new style string formatting and adjust example and README to the latest changes on django-selectable

  • Participants
  • Parent commits 52a8a21
  • Branches default

Comments (0)

Files changed (6)

File README.rst

View file
  • Ignore whitespace
 This project is a kind of a plugin for `django-selectable`_.
 
 It provides widgets for use with a great JS library called `select2`_ rather than jQuery UI.
-It also provides it's own Lookup classes for better (IMO) serialization results and limiting results (on server side).
 
 For now there's only a basic single-valued autocomplete widget for usage on ForeignKey (or simply ModelChoiceField) fields.
 
         ...
     )
 
+* add/change a setting ``SELECTABLE_ESCAPED_KEYS`` like this::
+
+    SELECTABLE_ESCAPED_KEYS = ('label', 'value')
+
+
 Usage
 ============
 
 
 check out `TODO.rst`
 
+A note about version of django-selectable
+===========================================
+
+The minimal version of django-selectable that is required for this app is
+0.6
 
 A note about version of select2.js used here
 ==============================================

File example/core/lookups.py

View file
  • Ignore whitespace
 from django.contrib.auth.models import User
 
-from selectable_select2.base import ModelLookup, LookupBase
+# from selectable_select2.base import ModelLookup, LookupBase
+from selectable.base import ModelLookup, LookupBase
 from selectable.registry import registry
 
 from example.core.models import Fruit, City
         return results
 
     def get_item_label(self, item):
-        return u"%s, %s" % (item.name, item.state)
+        return u"{0}, {1}".format(item.name, item.state)
 
 
 class CityLookup(ModelLookup):
     search_fields = ('name__icontains', )
 
     def get_item_label(self, item):
-        return u"%s, %s" % (item.name, item.state)
+        return u"{0}, {1}".format(item.name, item.state)
 
 
 registry.register(CityLookup)

File example/core/models.py

View file
  • Ignore whitespace
     fruit = models.ManyToManyField(Fruit)
 
     def __unicode__(self):
-        return u"%s's Farm: %s" % (self.owner.username, self.name)
+        return u"{0}'s Farm: {1}".format(self.owner.username, self.name)
 
 
 class City(models.Model):
         return ('example-detail', [str(self.id)])
 
     def __unicode__(self):
-        ret = u"%s: %s - %s - %s" % (str(self.pk), self.city, self.fruit, self.fruit2)
+        ret = u"{0}: {1} - {2} - {3}".format(str(self.pk), self.city, self.fruit, self.fruit2)
         if self.farm:
-            ret += u" - %s" % self.farm
+            ret += u" - {0}".format(self.farm)
         return ret

File example/core/templates/base.html

View file
  • Ignore whitespace
     {% block content %}
     <div class="row">
         <div class="span8">
-            <form action="" method="post" class="well form-horizontal">
+            <form action="." method="post" class="well form-horizontal">
                 {% csrf_token %}
             {% comment %}
 

File example/settings.py

View file
  • Ignore whitespace
 
 PROJECT_PATH = os.path.dirname(__file__)
 
+SELECTABLE_ESCAPED_KEYS = ('label', 'value')
+
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
 

File selectable_select2/widgets.py

View file
  • Ignore whitespace
 
 MEDIA_URL = settings.MEDIA_URL
 STATIC_URL = getattr(settings, 'STATIC_URL', u'')
-MEDIA_PREFIX = u'%sselectable_select2/' % (STATIC_URL or MEDIA_URL)
+MEDIA_PREFIX = u'{0}selectable_select2/'.format(STATIC_URL or MEDIA_URL)
 
 # these are the kwargs that u can pass when instantiating the widget
 TRANSFERABLE_ATTRS = ('placeholder', 'initial_selection', 'parents', 'clearonparentchange')
 
     class Media(object):
         css = {
-            'all': (u'%scss/select2.css' % MEDIA_PREFIX,)
+            'all': (u'{0}css/select2.css'.format(MEDIA_PREFIX),)
         }
         js = (
-            u'%sjs/jquery.django.admin.fix.js' % MEDIA_PREFIX,
-            u'%sjs/select2.min.js' % MEDIA_PREFIX,
-            u'%sjs/jquery.dj.selectable.select2.js' % MEDIA_PREFIX,
+            u'{0}js/jquery.django.admin.fix.js'.format(MEDIA_PREFIX),
+            u'{0}js/select2.min.js'.format(MEDIA_PREFIX),
+            u'{0}js/jquery.dj.selectable.select2.js'.format(MEDIA_PREFIX),
         )
 
 
             attr = real_attr.replace('_', '-')
             value = getattr(self, real_attr)
             if real_attr in SERIALIZABLE_ATTRS:
-                value = json.dumps(value).strip('"')
+                value = json.dumps(value)
             attrs[u'data-' + attr] = value
 
         attrs[u'data-selectable-type'] = 'select2'