Commits

Simon Meers  committed 8bb5871 Merge

Merged in aweakley/django-generic (pull request #1)

catch cook-id urls with no ids supplied even if there is no final second slash. Don't make requests for such lists if the ids list is empty.

  • Participants
  • Parent commits 5990ae3, 9c417f4

Comments (0)

Files changed (2)

File generic/admin/mixins/cooking.py

     def get_urls(self):
         return patterns(
             '',
-            url(r'^cook-ids/(?P<field_name>\w+)/(?P<raw_ids>.*)/$',
+            url(r'^cook-ids/(?P<field_name>\w+)/(?P<raw_ids>[^/]*)/?$',
                 self.admin_site.admin_view(self.cook_ids))
         ) + super(CookedIdAdmin, self).get_urls()
 

File generic/static/generic/js/cooked_id_widgets.js

                 );
                 var field_name = $(field).attr('name');
                 var ids = escape($(field).val());
-                var url_base = window.cooked_id_url_base || '../';
-                var cook_url =
-                    url_base + 'cook-ids/' + field_name + '/' + ids + '/';
-                $.get(cook_url, function(data){
-                    var cooked = $('.cooked-data', container);
-                    cooked.html('');
-                    $.each(data, function(key, name){
+                if (ids){
+                    var url_base = window.cooked_id_url_base || '../';
+                    var cook_url =
+                        url_base + 'cook-ids/' + field_name + '/' + ids + '/';
+                    $.get(cook_url, function(data){
+                        var cooked = $('.cooked-data', container);
+                        cooked.html('');
+                        $.each(data, function(key, name){
                         $('<li data-id="'+key+'"></li>').text(name).append(
                             ' <a onclick="remove_cooked_item();"' +
                             ' title="remove">&nbsp;</a>'
                         ).appendTo(cooked);
+                        });
                     });
-                });
+                }
             }
 
             window.remove_cooked_item = function(){