Mark Lavin avatar Mark Lavin committed 257675b

Include the pagination label to be translated on the server in the meta and update the JS code to include the link item.

Comments (0)

Files changed (2)

selectable/base.py

 from django.utils import simplejson as json
 from django.utils.encoding import smart_unicode
 from django.utils.html import conditional_escape
-#from django.utils.translation import ugettext as _
+from django.utils.translation import ugettext as _
 
 from selectable.forms import BaseLookupForm
-from selectable.forms.base import DEFAULT_LIMIT as MAX_LIMIT
 
 
 __all__ = (
     "Base class for all django-selectable lookups."
 
     form = BaseLookupForm
-    max_limit = MAX_LIMIT
 
     def _name(cls):
         app_name = cls.__module__.split('.')[-2].lower()
         results = {}
         form = self.form(request.GET)
         if form.is_valid():
-
-            options = self._get_options(form)
+            options = form.cleaned_data
             term, limit = options['term'], options['limit']
             raw_data = self.get_query(request, term)
             page_data = self.paginate_results(request, raw_data, limit)
         content = self.get_content(results)
         return self.get_response(content, 'application/json')
 
-    def _get_options(self, valid_form):
-        '''
-        Returns a dictionary of options from a valid lookup form instance.
-        `term` and `limit` are required
-        '''
-        term = valid_form.cleaned_data.get('term', '')
-        limit = valid_form.cleaned_data.get('limit', self.max_limit)
-
-        # check if provided limit isn't bigger than max_limit
-        if limit and self.max_limit and limit > self.max_limit:
-            limit = self.max_limit
-
-        return {'term' : term, 'limit' : limit}
-
     def format_results(self, page_data, options):
         '''
         Returns a python structure that later gets serialized.
         '''
         results = {}
         meta = options.copy()
+        meta['more'] = _('Show more results')
 
         if page_data and hasattr(page_data, 'has_next') and page_data.has_next():
             meta.update( {

selectable/static/selectable/js/jquery.dj.selectable.js

                 }
                 function unwrapResponse(data) {
                     var results = data.data;
+                    var meta = data.meta;
+                    if (meta.next_page && meta.more) {
+                        results.push({
+                            id: '',
+                            value: '',
+                            label: meta.more,
+                            page: meta.next_page
+                        });
+                    }
                     return response(results);
                 }   
 				$.getJSON(url, query, unwrapResponse);
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.