Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sorted facilities alphabetically #2846

Merged
merged 1 commit into from
Feb 16, 2025

Conversation

ayeshmcg
Copy link
Contributor

@ayeshmcg ayeshmcg commented Feb 14, 2025

Card: bcgov/cas-reporting#564
Changes:
sorted facilities by facility_name

To test:-

  1. Login vi BCeId

  2. Select an LFO operation on reports table and navigate to review facilties, you will see all the facilities sorted alphabetically like http://localhost:3000/reporting/reports/2/facilities/review-facilities-list
    image

  3. Navigate to http://localhost:3000/reporting/reports/2/facilities/report-information
    image

@ayeshmcg ayeshmcg force-pushed the chore/564-sorting-facilities branch from bfd273f to a4367bf Compare February 14, 2025 00:32
@@ -82,6 +82,7 @@ def get_all_facilities_for_review(version_id: int) -> dict:
operation_id = report_version.report.operation.id
available_facilities = (
FacilityDesignatedOperationTimeline.objects.filter(operation_id=operation_id)
.order_by('facility__name')
Copy link
Contributor

@shon-button shon-button Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayeshmcg

Suggest using a natural sort (how humans might expect the sort: "Facility 1", "Facility 3", ..., "Facility 10" instead of "Facility 1", "Facility 10", "Facility 3").

image
image

Perhaps something like pip install django-naturalsort then

from naturalsort import natural_sort_key

available_facilities = (
    FacilityDesignatedOperationTimeline.objects.filter(operation_id=operation_id)
    .distinct()
    .values('facility_id', 'facility__name', 'end_date')
)

# Sort using natural sort
available_facilities = sorted(available_facilities, key=lambda x: natural_sort_key(x['facility__name']))

This approach ensures that names like "Facility 2" and "Facility 10" are sorted correctly in human-friendly order.
565

@shon-button shon-button force-pushed the chore/564-sorting-facilities branch from a4367bf to 8a15d10 Compare February 16, 2025 12:08
@shon-button shon-button force-pushed the chore/564-sorting-facilities branch from c82b356 to 2dc5c9c Compare February 16, 2025 12:46
@shon-button shon-button merged commit 95bf4bd into develop Feb 16, 2025
42 checks passed
@shon-button shon-button deleted the chore/564-sorting-facilities branch February 16, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants