Skip to content

Commit 2ac2240

Browse files
authored
Fix the /find department sort (#1133)
## Fixes issue Addresses TO-DO in code. ## Description of Changes The `/find` route was using an unsorted list of departments unlike the rest of the application. Before: <img width="1334" alt="Screenshot 2024-11-06 at 10 13 13 PM" src="https://github.com/user-attachments/assets/8c6b832a-109e-465a-a6ec-c102524eb43b"> After: <img width="1324" alt="Screenshot 2024-11-06 at 10 13 36 PM" src="https://github.com/user-attachments/assets/1f639518-a750-498e-8a26-6f5784ad052b"> ## Tests and Linting - [x] This branch is up-to-date with the `develop` branch. - [x] `pytest` passes on my local development environment. - [x] `pre-commit` passes on my local development environment.
1 parent 0c430e7 commit 2ac2240

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

OpenOversight/app/main/forms.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
STATE_CHOICES,
4141
SUFFIX_CHOICES,
4242
)
43-
from OpenOversight.app.utils.db import dept_choices, unit_choices, unsorted_dept_choices
43+
from OpenOversight.app.utils.db import dept_choices, unit_choices
4444
from OpenOversight.app.widgets import BootstrapListWidget, FormFieldWidget
4545

4646

@@ -102,7 +102,7 @@ class FindOfficerForm(Form):
102102
dept = QuerySelectField(
103103
"dept",
104104
validators=[DataRequired()],
105-
query_factory=unsorted_dept_choices,
105+
query_factory=dept_choices,
106106
get_label="display_name",
107107
)
108108
unit = StringField("unit", default="Not Sure", validators=[Optional()])

OpenOversight/app/main/views.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@
9898
add_department_query,
9999
add_unit_query,
100100
compute_leaderboard_stats,
101+
dept_choices,
101102
unit_choices,
102-
unsorted_dept_choices,
103103
)
104104
from OpenOversight.app.utils.forms import (
105105
add_new_assignment,
@@ -181,12 +181,6 @@ def browse():
181181
def get_officer():
182182
form = FindOfficerForm()
183183

184-
# TODO: Figure out why this test is failing when the departments are sorted using
185-
# the dept_choices function.
186-
departments_dict = [
187-
dept_choice.to_custom_dict() for dept_choice in unsorted_dept_choices()
188-
]
189-
190184
if getattr(current_user, "dept_pref_rel", None):
191185
set_dynamic_default(form.dept, current_user.dept_pref_rel)
192186

@@ -217,7 +211,7 @@ def get_officer():
217211
return render_template(
218212
"input_find_officer.html",
219213
form=form,
220-
depts_dict=departments_dict,
214+
depts_dict=[dept_choice.to_custom_dict() for dept_choice in dept_choices()],
221215
jsloads=["js/find_officer.js"],
222216
)
223217

OpenOversight/app/utils/db.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ def dept_choices():
6161
)
6262

6363

64-
def unsorted_dept_choices():
65-
return db.session.query(Department).all()
66-
67-
6864
def get_officer(department_id, star_no, first_name, last_name):
6965
"""
7066
Return the first officer with the given name and badge combo in the department, if one exists.

0 commit comments

Comments
 (0)