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

Sort choices to make it easier to select #123

Merged
merged 4 commits into from
Apr 28, 2024

Conversation

hrbonz
Copy link
Contributor

@hrbonz hrbonz commented Jan 13, 2024

The sorting is applied to both standard and GMT choices.

Close #116

@hrbonz hrbonz force-pushed the wip/116-sort_form_tz branch from 1b5a399 to 70dea6e Compare January 17, 2024 05:12
@hrbonz
Copy link
Contributor Author

hrbonz commented Jan 17, 2024

Strengthen edge cases sorting in standard and proper GMT sorting (alpha sort does not result in a natural order with -xx:xx and +xx:xx).
Fix testing to reflect the sorting.
Issues:

  • testing all the values as they're read from the backend (unordered) does not work, those two tests were dropped. I suspect they would make more sense as a separate test.
  • There's still a problem with tests.test_deconstruct:test_specifying_defaults_not_frozen(), I don't think I impacted that test and don't understand the use case.

@paulocoutinhox
Copy link

Hi,

Merge this pls.

thanks.

Copy link
Owner

@mfogel mfogel left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. Two minor comments that need to be addressed before this can be merged - the CI is failing because those checks were removed (unused variables).

There is a separate issue causing CI to fail - a codecoverage token issue. I'll address that via a separate PR

tests/test_choices_display_option.py Show resolved Hide resolved
tests/test_choices_display_option.py Show resolved Hide resolved
@hrbonz
Copy link
Contributor Author

hrbonz commented Apr 23, 2024

Let me refresh my memory on the code, I'll try to get this done quickly to keep the momentum.

@hrbonz hrbonz force-pushed the wip/116-sort_form_tz branch 2 times, most recently from 0cfa00d to 181276b Compare April 23, 2024 07:40
@hrbonz
Copy link
Contributor Author

hrbonz commented Apr 23, 2024

@mfogel I found a good way to re-introduce the assert in both tests. I use sorted for speed and Counter (slower but required for non sortable elements) to validate the test.
Running the test through poetry, I found another test failing (tests/test_deconstruct.py:80) but I don't think it was caused by my changes.

@mfogel
Copy link
Owner

mfogel commented Apr 24, 2024

Awesome, thank you for all that @hrbonz

I fixed the codecov token issue on main. The tests are fully passing there - even that one you noticed is still failing. Can you rebase this on the latest on main, and then we can try to figure out what's up with that final failing test?

@paulocoutinhox
Copy link

Hi @hrbonz, can you rebase? Thanks for your time.

Sorting the choices in forms helps with a more natural selection process
@hrbonz hrbonz force-pushed the wip/116-sort_form_tz branch from 181276b to 9bcf0ef Compare April 25, 2024 21:51
@hrbonz
Copy link
Contributor Author

hrbonz commented Apr 25, 2024

@mfogel @paulocoutinhox rebased and the same test is still failing.

@hrbonz
Copy link
Contributor Author

hrbonz commented Apr 25, 2024

Here's the failing test:

___________________________________ test_specifying_defaults_not_frozen[zoneinfo] ____________________________________

use_pytz = False
to_tzobj = <bound method ZoneInfoBackend.to_tzobj of <timezone_field.backends.zoneinfo.ZoneInfoBackend object at 0x7f8343ef3a60>>
base_tzstrs = {'Africa/Abidjan', 'Africa/Accra', 'Africa/Addis_Ababa', 'Africa/Algiers', 'Africa/Asmara', 'Africa/Asmera', ...}

    def test_specifying_defaults_not_frozen(use_pytz, to_tzobj, base_tzstrs):
        """
        If someone's matched the default values with their kwarg args, we
        shouldn't bothering freezing those
        (excluding the use_pytz, which changes with your django version).
        """
        field = TimeZoneField(max_length=63)
        _name, _path, _args, kwargs = field.deconstruct()
        assert "max_length" not in kwargs
    
        choices = [(to_tzobj(tz), tz.replace("_", " ")) for tz in base_tzstrs]
        field = TimeZoneField(choices=choices, use_pytz=use_pytz)
        _name, _path, _args, kwargs = field.deconstruct()
>       assert "choices" not in kwargs
E       AssertionError: assert 'choices' not in {'choices': [('Pacific/Funafuti', 'Pacific/Funafuti'), ('America/Panama', 'America/Panama'), ('America/Port_of_Spain',...ersey'), ('Indian/Kerguelen', 'Indian/Kerguelen'), ('America/Goose_Bay', 'America/Goose Bay'), ...], 'use_pytz': False}

tests/test_deconstruct.py:78: AssertionError

From verbose run:

tests/test_deconstruct.py::test_specifying_defaults_not_frozen[pytz] PASSED                                    [ 57%]
tests/test_deconstruct.py::test_specifying_defaults_not_frozen[zoneinfo] FAILED                                [ 57%]

I did another pass on my code and can't find a reason for my changes to break this test.

For information, here's my environment:

$ python -V
Python 3.9.2
$ pip freeze --local
asgiref==3.7.2
astroid==2.15.8   
asttokens==2.4.1
attrs==23.1.0  
black==23.11.0  
build==1.0.3  
CacheControl==0.13.1  
certifi==2023.11.17
cffi==1.16.0     
charset-normalizer==3.3.2
cleo==2.1.0               
click==8.1.7            
coverage==6.5.0   
crashtest==0.4.1
cryptography==41.0.7
decorator==5.1.1        
dill==0.3.7         
distlib==0.3.8    
Django==4.2.7
-e git+ssh://git@github.com/hrbonz/django-timezone-field.git@9bcf0ef0cee90b246fb45483b73a7aeb865bf96f#egg=django_timez
one_field        
djangorestframework==3.14.0
dulwich==0.21.7
exceptiongroup==1.2.0
executing==2.0.1 
fastjsonschema==2.19.1     
filelock==3.13.1        
flake8==5.0.4 
idna==3.6     
importlib-metadata==7.0.1
iniconfig==2.0.0
installer==0.7.0
ipdb==0.13.13
ipython==8.18.1
isort==5.12.0
jaraco.classes==3.3.0
jedi==0.19.1             
jeepney==0.8.0
keyring==24.3.0                                                                                                       
lazy-object-proxy==1.9.0                                   
matplotlib-inline==0.1.6 
mccabe==0.7.0            
more-itertools==10.2.0                                     
msgpack==1.0.7     
mypy-extensions==1.0.0                                     
packaging==23.2
parso==0.8.3
pathspec==0.11.2                                           
pexpect==4.9.0                                                                                                        
pkginfo==1.9.6                                             
platformdirs==4.0.0                                        
pluggy==1.3.0                                              
poetry==1.7.1      
poetry-core==1.8.1                                         
poetry-plugin-export==1.6.0                                
prompt-toolkit==3.0.43
psycopg2-binary==2.9.9
ptyprocess==0.7.0                                          
pure-eval==0.2.2             
py==1.11.0    
pycodestyle==2.9.1
pycparser==2.21 
pyflakes==2.5.0
Pygments==2.17.2
pylint==2.17.7
pyproject_hooks==1.0.0
pytest==6.2.5      
pytest-cov==3.0.0
pytest-django==4.5.2     
pytest-lazy-fixture==0.6.3
pytest-pythonpath==0.7.4
pytz==2023.3.post1
rapidfuzz==3.6.1
requests==2.31.0    
requests-toolbelt==1.0.0
SecretStorage==3.3.3
shellingham==1.5.4
six==1.16.0  
sqlparse==0.4.4                                                                                                       
stack-data==0.6.3
toml==0.10.2               
tomli==2.0.1   
tomlkit==0.12.3      
traitlets==5.14.1
trove-classifiers==2024.1.8
typing_extensions==4.8.0
tzdata==2023.3
urllib3==2.1.0
virtualenv==20.25.0      
wcwidth==0.2.13 
wrapt==1.16.0   
zipp==3.17.0

@mfogel
Copy link
Owner

mfogel commented Apr 26, 2024

Thanks for rebasing. I should have time to dig into this this weekend.

@hrbonz
Copy link
Contributor Author

hrbonz commented Apr 26, 2024

Looks like there's still an issue with codecov

@mfogel
Copy link
Owner

mfogel commented Apr 28, 2024

Ok, I've fixed that failing test... it was implicitly depending on the sort order of the choices. The remaining failures are all uploads to codecov, and I'm confident they will pass once on main (famous last words).

Thanks a bunch for the contribution @hrbonz ! Merging in now

@mfogel mfogel merged commit cb9b81b into mfogel:main Apr 28, 2024
2 of 62 checks passed
@tomasztyzaj
Copy link

@mfogel do we have a minor release for that fix or can we have one ? :)

@meh9
Copy link

meh9 commented Jul 6, 2024

Yes - please can we have a release for this.

@paulocoutinhox
Copy link

PLS!!!

@mfogel
Copy link
Owner

mfogel commented Jul 6, 2024

Yup sorry for the delay. I'm planning to get a new release out this weekend.

@hrbonz
Copy link
Contributor Author

hrbonz commented Jul 6, 2024

Yay, can't wait!

@mfogel
Copy link
Owner

mfogel commented Jul 7, 2024

Ok I just released v7.0 to pypi. Please open an issue if you run across any issue upgrading to it, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sorting list of timezones on ModelForm?
5 participants