def all_refs(self): refs = [] for vs in self: try: content_nodes = vs.index.nodes.get_leaf_nodes() except Exception as e: logger.warning( u"Failed to find VersionState Index while generating references for {}. {}" .format(vs.title, e.message)) continue for c in content_nodes: try: state_ja = vs.state_node(c).ja("all") for indxs in state_ja.non_empty_sections(): sections = [a + 1 for a in indxs] refs += [ Ref( _obj={ "index": vs.index, "book": vs.index.nodes.full_title("en"), "type": vs.index.categories[0], "index_node": c, "sections": sections, "toSections": sections }) ] except Exception as e: logger.warning( u"Failed to generate references for {}, section {}. {}" .format( c.full_title("en"), ".".join([str(s) for s in sections]) if sections else "-", e.message)) return refs
def _first_section_ref(self): if not getattr(self, "index", False): return None current_leaf = self.index.nodes.first_leaf() new_section = None while current_leaf: if not current_leaf.is_virtual: # todo: handle first entries of virtual nodes r = current_leaf.ref() c = self.state_node(current_leaf).ja("all") new_section = c.next_index([]) if new_section: break current_leaf = current_leaf.next_leaf() if not new_section: return None depth_up = 0 if current_leaf.depth == 1 else 1 d = r._core_dict() d["toSections"] = d["sections"] = [(s + 1) for s in new_section[:-depth_up]] return Ref(_obj=d)
def refresh(self): if self.is_new_state: # refresh done on init return self.content = self.index.nodes.visit_content( self._content_node_visitor, self.content) self.index.nodes.visit_structure(self._aggregate_structure_state, self) self.linksCount = link.LinkSet(Ref(self.index.title)).count() self.save()
def refresh(self): if self.is_new_state: # refresh done on init return self.content = self.index.nodes.visit_content( self._content_node_visitor, self.content) self.index.nodes.visit_structure(self._aggregate_structure_state, self) self.linksCount = link.LinkSet(Ref(self.index.title)).count() self.save() if USE_VARNISH: from sefaria.system.sf_varnish import invalidate_counts invalidate_counts(self.index)
def refresh(self): if self.is_new_state: # refresh done on init return self.content = self.index.nodes.visit_content(self._content_node_visitor, self.content) self.index.nodes.visit_structure(self._aggregate_structure_state, self) self.linksCount = link.LinkSet(Ref(self.index.title)).count() fsr = self._first_section_ref() self.first_section_ref = fsr.normal() if fsr else None self.save() if USE_VARNISH: from sefaria.system.varnish.wrapper import invalidate_counts invalidate_counts(self.index)
def all_refs(self): refs = [] for vs in self: content_nodes = vs.index.nodes.get_leaf_nodes() for c in content_nodes: state_ja = vs.state_node(c).ja("_all") for indxs in state_ja.non_empty_sections(): sections = [a + 1 for a in indxs] refs += [ Ref( _obj={ "index": vs.index, "book": vs.index.nodes.full_title("en"), "type": vs.index.categories[0], "index_node": vs.index.nodes, "sections": sections, "toSections": sections }) ] return refs