コード例 #1
0
def create():
    form = CreateCodeTagCodeForm(request.form)
    if request.method == 'POST' and form.validate():
        appConf = getConfig()
        cTagsRepo = CodeTagsRepo(appConf['appDbConnStr'])
        # initialize new code tag string as None
        codeTagStr = None

        # attach placeholder to code only if form input is not None
        suppliedCodeStr = form.codeTag.data
        if (not suppliedCodeStr == None) and (not suppliedCodeStr.strip()
                                              == ""):
            codeTagStr = suppliedCodeStr

        # create code tag
        isSuccess = cTagsRepo.insertCodeTag(codeTagStr)
        if isSuccess:
            flash('Successfully created the code tag - {0}'.format(
                form.codeTag.data),
                  category='success')
            return redirect(url_for('codeTags.list'))
        else:
            flash('Could not create the code tag - {0}'.format(
                form.codeTag.data),
                  category='danger')
    return render_template('codeTag/create.html.j2', form=form)
コード例 #2
0
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})
コード例 #3
0
def create():
    form = CreateElementOutageCodeForm(request.form)
    appConf = getConfig()
    pwcDbConnStr = appConf['pwcDbConnStr']
    oTagsRepo = OutageTagsRepo(pwcDbConnStr)
    oTypesRepo = OutageTypesRepo(pwcDbConnStr)
    oTags = oTagsRepo.getRealTimeOutageTags()
    oTypes = oTypesRepo.getRealTimeOutageTypes()
    if request.method == 'POST' and form.validate():
        elId = form.elementId.data
        elTypeId = form.elementTypeId.data
        elName = form.elementName.data
        # check if element is already out
        isElOut = checkIfElementIsOut(pwcDbConnStr=pwcDbConnStr,
                                      elId=elId,
                                      elTypeId=elTypeId)
        if isElOut:
            # element is already out, hence this is not a valid real time outage
            print(
                "could not edit element outage code for element {0} with element id = {1}, element type id = {2}, since element is already out"
                .format(elName, elId, elTypeId))
            flash(
                'element already out, hence could not create the real-time outage',
                category='danger')
        else:
            # create real time outage
            newRtoId = createRealTimeOutage(
                pwcDbConnStr=pwcDbConnStr,
                elemTypeId=elTypeId,
                elementId=elId,
                outageDt=form.outageTime.data,
                outageTypeId=form.outageTypeId.data,
                reason=form.outageReason.data,
                elementName=form.elementName.data,
                sdReqId=0,
                outageTagId=form.outageTagId.data)
            if newRtoId > 0:
                flash(
                    'Successfully created the real-time outage with id - {0}'.
                    format(newRtoId),
                    category='success')
                # return redirect(url_for('codes.list'))
            else:
                flash('Could not create the real-time outage',
                      category='danger')
    return render_template('realTimeOutage/create.html.j2',
                           form=form,
                           data={
                               "oTags": oTags,
                               "oTypes": oTypes
                           })
コード例 #4
0
def detail(codeId: int):
    appConf = getConfig()
    cRepo = CodesRepo(appConf['appDbConnStr'])
    code = cRepo.getCodeById(codeId)
    return render_template('code/detail.html.j2', data={'code': code})
コード例 #5
0
def getLatestCode():
    appConf = getConfig()
    cRepo = CodesRepo(appConf['appDbConnStr'])
    latestCode = cRepo.getLatestCode()
    return {"code": latestCode}
コード例 #6
0
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()
コード例 #7
0
def list():
    appConf = getConfig()
    cTagsRepo = CodeTagsRepo(appConf['appDbConnStr'])
    codeTags = cTagsRepo.getAllCodeTags()
    return render_template('codeTag/list.html.j2', data={'codeTags': codeTags})
コード例 #8
0
def getCodeTags():
    appConf = getConfig()
    cTagsRepo = CodeTagsRepo(appConf['appDbConnStr'])
    codeTags = cTagsRepo.getAllCodeTags()
    return {"codeTags": [x['tag'] for x in codeTags]}
コード例 #9
0
def getApprovedOutages() -> dict:
    appConf = getConfig()
    oRepo = OutagesRepo(appConf['pwcDbConnStr'])
    outages = oRepo.getApprovedOutages(dt.datetime.now())
    return jsonify({"outages": outages})
コード例 #10
0
def getLatestUnrevivedOutages() -> dict:
    appConf = getConfig()
    outages = getLatestUnrevOutages(appConf['appDbConnStr'],
                                    appConf['pwcDbConnStr'])
    return jsonify({"outages": outages})