def put(self, *args, **kwargs): create = not self.is_saved() if create: self.subtree_cacheable = self.cacheable self.linked_url_node_keys = [ str(node.key()) for node in self._get_linked_url_nodes()] super(Widget, self).put(**kwargs) if not self.cacheable: assert not self.subtree_cacheable, ( '"%s" is uncacheable, therefore its subtree must ' 'also be uncacheable.' % self.__class__.__name__) if self.element_parent: if (not self.subtree_cacheable and self.element_parent.subtree_cacheable): self.element_parent.subtree_cacheable = False self.element_parent.put() if (self.subtree_cacheable and not self.element_parent.subtree_cacheable): self.element_parent.update_subtree_cacheable() invalidate_caches_for_node(self)
def delete(self, **kwargs): parent_should_update = False if self.element_parent: parent = self.element_parent parent_should_update = not self.subtree_cacheable invalidate_caches_for_node(self) super(Widget, self).delete(**kwargs) if parent_should_update: parent.update_subtree_cacheable()
def put(self, **kwargs): this_is_root = not isinstance(self.url_parent, URLNode) parent_is_root = ( not this_is_root and not isinstance( self.url_parent.url_parent, URLNode)) if this_is_root: prefix = '' else: prefix = self.url_parent.denormalized_url if parent_is_root and not self.url_parent.url_fragment: self.denormalized_url = prefix + self.url_fragment else: self.denormalized_url = '%s/%s' % (prefix, self.url_fragment) # Need to compare the underlying value which was last retrieved # from the datastore before put(). url_changed = self.property_changed('denormalized_url') super(URLNode, self).put(**kwargs) if url_changed: # TODO: Requires test # Re-put all children, in order to update their URLs, causing # the entire subtree to be updated. for child in get_direct_url_node_children(self): child.put() # TODO: Requires test widgets = ( Widget.all() .filter('linked_url_node_keys =', str(self.key())).fetch(None) ) for widget in widgets: invalidate_caches_for_node(widget)