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

feat: order location types in checklist export #932

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions apollo/submissions/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import csv
from io import StringIO

import sqlalchemy as sa
from flask_babelex import gettext as _
from geoalchemy2.shape import to_shape

from apollo import constants
from apollo.dal.service import Service
from apollo.locations.models import LocationType
from apollo.locations.models import LocationType, LocationTypePath
from apollo.participants.models import Sample
from apollo.submissions.models import (
Submission, SubmissionComment, SubmissionVersion)
Expand Down Expand Up @@ -41,9 +42,19 @@ def export_list(self, query, include_qa=False):
event = submission.event
form = submission.form
extra_fields = event.location_set.extra_fields
location_types = LocationType.query.filter_by(
is_administrative=True,
location_set_id=event.location_set_id).all()
location_types = LocationTypePath.query.filter_by(
location_set_id=event.location_set_id
).join(
LocationType, LocationType.id == LocationTypePath.ancestor_id
).with_entities(
LocationType
).group_by(
LocationTypePath.ancestor_id,
LocationType.id
).order_by(
sa.func.count(LocationTypePath.ancestor_id).desc(),
LocationType.name
).all()
samples = Sample.query.filter_by(
participant_set_id=event.participant_set_id).all()
tags = form.tags
Expand Down