Disable selects when content is set as public + replace To_protect class by function with setattr
authorverrierj
Fri, 16 Dec 2011 17:19:22 +0100
changeset 292 48d9e8297287
parent 291 bd1c08c872ac
child 293 4fd110c8fa26
Disable selects when content is set as public + replace To_protect class by function with setattr
src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html
src/ldt/ldt/security/utils.py
--- a/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Fri Dec 16 16:42:08 2011 +0100
+++ b/src/ldt/ldt/ldt_utils/templates/ldt/ldt_utils/create_content.html	Fri Dec 16 17:19:22 2011 +0100
@@ -31,6 +31,16 @@
 	<script type="text/javascript">
 	window.__admin_media_prefix__ = "{% filter escapejs %}{% admin_media_prefix %}{% endfilter %}";
 	
+	function public_checkbox (checkbox) {		
+		if (checkbox.is(":checked")) {
+			$("#removeall").trigger("click");
+			$("#sharelist option").css('color', '');
+			$("#sharelist, #selectedlist").attr("disabled", "disabled");
+		} else {
+			$("#sharelist, #selectedlist").removeAttr("disabled");
+		}
+	}
+	
 	$(document).ready(function() {
 		// url_upload, media_prefix, post_added_params, btn_label, success_label, wait_label, cancel_label, remove_url, get_dur_url
 		post_added_params = {"csrfmiddlewaretoken" : "{{csrf_token}}",
@@ -45,6 +55,12 @@
 							'{% trans "Cancel upload" %}',
 							"{% url ldt.ldt_utils.views.remove_temp_file %}",
 							"{% url ldt.ldt_utils.views.get_duration %}");
+		
+		$("#public input").change(function () {
+			public_checkbox($(this));		
+		});
+		
+		public_checkbox($("#public input"));
 			
 	});
 	
--- a/src/ldt/ldt/security/utils.py	Fri Dec 16 16:42:08 2011 +0100
+++ b/src/ldt/ldt/security/utils.py	Fri Dec 16 17:19:22 2011 +0100
@@ -20,30 +20,27 @@
     del _thread_locals.user
     
 def protect_models():
-    cls_list = ToProtect.get_models()
+    cls_list = get_models_to_protect()
     if cls_list:
         user = get_current_user()
-        for cls in ToProtect.get_models():
+        for cls in get_models_to_protect():
                 protect_model(cls, user)    
     
 def unprotect_models():
-    for cls in ToProtect.get_models():
+    for cls in get_models_to_protect():
             unprotect_model(cls)
 
-class ToProtect(object):
-    
-    @staticmethod
-    def get_models():
-        if hasattr(ToProtect, 'cls_list'):
-            return ToProtect.cls_list
+def get_models_to_protect():
+    if hasattr(get_models_to_protect, 'cls_list'):
+        return get_models_to_protect.cls_list
         
-        cls_list = []
-        for cls_name in settings.USE_GROUP_PERMISSIONS:
-            cls_type = ContentType.objects.get(model=cls_name.lower())
-            cls_list.append(cls_type.model_class())
-        ToProtect.cls_list = cls_list
+    cls_list = []
+    for cls_name in settings.USE_GROUP_PERMISSIONS:
+        cls_type = ContentType.objects.get(model=cls_name.lower())
+        cls_list.append(cls_type.model_class())
+    get_models_to_protect.cls_list = cls_list
         
-        return cls_list
+    return cls_list
 
 def protect_model(cls, user):   
     cls.safe_objects.user = user
@@ -89,7 +86,6 @@
     
     return xml
 
-
 def add_change_attr(user, obj_list):
     """ 
      Add a change attribute set to True to objects of obj_list