City select#372
Conversation
The city autocomplete will require a county parameter to return the cities only found in that county. Fixed dropdown selection on the front page to use the new city model properly.
There was a problem hiding this comment.
I put together a hacky solution of how it would work with an autocomplete city field in my branch #368. Commit link: 1115009
I used select2 directly, though probably I would have been better off using a django package that automates some of the stuff, like https://django-select2.readthedocs.io/.
Let me know what you think.
| "class": "cityAutoComplete", | ||
| "disabled": "true", | ||
| "data-url": reverse_lazy("city-autocomplete") | ||
| } |
There was a problem hiding this comment.
This could be problematic as it will load all 13K cities in the page select. It will make loading the registration page slower and the Code4ro partners who provided this data would not be be happy about leaving it out in the open to be scraped. (my understanding was that they are very protective of it)
| response = [{"v": row.id, "t": row.city} for row in rows] | ||
| if county: | ||
| rows = City.objects.filter(county__iexact=county).values_list("id", "city", named=True) | ||
| response = [{"id": row.id, "city": row.city} for row in rows] |
There was a problem hiding this comment.
One of the reasons I made this query to require 2 parameters was to make it harder to scraping this data. Although, thinking about it, having a limit of 1 characters is not offering much more complexity as it would require only about 50*26 requests to get it all.
Another reason is that you would still load on average 250 cities for every county and that is still quite a big select box.
This is part 2 of the #327
Finishes the work from #368