def create(): form = CreateElementCodeForm(request.form) if request.method == 'POST' and form.validate(): appConf = getConfig() cRepo = CodesRepo(appConf['appDbConnStr']) loggedInUsername = session['SUSER']['name'] # initialize new code as None codeStr = None # attach placeholder to code only if form input is not None suppliedCodeStr = form.code.data if (not suppliedCodeStr == None) and (not suppliedCodeStr.strip() == ""): codeStr = getNewCodePlaceHolder()+suppliedCodeStr # create element code isSuccess = cRepo.insertElementCode( code_issue_time=form.codeIssueTime.data, code_str=codeStr, other_ldc_codes=form.otherLdcCodes.data, code_description=form.codeDescription.data, code_execution_time=None, code_tags=form.codeTags.data, code_issued_by=loggedInUsername, code_issued_to=form.codeIssuedTo.data, pwc_element_type_id=form.elementTypeId.data, pwc_element_id=form.elementId.data, pwc_element_name=form.elementName.data, pwc_element_type=form.elementType.data) if isSuccess: flash( 'Successfully created the element code - {0}'.format(form.code.data), category='success') return redirect(url_for('codes.list')) else: flash( 'Could not create the element code - {0}'.format(form.code.data), category='danger') return render_template('elementCode/create.html.j2', form=form)
def test_createGenericCode(self) -> None: """tests the function that gets creates generic code """ appDbConnStr = self.appConf['appDbConnStr'] cRepo = CodesRepo(appDbConnStr) # no execution time isSuccess = cRepo.insertGenericCode( code_issue_time=None, code_str="TEST_01", other_ldc_codes=None, code_description="test description", code_execution_time=None, code_tags="TESTING", code_issued_by="NA", code_issued_to="NA") self.assertTrue(isSuccess) # with execution time isSuccess = cRepo.insertGenericCode( code_issue_time=None, code_str="TEST_01", other_ldc_codes=None, code_description="test description", code_execution_time=dt.datetime.now(), code_tags="TESTING", code_issued_by="NA", code_issued_to="NA") self.assertTrue(isSuccess)
def test_getNextCodeForInsertion(self) -> None: """tests the function that gets Next Code For Insertion """ appDbConnStr = self.appConf['appDbConnStr'] cRepo = CodesRepo(appDbConnStr) dbConn = None dbCur = None nextCode = None try: # get connection with raw data table dbConn = cx_Oracle.connect(appDbConnStr) # get cursor and execute fetch sql dbCur = dbConn.cursor() nextCode = cRepo.getNextCodeForInsertion(dbCur=dbCur) except Exception as err: print( 'Error while fetching next code for insertion from codes repo') print(err) finally: # closing database cursor and connection if dbCur is not None: dbCur.close() if dbConn is not None: dbConn.close() print(nextCode) self.assertFalse(nextCode == None)
def list(): form = ListCodesForm(request.form) appConf = getConfig() cRepo = CodesRepo(appConf['appDbConnStr']) if request.method == 'POST' and form.validate(): codes = cRepo.getCodesBetweenDates(startDt=form.startDate.data, endDt=form.endDate.data) else: todayDt = dt.datetime.now() codes = cRepo.getCodesBetweenDates(startDt=todayDt, endDt=todayDt) form.startDate.data = dt.datetime(todayDt.year, todayDt.month, todayDt.day) form.endDate.data = dt.datetime(todayDt.year, todayDt.month, todayDt.day) for code in codes: classStrs = [] if code['isCodeCancelled'] == True: classStrs.append("cancelledCode") if not code['codeExecTime']: classStrs.append("notExecCode") elif code['codeType'] == "Revival": classStrs.append("revivalCode") elif code['codeType'] in ["Outage"]: classStrs.append("outageCode") elif code['codeType'] in ["ApprovedOutage"]: classStrs.append("approvedOutageCode") code["cssClass"] = ' '.join(classStrs) return render_template('code/list.html.j2', form=form, data={'codes': codes})
def test_getCodesForRtoIds(self) -> None: """tests the function that gets codes for rto Ids """ appDbConnStr = self.appConf['appDbConnStr'] cRepo = CodesRepo(appDbConnStr) rtoCodes = cRepo.getCodesForRtoIds([430, 5163]) # print(rtoCodes) self.assertFalse(len(rtoCodes) == 0)
def test_getLatestCode(self) -> None: """tests the function that gets the latest code """ appDbConnStr = self.appConf['appDbConnStr'] cRepo = CodesRepo(appDbConnStr) # no execution time code = cRepo.getLatestCode() self.assertFalse(code == None)
def test_getCodesBetweenDates(self) -> None: """tests the function that gets the codes """ appDbConnStr = self.appConf['appDbConnStr'] cRepo = CodesRepo(appDbConnStr) # no execution time codes = cRepo.getCodesBetweenDates(startDt=dt.datetime(2021, 1, 6), endDt=dt.datetime(2021, 1, 6)) self.assertTrue(len(codes) > 0)
def create(): form = CreateApprovedOutageCodeForm(request.form) appConf = getConfig() oTagsRepo = OutageTagsRepo(appConf['pwcDbConnStr']) oTypesRepo = OutageTypesRepo(appConf['pwcDbConnStr']) oTags = oTagsRepo.getRealTimeOutageTags() oTypes = oTypesRepo.getRealTimeOutageTypes() if request.method == 'POST' and form.validate(): cRepo = CodesRepo(appConf['appDbConnStr']) loggedInUsername = session['SUSER']['name'] # initialize new code as None codeStr = None # attach placeholder to code only if form input is not None suppliedCodeStr = form.code.data if (not suppliedCodeStr == None) and (not suppliedCodeStr.strip() == ""): codeStr = getNewCodePlaceHolder() + suppliedCodeStr # create approved outage code isSuccess = cRepo.insertApprovedOutageCode( code_issue_time=form.codeIssueTime.data, code_str=codeStr, other_ldc_codes=form.otherLdcCodes.data, code_description=form.codeDescription.data, code_execution_time=None, code_tags=form.codeTags.data, code_issued_by=loggedInUsername, code_issued_to=form.codeIssuedTo.data, pwc_element_type_id=form.elementTypeId.data, pwc_element_id=form.elementId.data, pwc_element_name=form.elementName.data, pwc_element_type=form.elementType.data, pwc_outage_type_id=form.outageTypeId.data, pwc_outage_tag_id=form.outageTagId.data, pwc_outage_type=form.outageType.data, pwc_outage_tag=form.outageTag.data, pwc_sd_req_id=form.sdReqId.data) if isSuccess: flash('Successfully created the approved outage code - {0}'.format( form.code.data), category='success') return redirect(url_for('codes.list')) else: flash( 'Could not create the approved outage code - {0}, please check if element is already out' .format(form.code.data), category='danger') return render_template('approvedOutageCode/create.html.j2', form=form, data={ "oTags": oTags, "oTypes": oTypes })
def getLatestUnrevOutages(appDbConnStr: str, pwcDbConnStr: str) -> List[IUnRevOutageWithCode]: oRepo = OutagesRepo(pwcDbConnStr) outages = oRepo.getLatestUnrevOutages() cRepo = CodesRepo(appDbConnStr) rtoIds = [o['rtoId'] for o in outages] rtoCodes = cRepo.getCodesForRtoIds(rtoIds) for o in outages: o['code'] = '' rtoId = o['rtoId'] if rtoId in rtoCodes: o['code'] = rtoCodes[rtoId] return outages
def delete(codeId: int): appConf = getConfig() cRepo = CodesRepo(appConf['appDbConnStr']) code = cRepo.getCodeById(codeId) if request.method == 'POST': isSuccess = cRepo.deleteCode(codeId) if isSuccess: flash('Successfully deleted the code', category='success') return redirect(url_for('codes.list')) else: flash('Could not delete the code', category='error') return render_template('code/delete.html.j2', data={'code': code})
def editElementRevivalCodeViaForm(codeId: int, cRepo: CodesRepo, form: EditElementRevivalCodeForm): isSuccess = cRepo.editElementRevivalCode(codeId=codeId, code_issue_time=form.codeIssueTime.data, code_str=form.code.data, other_ldc_codes=form.otherLdcCodes.data, code_description=form.codeDescription.data, code_execution_time=form.codeExecTime.data, code_tags=form.codeTags.data, code_issued_by=form.codeIssuedBy.data, code_issued_to=form.codeIssuedTo.data, is_code_cancelled=form.isCodeCancelled.data, pwc_rto_id=form.rtoId.data) return isSuccess
def detail(codeId: int): appConf = getConfig() cRepo = CodesRepo(appConf['appDbConnStr']) code = cRepo.getCodeById(codeId) return render_template('code/detail.html.j2', data={'code': code})
def getLatestCode(): appConf = getConfig() cRepo = CodesRepo(appConf['appDbConnStr']) latestCode = cRepo.getLatestCode() return {"code": latestCode}
def edit(codeId: int): appConf = getConfig() cRepo = CodesRepo(appConf['appDbConnStr']) code = cRepo.getCodeById(codeId) if code == None: raise werkzeug.exceptions.NotFound() if code["codeType"] == "Generic": if request.method == 'POST': form = EditGenericCodeForm(request.form) if form.validate(): isSuccess = editGenericCodeViaForm(codeId=codeId, cRepo=cRepo, form=form) if isSuccess: flash('Successfully edited the code - {0}'.format( form.code.data), category='success') else: flash('Could not edit the code - {0}'.format( form.code.data), category='danger') return redirect(url_for('codes.list')) else: form = createGenericCodeEditForm(code) return render_template('genericCode/edit.html.j2', form=form) elif code["codeType"] == "Element": if request.method == 'POST': form = EditElementCodeForm(request.form) if form.validate(): isSuccess = editElementCodeViaForm(codeId=codeId, cRepo=cRepo, form=form) if isSuccess: flash('Successfully edited the code - {0}'.format( form.code.data), category='success') else: flash('Could not edit the code - {0}'.format( form.code.data), category='danger') return redirect(url_for('codes.list')) else: form = createElementCodeEditForm(code) return render_template('elementCode/edit.html.j2', form=form) elif code["codeType"] in ["Outage", "ApprovedOutage"]: if request.method == 'POST': form = EditElementOutageCodeForm(request.form) if form.validate(): isSuccess = editElementOutageCodeViaForm(codeId=codeId, cRepo=cRepo, form=form) if isSuccess: flash('Successfully edited the code - {0}'.format( form.code.data), category='success') else: flash( 'Could not edit the code - {0}, please check if element is already out' .format(form.code.data), category='danger') return redirect(url_for('codes.list')) else: form = createElementOutageCodeEditForm(code) oTagsRepo = OutageTagsRepo(appConf['pwcDbConnStr']) oTypesRepo = OutageTypesRepo(appConf['pwcDbConnStr']) oTags = oTagsRepo.getRealTimeOutageTags() oTypes = oTypesRepo.getRealTimeOutageTypes() return render_template('elementOutageCode/edit.html.j2', form=form, data={ "code": json.dumps(code, default=defaultJsonEncoder), "oTags": oTags, "oTypes": oTypes }) elif code["codeType"] == "Revival": if request.method == 'POST': form = EditElementRevivalCodeForm(request.form) if form.validate(): isSuccess = editElementRevivalCodeViaForm(codeId=codeId, cRepo=cRepo, form=form) if isSuccess: flash('Successfully edited the code - {0}'.format( form.code.data), category='success') else: flash( 'Could not edit the code - {0}, please check if element is already in service' .format(form.code.data), category='danger') return redirect(url_for('codes.list')) else: form = createElementRevivalCodeEditForm(code) return render_template( 'elementRevivalCode/edit.html.j2', form=form, data={"code": json.dumps(code, default=defaultJsonEncoder)}) else: raise werkzeug.exceptions.NotFound()