Fix rendering new widgets in admin dashboard
Review Request #10165 — Created Sept. 22, 2018 and submitted — Latest diff uploaded
The dashboard on /admin/ crashed when a brand new widget was added
to the page. The expected output is that the new widget, whether
it's a primary or secondary widget, should appear on the dashboard
with the other widgets.This was because there was a check to find the new widgets position,
before it actually had been given one. This raised aKeyError
,
which crashed the page.I added some .get() checks, so that if the widget position is not in
the dictionary, a None value is returned.I also refactored code on how new widgets are rendered in the
dashboard, so that thedashboard()
function inadmin/views.py
is much easier to read.
I ran all tests using
./tests/runtests.py
and no errors resulted.I also used the JS-tests on /js-tests/, and there were no issues.
I created a Unit Test class named WidgetTests, that can be run
with./tests/runtests.py reviewboard.admin.tests:WidgetTests
.
This test checks that adding a new primary widget and a new secondary
widget on the dashboard does not raise a KeyError, and gives the two
widgets a position.