def _cache_pdf(user_access_area_ids, tally_sheet_id, tally_sheet_version_id): tally_sheet = TallySheet.get_by_id(tallySheetId=tally_sheet_id) if tally_sheet is None: raise NotFoundException( message="Tally sheet not found (tallySheetId=%d)" % tally_sheet_id, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND) tally_sheet_version = TallySheetVersion.get_by_id( tallySheetId=tally_sheet_id, tallySheetVersionId=tally_sheet_version_id) if tally_sheet_version is None: raise NotFoundException( message="Tally sheet version not found (tallySheetVersionId=%d)" % tally_sheet_version_id, code=MESSAGE_CODE_TALLY_SHEET_VERSION_NOT_FOUND) file_response = FileApi.get_download_file( fileId=tally_sheet_version.get_exported_pdf_file_id( tallySheetId=tally_sheet_id, tallySheetVersionId=tally_sheet_version_id)) db.session.commit() return file_response
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 endCommand(self, clientId, commandId): command = self._commandDAO.find(commandId) if command is None: raise NotFoundException() if command.clientId != clientId: raise NotFoundException() command.endTime = time.time() self._commandDAO.save(command) return command
def get_by_id(tallySheetId, tallySheetVersionId): tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tallySheet is None: raise NotFoundException("Tally sheet not found. (tallySheetId=%d)" % tallySheetId) elif tallySheet.tallySheetCode is not TallySheetCodeEnum.CE_201_PV: raise NotFoundException("Requested version not found. (tallySheetId=%d)" % tallySheetId) result = Model.query.filter( Model.tallySheetVersionId == tallySheetVersionId ).one_or_none() return result
def get_by_id(tallySheetId, tallySheetVersionId): tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tallySheet is None: raise NotFoundException("Tally sheet not found. (tallySheetId=%d)" % tallySheetId) elif tallySheet.tallySheetCode is not TallySheetCodeEnum.PRE_ALL_ISLAND_RESULTS_BY_ELECTORAL_DISTRICTS: raise NotFoundException( "Requested version not found. (tallySheetId=%d)" % tallySheetId) result = Model.query.filter( Model.tallySheetVersionId == tallySheetVersionId).one_or_none() return result
def __init__(self, tallySheetId): tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tallySheet is None: raise NotFoundException("Tally sheet not found. (tallySheetId=%d)" % tallySheetId) elif tallySheet.tallySheetCode is not self.tallySheetVersionCode: raise NotFoundException("Invalid tally sheet. (tallySheetId=%d)" % tallySheetId) submissionVersion = SubmissionVersion.create(submissionId=tallySheetId) super(TallySheetVersionModel, self).__init__( tallySheetVersionId=submissionVersion.submissionVersionId ) db.session.add(self) db.session.flush()
def update(invoiceId, stationaryItemId, received=False, receivedFrom=None, receivedOfficeId=None, scannedImages=None): instance = get_by_id(invoiceId, stationaryItemId) # if scannedImages is not None: # file = Image.create(fileSource=scannedImages) # FolderFile.create(folderId=instance.receivedScannedFilesFolderId, fileId=file.fileId) # TODO support muliple images # https://github.com/zalando/connexion/issues/510 if instance is None: raise NotFoundException("Invoice Stationary Item not found associated with the given invoiceId (%d, %d)" % (invoiceId, stationaryItemId)) else: if received is not None: instance.received = received if receivedFrom is not None: instance.receivedFrom = receivedFrom if receivedOfficeId is not None: instance.receivedOfficeId = receivedOfficeId if instance.received is True: Proof.update( proofId=instance.receivedProofId, finished=True ) instance.receivedBy = Auth().get_user_id() instance.receivedAt = datetime.now() db.session.flush() return instance
def get_by_id(proofId): result = Proof.get_by_id(proofId=proofId) if result is None: raise NotFoundException("Proof not found. (proofId=%d)" % proofId) return Schema().dump(result).data
def html(tallySheetId, tallySheetVersionId): 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( tallySheetId=tallySheetId, tallySheetVersionId=tallySheetVersionId) if tally_sheet_version is None: NotFoundException( "Tally sheet version not found (tallySheetVersionId=%d)" % tallySheetVersionId) return Response(tally_sheet_version.html(), mimetype='text/html')
def getHTML(self,config,parsecandidate): hashChar = parsecandidate.url.find('#') if(hashChar>=0): url = parsecandidate.url[0:hashChar] else: url = parsecandidate.url try: #empty cookie store? #get http response request = Request(url,None, config.headers) response = urlopen(request) if response.getcode() == 404: raise NotFoundException(url) #find character encode contenttype = response.getheader('content-type') csidx = contenttype.find('charset') if contenttype and csidx : parsecandidate.charset = contenttype[csidx + len('charset='):] parsecandidate.charset = parsecandidate.charset.strip() return response.readall() except NotFoundException as e: logging.error("Link not found (404): " + e.url) raise e except Exception as e: raise e
def release(tallySheetId): tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: raise NotFoundException("Tally sheet not found (tallySheetId=%d)" % tallySheetId) # TODO refactor tally_sheet.submissionProof.close() tally_sheet.set_released_version() db.session.commit() try: result_push_service.release_results( tally_sheet=tally_sheet, tally_sheet_version_id=tally_sheet.releasedVersionId) except: # rollback release flag print("Result push service failed. Check the url configuration.") tally_sheet.releasedVersionId = None tally_sheet.releasedStampId = None db.session.commit() return "Push Service Failed. Please check configuration and try again.", 500 return TallySheetSchema().dump(tally_sheet).data, 201
def __init__(self, electionId, areaId): area = PollingDivision.get_by_id(pollingDivisionId=areaId) if area is None: raise NotFoundException("Polling division not found (areaId=%d)" % areaId) super(Report_PRE_30_PD_Model, self).__init__(electionId=electionId, areaId=areaId)
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 is_locked(stationaryItemId): entry = get_by_id(stationaryItemId) if entry is None: raise NotFoundException("Stationary Item Not Found (stationaryItemId=%d) " % stationaryItemId) else: return entry.locked
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(reportId): report = Report.get_by_id(reportId=reportId) if report is None: raise NotFoundException("Report not found. (reportId=%d)" % reportId) submissionVersion = SubmissionVersion.create(submissionId=reportId) html = render_template('test-report-template.html', title="Test Template", data=[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]) if report.submission.electorate is None: fileName = "PRE-41-%s-%s.pdf" % (report.office.officeType.name, report.office.officeName) else: fileName = "PRE-41-%s-%s.pdf" % (report.electorate.electorateType.name, report.electorate.electorateName) reportFile = File.createReport(fileName=fileName, html=html) result = Model(reportVersionId=submissionVersion.submissionVersionId, reportFileId=reportFile.fileId) db.session.add(result) db.session.commit() return result
def __init__(self, electionId, areaId): area = ElectoralDistrict.get_by_id(electoralDistrictId=areaId) if area is None: raise NotFoundException("Electoral district not found (areaId=%d)" % areaId) super(Report_PRE_30_ED_Model, self).__init__(electionId=electionId, areaId=areaId)
def upload_file(proofId, fileSource, fileType): proof = get_by_id(proofId=proofId) if proof is None: raise NotFoundException( message="Proof not found associated with the given proofId (proofId=%d)" % proofId, code=MESSAGE_CODE_PROOF_NOT_FOUND ) elif proof.finished is True: raise ForbiddenException( message="No more evidence is accepted for this proof (proofId=%d)" % proofId, code=MESSAGE_CODE_PROOF_NOT_MORE_EVIDENCE_ACCEPTED ) else: file = File.createFromFileSource( fileSource=fileSource, fileType=fileType ) FolderFile.create( folderId=proof.scannedFilesFolderId, fileId=file.fileId ) return proof
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 get_by_id(tallySheetId): tally_sheet = TallySheetModel.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: NotFoundException("Tally sheet not found (tallySheetId=%d)" % tallySheetId) return TallySheetSchema().dump(tally_sheet).data
def get_by_id(proofId): result = Proof.get_by_id(proofId=proofId) if result is None: raise NotFoundException("Proof not found. (proofId=%d)" % proofId, code=MESSAGE_CODE_PROOF_NOT_FOUND) return Schema().dump(result).data
def get_user(email): email = email.replace(' ', '') user = mongo.db.users user = user.find_one({'email': email}) if not user: raise NotFoundException("user with email {} not found".format(email)) user = User(name=user['name'], role=user['role'], email=user['email']) return user
def popCommand(self, clientId): logging.debug("Server.popCommand(%s)" % clientId) command = self._commandDAO.findNextFromClient(clientId) if command is None: raise NotFoundException() command.startTime = time.time() self._commandDAO.save(command) return command
def get_by_id(electionId): result = Election.get_by_id(electionId=electionId) if result is None: raise NotFoundException(message="Election not found (electionId=%d)" % electionId, code=MESSAGE_CODE_ELECTION_NOT_FOUND) return Schema().dump(result).data
def has_confirmed(invoiceId): entry = get_by_id(invoiceId) if entry is None: raise NotFoundException("Invoice Not Found (invoiceId=%d) " % invoiceId) else: return entry.confirmed
def get_all(tallySheetId): tallySheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tallySheet is None: raise NotFoundException("Tally sheet not found. (tallySheetId=%d)" % tallySheetId) result = TallySheetVersionPRE21.get_all(tallySheetId=tallySheetId) return TallySheetVersionPRE21Schema(many=True).dump(result).data
def get_by_id(tallySheetId): tally_sheet = TallySheet.get_by_id(tallySheetId=tallySheetId) if tally_sheet is None: NotFoundException(message="Tally sheet not found (tallySheetId=%s)" % tallySheetId, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND) return TallySheetSchema().dump(tally_sheet).data
def create_empty_version(tallySheetId): tallySheet = get_by_id(tallySheetId=tallySheetId) if tallySheet is None: raise NotFoundException( message="Tally sheet not found. (tallySheetId=%d)" % tallySheetId, code=MESSAGE_CODE_TALLY_SHEET_NOT_FOUND) tallySheetVersion = tallySheet.create_empty_version() return tallySheet, tallySheetVersion
def html(tallySheetId, tallySheetVersionId): 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) tally_sheet_version = TallySheetVersion.get_by_id( tallySheetId=tallySheetId, tallySheetVersionId=tallySheetVersionId) 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) return Response(tally_sheet.html(tallySheetVersionId=tallySheetVersionId), mimetype='text/html')
def authenticate(email, password): email = email.replace(' ', '') user = mongo.db.users user = user.find_one({'email': email}) if not user: raise NotFoundException("user with email {} not found".format(email)) if bcrypt.check_password_hash(user['password'], password): user = User(name=user['name'], role=user['role'], email=user['email']) return user raise AbortException("password not match")