-
-
Notifications
You must be signed in to change notification settings - Fork 152
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
Conversation
There was a problem hiding this 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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
bika/lims/browser/bika_listing.py
Outdated
if not sort_value: | ||
continue | ||
if sort_value in (list, tuple): | ||
sort_value = sort_value[0] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Description of the issue/feature this PR addresses
This PR fixes the failures in doc tests
UIDReferenceTest.rst
andShowPrices.rst
. The former was failing because of the assumption the functiongetDependentServices
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 whatsort_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 thesort_on
value set incontentFilter
and in turn,sort_on
value set incontentFilter
gets priority over the value set inself.sort_on
. If no matches found against columns or indexes for any of these values, the system usescreated
index as asort_on
fallback.Current behavior before PR
Doctests
UIDReferenceTest.rst
andShowPrices.rst
fail.Desired behavior after PR is merged
Doctests
UIDReferenceTest.rst
andShowPrices.rst
pass--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.