Commits

Simon Meers committed a4b1745

Allow disabling of <optgroup>s, and tidy up templatetags code.

  • Participants
  • Parent commits c0b95be

Comments (0)

Files changed (2)

genericadmin/templates/admin/genericadmin/genericadmin.js

             this.lookupLink.hide();
         }
         
+        {% if USE_OPTGROUPS %}
         // Create optgroups
         opt_keys = [];
         opt_dict = {};
                 $opt_group.append(el);
             }
         }
+        {% endif %}
         
         $(this.contentTypeEl).change(function() {
             self.contentTypeId = this.value;    // Set our objectId when the content_type is changed

genericadmin/templatetags/genericadmin.py

 from django import template
+from django.conf import settings
 from django.contrib.contenttypes.models import ContentType
 
 register = template.Library()
 
 class do_get_generic_objects(template.Node):
-	def __init__(self):
-		pass
+    def render(self, context):
+        context['USE_OPTGROUPS'] = getattr(
+            settings, 'GENERICADMIN_OPTGROUPS', True)
+        return_string = "var MODEL_URL_ARRAY = {"
+        for c in ContentType.objects.all().order_by('id'):
+            return_string = "%s%d: '%s/%s'," % (
+                return_string, c.id, c.app_label, c.model)
+        return_string = "%s}" % return_string[:-1]
+        return return_string
 
-	def render(self, context):
-		return_string = "var MODEL_URL_ARRAY = {"
-		for c in ContentType.objects.all().order_by('id'):
-			return_string = "%s%d: '%s/%s'," % (return_string, c.id, c.app_label, c.model)
-		return_string = "%s}" % return_string[:-1]
-		return return_string
-		
-
+@register.tag
 def get_generic_relation_list(parser, token):
     """
-    Returns a list of installed applications and models for which the current user
-    has at least one permission.
+    Returns a list of installed applications and models for which the current
+    user has at least one permission.
+
+    Also throws GENERICADMIN_OPTGROUPS boolean setting into the context as
+    USE_OPTGROUPS.
 
     Syntax::
-    
+
         {% get_generic_relation_list %}
 
     """
     tokens = token.contents.split()
     return do_get_generic_objects()
 
-register.tag('get_generic_relation_list', get_generic_relation_list)