Skip to content

Commit

Permalink
feat(linker): adding the option for 'optional' referenceable node
Browse files Browse the repository at this point in the history
  • Loading branch information
YishaiGlasner committed Jan 18, 2023
1 parent 7e52d80 commit aa494d1
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sefaria/model/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,11 +899,18 @@ def has_scope_alone_match_template(self):
return any(template.scope in self.MATCH_TEMPLATE_ALONE_SCOPES for template in self.get_match_templates())

def get_next_referenceable_descendants(self):
'''
Node can have the attribute 'referenceable' sets to True (which is the default when the attribute ismissing), False of 'optional'.
When node has referenceable False, it will return its referenceable descendant instead of itself.
When has referenceable 'optional', it will return the node itself and its referenceable descendant.
:return: list of the next referenceable descendant of the node
'''
nodes = []
for node in self.children:
if getattr(node, 'referenceable', True):
referenceable = getattr(node, 'referenceable', True)
if referenceable: #referenceable or optional
nodes.append(node)
else:
if referenceable is not True: #unreferenceable or optional
nodes += node.get_next_referenceable_descendants()
return nodes

Expand Down

0 comments on commit aa494d1

Please sign in to comment.