def process_needlist(app, doctree, fromdocname):
env = app.builder.env<EOL>for node in doctree.traverse(Needlist):<EOL><INDENT>if not app.config.needs_include_needs:<EOL><INDENT>for att in ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>node[att] = []<EOL><DEDENT>node.replace_self([])<EOL>continue<EOL><DEDENT>id = node.attributes["<STR_LIT>"][<NUM_LIT:0>]<EOL>current_needfilter = env.need_all_needlists[id]<EOL>all_needs = env.needs_all_needs<EOL>content = []<EOL>all_needs = list(all_needs.values())<EOL>if current_needfilter["<STR_LIT>"] is not None:<EOL><INDENT>if current_needfilter["<STR_LIT>"] == "<STR_LIT:id>":<EOL><INDENT>all_needs = sorted(all_needs, key=lambda node: node["<STR_LIT:id>"])<EOL><DEDENT>elif current_needfilter["<STR_LIT>"] == "<STR_LIT:status>":<EOL><INDENT>all_needs = sorted(all_needs, key=status_sorter)<EOL><DEDENT><DEDENT>found_needs = procces_filters(all_needs, current_needfilter)<EOL>line_block = nodes.line_block()<EOL>for need_info in found_needs:<EOL><INDENT>para = nodes.line()<EOL>description = "<STR_LIT>" % (need_info["<STR_LIT:id>"], need_info["<STR_LIT:title>"])<EOL>if current_needfilter["<STR_LIT>"] and need_info["<STR_LIT:status>"] is not None:<EOL><INDENT>description += "<STR_LIT>" % need_info["<STR_LIT:status>"]<EOL><DEDENT>if current_needfilter["<STR_LIT>"] and need_info["<STR_LIT>"] is not None:<EOL><INDENT>description += "<STR_LIT>" % "<STR_LIT>".join(need_info["<STR_LIT>"])<EOL><DEDENT>title = nodes.Text(description, description)<EOL>if not need_info["<STR_LIT>"]:<EOL><INDENT>ref = nodes.reference('<STR_LIT>', '<STR_LIT>')<EOL>ref['<STR_LIT>'] = need_info['<STR_LIT>']<EOL>ref['<STR_LIT>'] = app.builder.get_relative_uri(<EOL>fromdocname, need_info['<STR_LIT>'])<EOL>ref['<STR_LIT>'] += '<STR_LIT:#>' + need_info['<STR_LIT>']['<STR_LIT>']<EOL>ref.append(title)<EOL>para += ref<EOL><DEDENT>else:<EOL><INDENT>para += title<EOL><DEDENT>line_block.append(para)<EOL><DEDENT>content.append(line_block)<EOL>if len(content) == <NUM_LIT:0>:<EOL><INDENT>content.append(no_needs_found_paragraph())<EOL><DEDENT>if current_needfilter["<STR_LIT>"]:<EOL><INDENT>content.append(used_filter_paragraph(current_needfilter))<EOL><DEDENT>node.replace_self(content)<EOL><DEDENT>
Replace all needlist nodes with a list of the collected needs.
Augment each need with a backlink to the original location.