diff --git a/training-front-end/src/components/LoginlessFlow.vue b/training-front-end/src/components/LoginlessFlow.vue index 784e1bac..27a36a68 100644 --- a/training-front-end/src/components/LoginlessFlow.vue +++ b/training-front-end/src/components/LoginlessFlow.vue @@ -213,7 +213,7 @@
We sent you an email at {{ user_input.email }} with a link to access {{ linkDestinationText }}. This link is only active for 24 hours.
+We sent you an email at {{ user_input.email }} with a link to access {{ linkDestinationText }}. This link is only active for 24 hours. If you have not received the email within 15 minutes, please check your spam folder.
Not the right email? Send another email
diff --git a/training/repositories/agency.py b/training/repositories/agency.py index 03440484..f0ad2c2d 100644 --- a/training/repositories/agency.py +++ b/training/repositories/agency.py @@ -1,8 +1,10 @@ + from sqlalchemy.orm import Session from training import models, schemas from training.schemas.agency import AgencyWithBureaus, Bureau from .base import BaseRepository -from sqlalchemy.sql.expression import collate +from sqlalchemy.sql.expression import collate, case +from itertools import groupby class AgencyRepository(BaseRepository[models.Agency]): @@ -24,35 +26,32 @@ def find_by_name(self, agency: schemas.AgencyCreate) -> models.Agency | None: return self._session.query(models.Agency).filter(models.Agency.name == agency.name, models.Agency.bureau == agency.bureau).first() def get_agencies_with_bureaus(self) -> list[AgencyWithBureaus]: - db_results = self._session.query(models.Agency).order_by(collate(models.Agency.name, 'C')).all() - parent_agencies = [record for record in db_results if record.bureau is None] - - # For UI display, sort all parent agency by alphabetical order except for 'Other', 'Other" needs to be placed at the bottom of the list. - other_agency = [record for record in parent_agencies if record.name.lower() == 'other'] - rest_agencies = [record for record in parent_agencies if record.name.lower() != 'other'] - sorted_parent_agencies = rest_agencies + other_agency + ''' + get agencies_with_bureaus return a list of parent agencies with bureaus list, if parent agency doesn't have bureaus, its bureaus list =[]. + parent agencies are those db records with bureau value is null + UI want to sort agency alphabetically but needs 'Other' option to be displayed at the end. Both parent agency and bureau has 'Other' option. + serveral sort order are combined and is put in a spefic order to achieve this. + groupby is used to group same agency together + ''' + + # set 'Other' order rule for both agency and bureau + agency_other_order = case((models.Agency.name == "Other", 1), else_=0) + bureau_other_order = case((models.Agency.bureau == "Other", 2), (models.Agency.bureau==None, 0), else_=1) # noqa E711 + + db_results = self._session.query(models.Agency).order_by( + agency_other_order, # agency named Other should be at the bottom of parent agencies list + collate(models.Agency.name, 'C'), # alphebetic order on agency's name + bureau_other_order, # bureau named 'Other' should be at the bollom of the bureau list + collate(models.Agency.bureau, 'C') # alphbetic order on bureau + ).all() transform_angecies = [] - for record in sorted_parent_agencies: - agency_with_bureaus = [obj for obj in db_results if obj.bureau and obj.name == record.name] - bureaus = [] - if len(agency_with_bureaus) > 0: - sorted_bureaus = sorted(agency_with_bureaus, key=lambda x: x.bureau) - other_bureau = {} - for obj in sorted_bureaus: - bureau = Bureau(id=obj.id, name=obj.bureau) - # for bureau name that is not 'Other', add them in alphebetic order - if (bureau.name.lower() != 'other'): - bureaus.append(bureau) - else: - other_bureau = bureau - # if agency has "Other" bureau, put it all the way in the end - if (other_bureau.id): - bureaus.append(other_bureau) + for _, group in groupby(db_results, lambda row: row.name): + parent = next(group) # Parent is first in the group transform_angecies.append({ - 'id': record.id, - 'name': record.name, - 'bureaus': bureaus + 'id': parent.id, + 'name': parent.name, + 'bureaus': [{"id": b.id, "name": b.bureau} for b in group] }) return transform_angecies