Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix doc tests and inconsistencies with sorting criteria in lists #416

Merged
merged 5 commits into from
Nov 27, 2017

Conversation

xispa
Copy link
Member

@xispa xispa commented Nov 26, 2017

Description of the issue/feature this PR addresses

This PR fixes the failures in doc tests UIDReferenceTest.rst and ShowPrices.rst. The former was failing because of the assumption the function getDependentServices returned the services sorted by title. The function returns de dependent services correctly, but don't care about the order. The latter was failing because of inconsistencies in the assignment of sorting criteria when rendering lists.

To resolve these inconsistencies, the logic regarding sort_on and sort_order in lists has been refactored.

Basically, sort_on var was meant to refer to table column, but is oftenly used to set the index for which the list must be sorted against. This inconsistence is the reason of the warnings and the perplexity of devs that never know what sort_on acts like (sometimes, sort_on is obtained from the request as a colunm name, but in other cases, expects an index, etc.). This refactoring takes all this into account and always tries to return the index (better because the sorting is done directly when querying) and if not, returns the name of the column, but tells the system the sorting must be done programatically. sort_on value set in the request gets priority over the sort_on value set in contentFilter and in turn, sort_on value set in contentFilter gets priority over the value set in self.sort_on. If no matches found against columns or indexes for any of these values, the system uses created index as a sort_on fallback.

Current behavior before PR

Doctests UIDReferenceTest.rst and ShowPrices.rst fail.

Desired behavior after PR is merged

Doctests UIDReferenceTest.rst and ShowPrices.rst pass

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

Copy link
Contributor

@ramonski ramonski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for one possible KeyError, I do not see any code problems with this PR. Please decide if you would like to change, otherwise I'm ok to merge that one.

:rtype: str
"""

def corrected_sort_value(value):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you do that function within the method? In my opinion this increases complexity without any additional advantage

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to check the same (if the value is set in columns and/or in indexes) for each sort_on possible sources (self.request, self.contentFilter and self.sort_on), so instead of triplicating the same code or placing it into the loop (see L808), I though this way would be better.

if not sort_value:
continue
if sort_value in (list, tuple):
sort_value = sort_value[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure when this happens, but this fails for an empty list/tuple with a KeyError

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted, I missed to evaluate the type against the list.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use isinstance(sort_value, (list, tuple)) and then len(sort_value)==1

@xispa xispa merged commit 8d09d9a into senaite:master Nov 27, 2017
@xispa xispa deleted the fix-doc-tests branch November 27, 2017 18:18
@xispa xispa restored the fix-doc-tests branch November 27, 2017 18:21
@xispa xispa deleted the fix-doc-tests branch November 27, 2017 18:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants