Exemplo n.º 1
0
def create(body):
    request_body = RequestBody(body)
    election_name = request_body.get("electionName")
    election_template_name = request_body.get("electionTemplateName")

    files = connexion.request.files
    polling_stations_dataset = files.get("pollingStationsDataset")
    postal_counting_centres_dataset = files.get("postalCountingCentresDataset")
    party_candidates_dataset = files.get("partyCandidatesDataset")
    invalid_vote_categories_dataset = files.get("invalidVoteCategoriesDataset")
    number_of_seats_dataset_file = files.get("numberOfSeatsDataset")

    election = Election.create(
        electionTemplateName=election_template_name,
        electionName=election_name,
        isListed=True,
        party_candidate_dataset_file=party_candidates_dataset,
        polling_station_dataset_file=polling_stations_dataset,
        postal_counting_centers_dataset_file=postal_counting_centres_dataset,
        invalid_vote_categories_dataset_file=invalid_vote_categories_dataset,
        number_of_seats_dataset_file=number_of_seats_dataset_file)

    db.session.commit()

    return Schema().dump(election).data
Exemplo n.º 2
0
    def create_test_election(mock_stamp_create):
        mock_stamp = Stamp()
        mock_stamp.ip = "0.0.0.0"
        mock_stamp.createdBy = "TestAdmin"
        mock_stamp.createdAt = datetime.now()
        db.session.add(mock_stamp)
        db.session.flush()
        mock_stamp_create.return_value = mock_stamp

        from orm.entities.Election.election_helper import build_presidential_election
        election = Election.create(electionName="Test Election")

        basedir = os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               "..", "sample-data", "test")
        party_candidate_dataset_file = os.path.join(basedir,
                                                    "party-candidate.csv")
        polling_station_dataset_file = os.path.join(basedir, "data.csv")
        postal_counting_centers_dataset_file = os.path.join(
            basedir, "postal-data.csv")
        invalid_vote_categories_dataset_file = os.path.join(
            basedir, "invalid-vote-categories.csv")

        build_presidential_election(
            root_election=election,
            party_candidate_dataset_file=party_candidate_dataset_file,
            polling_station_dataset_file=polling_station_dataset_file,
            postal_counting_centers_dataset_file=
            postal_counting_centers_dataset_file,
            invalid_vote_categories_dataset_file=
            invalid_vote_categories_dataset_file)
        return election
def create(body):
    request_body = RequestBody(body)
    election_name = request_body.get("electionName")

    files = connexion.request.files
    polling_stations_dataset = files.get("pollingStationsDataset")
    postal_counting_centres_dataset = files.get("postalCountingCentresDataset")
    party_candidates_dataset = files.get("partyCandidatesDataset")
    invalid_vote_categories_dataset = files.get("invalidVoteCategoriesDataset")

    election = Election.create(electionName=election_name)
    election.set_polling_stations_dataset(fileSource=polling_stations_dataset)
    election.set_postal_counting_centres_dataset(fileSource=postal_counting_centres_dataset)
    election.set_party_candidates_dataset(fileSource=party_candidates_dataset)
    election.set_invalid_vote_categories_dataset(fileSource=invalid_vote_categories_dataset)

    build_presidential_election(root_election=election)

    db.session.commit()

    return Schema().dump(election).data