def get_all(electionId=None,
            areaName=None,
            associatedAreaId=None,
            areaType=None):
    result = Area.get_all(election_id=electionId,
                          area_name=areaName,
                          associated_area_id=associatedAreaId,
                          area_type=get_area_type(area_type=areaType))

    return Schema(many=True).dump(result).data
Beispiel #2
0
def get_all(electionId=None,
            areaName=None,
            associatedAreaId=None,
            areaType=None):
    query = Area.get_all(election_id=electionId,
                         area_name=areaName,
                         associated_area_id=associatedAreaId,
                         area_type=get_area_type(area_type=areaType))
    query = get_paginated_query(query)
    result = query.all()

    return AreaSchema(many=True).dump(result).data
def init_global_area_map():
    # TODO Refactor

    from orm.entities import Area
    from orm.enums import AreaTypeEnum

    global_area_map = {
        ElectoralDistricts: {
            PollingDivisions: {
                # list of polling divisions mapped to the electoral district id.
            },
            CountingCentres: {
                Postal: {
                    # list of postal counting centres mapped to the electoral district id.
                },
                NonPostal: {
                    # list of non postal counting centres mapped to the electoral district id.
                }
            }
        },
        Countries: {
            ElectoralDistricts: {
                # list of electoral districts mapped to the country id.
            },
            PollingDivisions: {
                # list of polling divisions mapped to the country id.
            },
            CountingCentres: {
                Postal: {
                    # list of postal counting centres mapped to the country id.
                },
                NonPostal: {
                    # list of non postal counting centres mapped to the country id.
                }
            }
        }
    }

    countries = Area.get_all(area_type=AreaTypeEnum.Country)
    electoral_districts = Area.get_all(
        area_type=AreaTypeEnum.ElectoralDistrict)

    for electoral_district in electoral_districts:

        sub_elections = electoral_district.election.subElections
        for sub_election in sub_elections:
            if sub_election.voteType == VoteTypeEnum.Postal:
                global_area_map[ElectoralDistricts][CountingCentres][Postal][
                    electoral_district.areaId] = [
                        counting_centre.areaId for counting_centre in
                        electoral_district.get_associated_areas(
                            areaType=AreaTypeEnum.CountingCentre,
                            electionId=sub_election.electionId)
                    ]
            elif sub_election.voteType == VoteTypeEnum.NonPostal:
                global_area_map[ElectoralDistricts][CountingCentres][
                    NonPostal][electoral_district.areaId] = [
                        counting_centre.areaId for counting_centre in
                        electoral_district.get_associated_areas(
                            areaType=AreaTypeEnum.CountingCentre,
                            electionId=sub_election.electionId)
                    ]

        global_area_map[ElectoralDistricts][PollingDivisions][
            electoral_district.areaId] = [
                counting_centre.areaId
                for counting_centre in electoral_district.get_associated_areas(
                    areaType=AreaTypeEnum.PollingDivision)
            ]

    for country in countries:

        sub_elections = country.election.subElections
        for sub_election in sub_elections:
            if sub_election.voteType == VoteTypeEnum.Postal:
                global_area_map[Countries][CountingCentres][Postal][
                    country.areaId] = [
                        counting_centre.areaId
                        for counting_centre in country.get_associated_areas(
                            areaType=AreaTypeEnum.CountingCentre,
                            electionId=sub_election.electionId)
                    ]
            elif sub_election.voteType == VoteTypeEnum.NonPostal:
                global_area_map[Countries][CountingCentres][NonPostal][
                    country.areaId] = [
                        counting_centre.areaId
                        for counting_centre in country.get_associated_areas(
                            areaType=AreaTypeEnum.CountingCentre,
                            electionId=sub_election.electionId)
                    ]

        global_area_map[Countries][ElectoralDistricts][country.areaId] = [
            counting_centre.areaId
            for counting_centre in country.get_associated_areas(
                areaType=AreaTypeEnum.ElectoralDistrict)
        ]

        global_area_map[Countries][PollingDivisions][country.areaId] = [
            counting_centre.areaId
            for counting_centre in country.get_associated_areas(
                areaType=AreaTypeEnum.PollingDivision)
        ]

    return global_area_map