Sort needs by the order they were added as outgoing link #1090
Replies: 1 comment 3 replies
-
I'm afraid, that this is not easily possible. First of all, Sphinx-Needs wasn't developed to keep the order of elements. Also the used needtable and the filter string have no access to the You could also have 2 "base" objects, which include different orders of .. req:: ReqOne_A
:id: A_REQ_1_A
:links: A_REQ_2, A_REQ_4, A_REQ_3
.. needtable::
:filter: "A_REQ_1_A" in links_back
:style: table
.. req:: ReqOne_B
:id: A_REQ_1_B
:links: A_REQ_4, A_REQ_3, A_REQ_2 # different order
.. needtable::
:filter: "A_REQ_1_B" in links_back
:style: table The only solution I see is using custom filter code, which is somehow aware of the basic order. My idea is something like: index.rst .. req:: ReqOne
:id: A_REQ_1
:status: open
:links: A_REQ_2, A_REQ_4, A_REQ_3
:template: req_post # Can automatically be set by needs_global_options needs_templates/req_post.need {content}
.. needtable::
:filter-func: my_filters.req_filter({{id}}) #Inject the ID of the "base need
:style: table
my_filters.py def req_filter(needs, results, **kwargs):
"""Searches for needs defined by the links of a given "base" need". Respects link-order. """
base_need_id = kwargs["arg1"]
base_need = needs[base_need_id]
base_need_links = base_need['links']
for link in base_need_links:
if link in needs:
results.append(needs[links]) ⚠ The above code is untested and I'm not 100% sure if the order of the returned filter-function result is kept. Let me know if this idea works for you and how your final solutions looks like.
No, I like the approach as the step-order is defined in one need and this makes it easy for the user to maintain it.
Wasn't aware that we have these two options. |
Beta Was this translation helpful? Give feedback.
-
We model test cases and test steps by introducing 2 need types (
test_case
andtest_step
). For traceability we:link:
the test case with its test steps. For the reader we want to list all test steps below the test cases in the very order they are linked (as the order is relevant).Example (all types being set to
req
for the sake of the example):The table sorts by
:id:
(i.e. 2, 3, 4).Adding
:sort: links
to theneedtable
sorts by the order the needs appear (i.e. 4, 3, 2).How can I have the table sorted in the given order 2, 4, 3?
Or, if this isn't possible or sensible, how can I display the outgoing links in a specific order not only showing their ID but also their title?
Or even further, would you suggest another modelling for test cases and test steps?
Bonus question: What is the difference in
needtable
between:sort:
and:sort_by:
? I couldn't grasp it reading the documentation.Thanks in advance for your answers, and thanks a lot for this nice docs-as-code framework.
Beta Was this translation helpful? Give feedback.
All reactions