enable remove unused annotations in mashupbytag
authorcavaliet
Fri, 14 Dec 2012 17:48:30 +0100
changeset 1030 581c7906ebb4
parent 1029 9bd66b69effc
child 1031 04f8cf193221
enable remove unused annotations in mashupbytag
src/ldt/ldt/ldt_utils/views/json.py
--- a/src/ldt/ldt/ldt_utils/views/json.py	Thu Dec 13 17:42:29 2012 +0100
+++ b/src/ldt/ldt/ldt_utils/views/json.py	Fri Dec 14 17:48:30 2012 +0100
@@ -172,6 +172,18 @@
                         mashup_list["items"].append(res["element_id"])
             mashup_dict["lists"].append(mashup_list)
     
+            # If asked, we remove the annotations not used in the mashup.
+            # It enabled a lighter response 
+            remove_not_used_str = request.REQUEST.get("removenotused")
+            remove_not_used = False
+            if remove_not_used_str:
+                remove_not_used = {'true': True, 'false': False, "0": False, "1": True}.get(remove_not_used_str.lower())
+            if remove_not_used:
+                for a in mashup_dict["annotations"]:
+                    if a["id"] not in mashup_list["items"]:
+                        mashup_dict["annotations"].remove(a)
+    
+    
     json_str = simplejson.dumps(mashup_dict, ensure_ascii=False, indent=indent)
     if escape_bool:
         json_str = escape(json_str)