def upload_workflow_proof_file(body): request_body = RequestBody(body) tallySheetId = request_body.get("tallySheetId") tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: raise NotFoundException("Tally sheet not found (tallySheetId=%d)" % tallySheetId, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND) body["proofId"] = tally_sheet.workflowInstance.proofId ProofApi.upload_file(body=body) extended_tally_sheet: ExtendedTallySheet = tally_sheet.get_extended_tally_sheet( ) extended_tally_sheet.execute_tally_sheet_proof_upload() tally_sheet_response = TallySheetSchema_1().dump( refactor_tally_sheet(tally_sheet)).data _append_latest_workflow_instance_to_cached_tally_sheets( cached_tally_sheets=[tally_sheet_response]) _append_latest_version_ids_to_cached_tally_sheets( cached_tally_sheets=[tally_sheet_response]) return tally_sheet_response
def create(invoiceId, body): request_body = RequestBody(body) result = InvoiceStationaryItem.create( invoiceId=invoiceId, stationaryItemId=request_body.get("stationaryItemId")) return Schema().dump(result).data, 201
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
def submit(tallySheetId, body): request_body = RequestBody(body) tallySheetVersionId = request_body.get("submittedVersionId") tally_sheet: TallySheetModel = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: raise NotFoundException( message="Tally sheet not found (tallySheetId=%d)" % tallySheetId, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND ) if tally_sheet.tallySheetCode not in [TallySheetCodeEnum.PRE_41, TallySheetCodeEnum.CE_201, TallySheetCodeEnum.CE_201_PV, TallySheetCodeEnum.PRE_34_CO]: raise ForbiddenException( message="Submit operation is not supported for this tally sheet type.", code=MESSAGE_CODE_TALLY_SHEET_SUBMIT_IS_NOT_SUPPORTED ) tally_sheet_version = TallySheetVersion.get_by_id(tallySheetVersionId=tallySheetVersionId, tallySheetId=tallySheetId) if tally_sheet_version is None: raise NotFoundException( message="Tally sheet version not found (tallySheetVersionId=%d)" % tallySheetVersionId, code=MESSAGE_CODE_TALLY_SHEET_VERSION_NOT_FOUND ) tally_sheet.set_submitted_version(tally_sheet_version) if tally_sheet.tallySheetCode in [TallySheetCodeEnum.CE_201, TallySheetCodeEnum.CE_201_PV]: election = tally_sheet.submission.election electionId = election.parentElectionId countingCentreId = tally_sheet.areaId results = StatusCE201.get_status_records(electionId, countingCentreId) for item in results: item.status = "Submitted" if tally_sheet.tallySheetCode in [TallySheetCodeEnum.PRE_41]: election = tally_sheet.submission.election electionId = election.parentElectionId countingCentreId = tally_sheet.areaId results = StatusPRE41.get_status_records(electionId, countingCentreId) for item in results: item.status = "Submitted" if tally_sheet.tallySheetCode in [TallySheetCodeEnum.PRE_34_CO]: election = tally_sheet.submission.election electionId = election.parentElectionId countingCentreId = tally_sheet.areaId results = StatusPRE34.get_status_records(electionId, countingCentreId) for item in results: item.status = "Submitted" db.session.commit() return TallySheetSchema().dump(tally_sheet).data, 201
def _create_tallysheet_PRE_41__party_list(body, tallysheetVersion): request_body = RequestBody(body) print("##########", body["party_wise_results"]) for party_wise_entry_body in request_body.get("party_wise_results"): _create_tallysheet_PRE_41__party_list_item(party_wise_entry_body, tallysheetVersion)
def lock(tallySheetId, body): request_body = RequestBody(body) tallySheetVersionId = request_body.get("lockedVersionId") tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: raise NotFoundException("Tally sheet not found (tallySheetId=%d)" % tallySheetId) tally_sheet_version = TallySheetVersion.get_by_id( tallySheetVersionId=tallySheetVersionId, tallySheetId=tallySheetId) if tally_sheet_version is None: raise NotFoundException( message="Tally sheet version not found (tallySheetVersionId=%d)" % tallySheetVersionId, code=MESSAGE_CODE_TALLY_SHEET_VERSION_NOT_FOUND) if not tally_sheet_version.isComplete: raise NotFoundException( message="Incomplete tally sheet version (tallySheetVersionId=%d)" % tallySheetVersionId, code= MESSAGE_CODE_TALLY_SHEET_INCOMPLETE_TALLY_SHEET_CANNOT_BE_LOCKED) tally_sheet.set_locked_version(tally_sheet_version) if tally_sheet.tallySheetCode in [ TallySheetCodeEnum.CE_201, TallySheetCodeEnum.CE_201_PV ]: election = tally_sheet.submission.election electionId = election.parentElectionId countingCentreId = tally_sheet.areaId results = StatusCE201.get_status_records(electionId, countingCentreId) for item in results: item.status = "Verified" if tally_sheet.tallySheetCode in [TallySheetCodeEnum.PRE_41]: election = tally_sheet.submission.election electionId = election.parentElectionId countingCentreId = tally_sheet.areaId results = StatusPRE41.get_status_records(electionId, countingCentreId) for item in results: item.status = "Verified" if tally_sheet.tallySheetCode in [TallySheetCodeEnum.PRE_34_CO]: election = tally_sheet.submission.election electionId = election.parentElectionId countingCentreId = tally_sheet.areaId results = StatusPRE34.get_status_records(electionId, countingCentreId) for item in results: item.status = "Verified" db.session.commit() return TallySheetSchema().dump(tally_sheet).data, 201
def workflow(tallySheetId, body): request_body = RequestBody(body) workflowActionId = request_body.get("workflowActionId") tallySheetVersionId = request_body.get("tallySheetVersionId") tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: raise NotFoundException("Tally sheet not found (tallySheetId=%d)" % tallySheetId, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND) extended_tally_sheet: ExtendedTallySheet = tally_sheet.get_extended_tally_sheet( ) extended_tally_sheet.execute_workflow_action( workflowActionId=workflowActionId, tallySheetVersionId=tallySheetVersionId) db.session.commit() tally_sheet_response = TallySheetSchema_1().dump( refactor_tally_sheet(tally_sheet)).data _append_latest_workflow_instance_to_cached_tally_sheets( cached_tally_sheets=[tally_sheet_response]) _append_latest_version_ids_to_cached_tally_sheets( cached_tally_sheets=[tally_sheet_response]) return tally_sheet_response
def create(body): request_body = RequestBody(body) result = TallySheetVersion.create( tallySheetId=request_body.get("tallySheetId")) db.session.commit() return Schema().dump(result).data, 201
def create(body): request_body = RequestBody(body) result = BallotBox.create(electionId=request_body.get("electionId"), ballotBoxId=request_body.get("ballotBoxId")) db.session.commit() return Schema().dump(result).data, 201
def letter_html(tallySheetId, tallySheetVersionId, body): request_body = RequestBody(body) signatures = request_body.get("signatures") user_access_area_ids = get_user_access_area_ids() return _cache_letter_html(user_access_area_ids=user_access_area_ids, tally_sheet_id=tallySheetId, tally_sheet_version_id=tallySheetVersionId, signatures=signatures)
def _create_tallysheet_PRE_41__party_list_item(body, tallysheetVersion): request_body = RequestBody(body) new_tallysheet_PRE_41__party = TallySheetPRE41PartyModel( partyId=request_body.get("partyId"), voteCount=request_body.get("voteCount"), tallySheetVersionId=tallysheetVersion.tallySheetVersionId) db.session.add(new_tallysheet_PRE_41__party) db.session.commit()
def upload_file(body): request_body = RequestBody(body) result = Proof.upload_file( proofId=request_body.get("proofId"), fileSource=connexion.request.files['scannedFile'], fileType=FileTypeEnum.Image ) return Schema().dump(result).data, 201
def create(tallySheetId, body): tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tallySheet is None: raise NotFoundException("Tally sheet not found. (tallySheetId=%d)" % tallySheetId) request_body = RequestBody(body) tallySheetVersion = TallySheetVersionPRE41.create( tallySheetId=tallySheetId ) tally_sheet_content = request_body.get("content") if tally_sheet_content is not None: for row in tally_sheet_content: party_count_body = RequestBody(row) tallySheetVersion.add_row( candidateId=party_count_body.get("candidateId"), count=party_count_body.get("count"), countInWords=party_count_body.get("countInWords") ) tally_sheet_summary_body = request_body.get("summary") if tally_sheet_summary_body is not None: tallySheetVersion.add_invalid_vote_count( electionId=tallySheetVersion.submission.electionId, rejectedVoteCount=tally_sheet_summary_body.get("rejectedVoteCount") ) db.session.commit() return TallySheetVersionSchema().dump(tallySheetVersion).data
def create(tallySheetId, body): request_body = RequestBody(body) tallySheet, tallySheetVersion = TallySheet.create_latest_version( tallySheetId=tallySheetId, content=request_body.get("content") ) db.session.commit() return TallySheetVersionSchema().dump(tallySheetVersion).data
def create(body): request_body = RequestBody(body) new_tallysheet = TallySheetModel(electionId=request_body.get("electionId"), code=request_body.get("code"), officeId=request_body.get("officeId")) # Add the entry to the database db.session.add(new_tallysheet) db.session.commit() new_tallysheet = create_tallysheet_version(body, new_tallysheet) # Serialize and return the newly created entry in the response return get_tallysheet_response(new_tallysheet), 201
def _create_tallysheet_PRE_41(body, tallysheetVersion): request_body = RequestBody(body) new_tallysheet_PRE_41 = TallySheetPRE41Model( tallySheetId=tallysheetVersion.tallySheetId, tallySheetVersionId=tallysheetVersion.tallySheetVersionId, electoralDistrictId=request_body.get("electoralDistrictId"), pollingDivisionId=request_body.get("pollingDivisionId"), countingCentreId=request_body.get("countingCentreId"), ) db.session.add(new_tallysheet_PRE_41) db.session.commit() _create_tallysheet_PRE_41__party_list(body, tallysheetVersion) return new_tallysheet_PRE_41
def create(tallySheetId, body): request_body = RequestBody(body) tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: raise NotFoundException( message="Tally sheet not found (tallySheetId=%d)" % tallySheetId, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND) extended_tally_sheet: ExtendedTallySheet = tally_sheet.get_extended_tally_sheet( ) extended_tally_sheet.execute_tally_sheet_post( content=request_body.get("content")) db.session.commit() return TallySheetSchema_1().dump(tally_sheet).data
def create(tallySheetId, body): request_body = RequestBody(body) tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) # validate user inputs to prevent XSS attacks validate_tally_sheet_version_request_content_special_characters(request_body.get("content")) if tally_sheet is None: raise NotFoundException( message="Tally sheet not found (tallySheetId=%d)" % tallySheetId, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND ) extended_tally_sheet: ExtendedTallySheet = tally_sheet.get_extended_tally_sheet() extended_tally_sheet.execute_tally_sheet_post(content=request_body.get("content")) db.session.commit() return TallySheetApi.get_by_id(tallySheetId=tallySheetId)
def upload_workflow_proof_file(body): request_body = RequestBody(body) tallySheetId = request_body.get("tallySheetId") tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: raise NotFoundException("Tally sheet not found (tallySheetId=%d)" % tallySheetId, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND) body["proofId"] = tally_sheet.workflowInstance.proofId ProofApi.upload_file(body=body) extended_tally_sheet: ExtendedTallySheet = tally_sheet.get_extended_tally_sheet( ) extended_tally_sheet.execute_tally_sheet_proof_upload() return TallySheetSchema_1().dump(tally_sheet).data
def create(tallySheetId, body): tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tallySheet is None: raise NotFoundException("Tally sheet not found. (tallySheetId=%d)" % tallySheetId) request_body = RequestBody(body) tallySheet, tallySheetVersion = TallySheet.create_latest_version( tallySheetId=tallySheetId, tallySheetCode=TallySheetCodeEnum.PRE_34_CO) tally_sheet_content = request_body.get("content") print(request_body.body) if tally_sheet_content is not None: for row in tally_sheet_content: party_count_body = RequestBody(row) row = tallySheetVersion.add_row( candidateId=party_count_body.get("candidateId"), notCountedBallotPapers=party_count_body.get( "notCountedBallotPapers"), remainingBallotPapers=party_count_body.get( "remainingBallotPapers")) # Lets add the preferences for the above row preferences = party_count_body.get("preferences") for preference in preferences: print(preference) TallySheetVersionRow_PRE_34_CO_PREFERENCES.create( tallySheetVersionRowId=row.tallySheetVersionRowId, candidateId=preference.get('candidateId'), no2ndPreferences=preference.get('no2rdPreferences'), no3rdPreferences=preference.get('no3rdPreferences')) tally_sheet_summary_body = request_body.get("summary") if tally_sheet_summary_body is not None: tallySheetVersion.add_invalid_vote_count( electionId=tallySheetVersion.submission.electionId, rejectedVoteCount=tally_sheet_summary_body.get( "rejectedVoteCount")) db.session.commit() return TallySheetVersionSchema().dump(tallySheetVersion).data
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
def workflow(tallySheetId, body): request_body = RequestBody(body) workflowActionId = request_body.get("workflowActionId") tallySheetVersionId = request_body.get("tallySheetVersionId") tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: raise NotFoundException("Tally sheet not found (tallySheetId=%d)" % tallySheetId, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND) extended_tally_sheet: ExtendedTallySheet = tally_sheet.get_extended_tally_sheet( ) extended_tally_sheet.execute_workflow_action( workflowActionId=workflowActionId, tallySheetVersionId=tallySheetVersionId) db.session.commit() return TallySheetSchema_1().dump(tally_sheet).data
def create(tallySheetId, body): request_body = RequestBody(body) tallySheetVersion = TallySheetVersion_CE_201_PV.create( tallySheetId=tallySheetId) total_number_of_a_packets_found = 0 tally_sheet_content = request_body.get("content") if tally_sheet_content is not None: for row in tally_sheet_content: tally_sheet_content_item = RequestBody(row) row = tallySheetVersion.add_row( ballotBoxStationaryItemId=tally_sheet_content_item.get( "ballotBoxStationaryItemId"), numberOfPacketsInserted=tally_sheet_content_item.get( "numberOfPacketsInserted"), numberOfAPacketsFound=tally_sheet_content_item.get( "numberOfAPacketsFound")) total_number_of_a_packets_found = total_number_of_a_packets_found + row.numberOfAPacketsFound tally_sheet_summary = request_body.get("summary") time_of_commencement_of_count = tally_sheet_summary.get( "timeOfCommencementOfCount") # To remove the colon between time zone comming from openapi date-time. # This is since the colon is not accepted in python datetime # if ":" == time_of_commencement_of_count[-3:-2]: # time_of_commencement_of_count = time_of_commencement_of_count[:-3] + time_of_commencement_of_count[-2:] tallySheetVersion.add_summary( situation=tally_sheet_summary.get("situation"), timeOfCommencementOfCount=datetime.datetime.strptime( time_of_commencement_of_count, '%Y-%m-%dT%H:%M:%S.%fZ'), numberOfAPacketsFound=total_number_of_a_packets_found, numberOfACoversRejected=tally_sheet_summary.get( "numberOfACoversRejected"), numberOfBCoversRejected=tally_sheet_summary.get( "numberOfBCoversRejected"), numberOfValidBallotPapers=tally_sheet_summary.get( "numberOfValidBallotPapers")) db.session.commit() return TallySheetVersionSchema().dump(tallySheetVersion).data
def create(tallySheetId, body): request_body = RequestBody(body) tallySheetVersion = TallySheetVersionPRE41.create( tallySheetId=tallySheetId) tally_sheet_content = request_body.get("content") if tally_sheet_content is not None: for row in tally_sheet_content: party_count_body = RequestBody(row) tallySheetVersion.add_row( candidateId=party_count_body.get("candidateId"), count=party_count_body.get("count"), countInWords=party_count_body.get("countInWords")) return TallySheetVersionPRE41Schema().dump(tallySheetVersion).data
def lock(tallySheetId, body): request_body = RequestBody(body) tallySheetVersionId = request_body.get("lockedVersionId") tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: raise NotFoundException("Tally sheet not found (tallySheetId=%d)" % tallySheetId) tally_sheet_version = TallySheetVersion.get_by_id( tallySheetVersionId=tallySheetVersionId, tallySheetId=tallySheetId) if tally_sheet_version is None: raise NotFoundException( "Tally sheet version not found (tallySheetVersionId=%d)" % tallySheetVersionId) tally_sheet.set_locked_version(tally_sheet_version) db.session.commit() return TallySheetSchema().dump(tally_sheet).data, 201
def create(body): request_body = RequestBody(body) result = Model.create( electionId=request_body.get("electionId"), issuingOfficeId=request_body.get("issuingOfficeId"), receivingOfficeId=request_body.get("receivingOfficeId"), issuedTo=request_body.get("issuedTo"), ) return Schema().dump(result).data
def receive(body): request_body = RequestBody(body) result = InvoiceStationaryItem.update( invoiceId=request_body.get("invoiceId"), stationaryItemId=request_body.get("stationaryItemId"), received=True, receivedFrom=request_body.get("receivedFrom"), receivedOfficeId=request_body.get("receivedOfficeId"), scannedImages=connexion.request.files['scannedImages']) return Schema().dump(result).data, 201
def create(tallySheetId, body): request_body = RequestBody(body) pre41 = TallySheetVersionPRE41.create( tallySheetId=tallySheetId ) tally_sheet_content = request_body.get("tallySheetContent") if tally_sheet_content is not None: for row in tally_sheet_content: party_count_body = RequestBody(row) PartyCount.create( partyWiseResultId=pre41.partyWiseResultId, partyId=party_count_body.get("partyId"), count=party_count_body.get("count"), countInWords=party_count_body.get("countInWords") # electionId=pre41.tallySheet.electionId ) return TallySheetVersionPRE41Schema().dump(pre41).data
def create(tallySheetId, body): request_body = RequestBody(body) tallySheet, tallySheetVersion = TallySheet.create_latest_version( tallySheetId=tallySheetId, tallySheetCode=TallySheetCodeEnum.PRE_41) tally_sheet_content = request_body.get("content") if tally_sheet_content is not None: for row in tally_sheet_content: party_count_body = RequestBody(row) tallySheetVersion.add_row( candidateId=party_count_body.get("candidateId"), count=party_count_body.get("count"), countInWords=party_count_body.get("countInWords")) tally_sheet_summary_body = request_body.get("summary") if tally_sheet_summary_body is not None: tallySheetVersion.add_invalid_vote_count( electionId=tallySheetVersion.submission.electionId, rejectedVoteCount=tally_sheet_summary_body.get( "rejectedVoteCount")) db.session.commit() return TallySheetVersionSchema().dump(tallySheetVersion).data
def create(tallySheetId, body): request_body = RequestBody(body) tallySheetVersion = TallySheetVersionPRE21.create( tallySheetId=tallySheetId) tally_sheet_content = request_body.get("content") if tally_sheet_content is not None: for row in tally_sheet_content: party_count_body = RequestBody(row) tallySheetVersion.add_row( count=party_count_body.get("count"), invalidVoteCategoryId=party_count_body.get( "invalidVoteCategoryId")) db.session.commit() return TallySheetVersionSchema().dump(tallySheetVersion).data