Flush cache if user makes a document featured
authorSverre Rabbelier <srabbelier@gmail.com>
Wed, 28 Jan 2009 00:35:11 +0000
changeset 1019 0cd056f2c739
parent 1018 02ffb446da6e
child 1020 846fe3d821fb
Flush cache if user makes a document featured Also flush it if a new document is created as featured. Patch by: Sverre Rabbelier
app/soc/logic/models/document.py
--- a/app/soc/logic/models/document.py	Wed Jan 28 00:33:47 2009 +0000
+++ b/app/soc/logic/models/document.py	Wed Jan 28 00:35:11 2009 +0000
@@ -22,6 +22,7 @@
   ]
 
 
+from soc.cache import sidebar
 from soc.logic.models import work
 from soc.logic.models import linkable as linkable_logic
 
@@ -41,5 +42,21 @@
     super(Logic, self).__init__(model=model, base_model=base_model,
                                 scope_logic=scope_logic)
 
+  def _updateField(self, entity, name, value):
+    """Special logic for role. If state changes to active we flush the sidebar.
+    """
+
+    if (name == 'is_featured') and (entity.is_featured != value):
+      sidebar.flush()
+
+    return True
+
+  def _onCreate(self, entity):
+    """Flush the sidebar cache when a new active role entity has been created.
+    """
+
+    if entity.is_featured:
+      sidebar.flush()
+
 
 logic = Logic()