Add a new selector for related users.

Review Request #8173 — Created May 18, 2016 and submitted — Latest diff uploaded

Information

Review Board
release-2.5.x
61d0cc5...

Reviewers

We're faced with a conundrum in the admin UI when it comes to models that have
relations to other tables which can contain tons of entries. We can either use
one of django's filter widgets, which query all rows and pre-populate the form
field completely, or we can use django's "raw ID field", which has a
comma-separated list of PKs and a pop-up window search to add items. In the
first case, when there are a very large number of users (such as on public
servers), we can actually crash the web server processes. In the second case,
it's efficient but totally unusable.

This change introduces a new, custom widget, which is based on selectize. This
widget provides a list for the currently selected objects, plus a searchable
drop-down to add new items. Whenever something is selected, it gets put into a
list which shows exactly what is already selected.

This has the benefits of the filter widget with some extra sauce on top
(avatars, better searching), plus it's much more efficient in its queries to
the database. This is currently only implemented for relations to User (since
there's custom display and API interface code per type), but that's the big
offender anyway.

  • Loaded the form with no users selected and saw an empty list.
  • Loaded the form with existing users selected and saw them show up correctly.
  • Clicked into the drop-down and saw it populate with the first page of results
    from the API.
  • Started typing in a name and saw that the drop-down searched for that name
    using the API.
  • Searched for a name which was already in the selected list and saw that it was
    properly hidden from the results.
  • Used the keyboard to navigate to and accept a result.
  • Removed items from the selected list.
  • Saved the form in various states and verified that the resulting database
    entries were correct.

    Loading...