Skip to content

Commit

Permalink
Fix the /find department sort (#1133)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
michplunkett authored Nov 8, 2024
1 parent 0c430e7 commit 2ac2240
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
4 changes: 2 additions & 2 deletions OpenOversight/app/main/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
STATE_CHOICES,
SUFFIX_CHOICES,
)
from OpenOversight.app.utils.db import dept_choices, unit_choices, unsorted_dept_choices
from OpenOversight.app.utils.db import dept_choices, unit_choices
from OpenOversight.app.widgets import BootstrapListWidget, FormFieldWidget


Expand Down Expand Up @@ -102,7 +102,7 @@ class FindOfficerForm(Form):
dept = QuerySelectField(
"dept",
validators=[DataRequired()],
query_factory=unsorted_dept_choices,
query_factory=dept_choices,
get_label="display_name",
)
unit = StringField("unit", default="Not Sure", validators=[Optional()])
Expand Down
10 changes: 2 additions & 8 deletions OpenOversight/app/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
add_department_query,
add_unit_query,
compute_leaderboard_stats,
dept_choices,
unit_choices,
unsorted_dept_choices,
)
from OpenOversight.app.utils.forms import (
add_new_assignment,
Expand Down Expand Up @@ -181,12 +181,6 @@ def browse():
def get_officer():
form = FindOfficerForm()

# TODO: Figure out why this test is failing when the departments are sorted using
# the dept_choices function.
departments_dict = [
dept_choice.to_custom_dict() for dept_choice in unsorted_dept_choices()
]

if getattr(current_user, "dept_pref_rel", None):
set_dynamic_default(form.dept, current_user.dept_pref_rel)

Expand Down Expand Up @@ -217,7 +211,7 @@ def get_officer():
return render_template(
"input_find_officer.html",
form=form,
depts_dict=departments_dict,
depts_dict=[dept_choice.to_custom_dict() for dept_choice in dept_choices()],
jsloads=["js/find_officer.js"],
)

Expand Down
4 changes: 0 additions & 4 deletions OpenOversight/app/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ def dept_choices():
)


def unsorted_dept_choices():
return db.session.query(Department).all()


def get_officer(department_id, star_no, first_name, last_name):
"""
Return the first officer with the given name and badge combo in the department, if one exists.
Expand Down

0 comments on commit 2ac2240

Please sign in to comment.