Ejemplo n.º 1
0
    def GET(self, session):
        print("LoadConfig Session:%s" % (session))
        webInsMgr.AddIns(int(session))
        webInsMgr.InstanceList[int(session)].ConfigMgr = configmgr.ConfigMgr(
        )  # Intializeds ConfigMgr within Instance
        #print ("Load Config: %s" %(webInsMgr.InstanceList[int(session)].ConfigMgr.GetConfigFileList()))
        #FileListDict =
        print()

        FileChoiceFormTable = HtmlTable(['Available Config Files'])
        FileChoiceFormTableSub = HtmlTable(['', 'Config File'])
        fpstring = 'LoadConfig/%s' % (session)
        print("Fpstring %s" % (fpstring))
        GetConfigFileDict = webInsMgr.InstanceList[int(
            session)].ConfigMgr.GetConfigFileList()
        for fileIndex in GetConfigFileDict:
            temp_Form = form.Form(
                form.Button('Load',
                            type="submit",
                            value=fileIndex,
                            target=fpstring,
                            id="submit"))
            FileChoiceFormTableSub.AddRow(
                [temp_Form.render(),
                 '%s' % (GetConfigFileDict[fileIndex])])

        FileChoiceFormTable.AddRow([FileChoiceFormTableSub])

        webInsMgr.InstanceList[int(session)].UpdateAccessTime()

        return render2.LoadExisting(0, FileChoiceFormTable.GetFormattedHtml(),
                                    session)
Ejemplo n.º 2
0
 def getBody(self):
     table = HtmlTable(cellspacing=2, cellpadding=2, border=1)
     table.addHeader(['Painter', 'Style', 'Born', 'Until'])
     table.setRowBGColor(table.rownum, 'lightgreen')
     for row in self.getData():
         table.addRow(row)
     return center(table.getTable())
Ejemplo n.º 3
0
 def GetHtmlTable(self, NewHtmlTable, divId=None, action=None, method=None, ajax = True):
     """
         GetHtmlTable(self, NewHtmlTable, divId=None, action=None, method=None, ajax = True):
     """
     if divId is not None:
         divId = self.divStrip(divId)
     table = HtmlTable(NewHtmlTable, divId, action, method, ajax)
     self.divGetHtml[divId] = table.GetFormattedHtml
     return table
Ejemplo n.º 4
0
    def GetAdminTableOutput(self):
        #self.Logger.addLog("AddInstance called")
        TableBase = HtmlTable(['Admin'])
        TableFreeSessionView = HtmlTable(
            ['# Active Sessions', '# Available Sessions for New Connections'])
        SessCount = self.GetCurrentCount()
        TableFreeSessionView.AddRow([SessCount, self.MaxInstances - SessCount])
        TableManageSessions = HtmlTable(
            ['Session Number', 'Last Active Time', 'Action'])
        TableManageServer = HtmlTable(['Restart Manager', 'Restart Server'])
        ManagerActionForm = form.Form(
            form.Button('RestartMan',
                        type="submit",
                        value='restart_man',
                        id="submit"))
        ServerActionForm = form.Form(
            form.Button('RestartSer',
                        type="submit",
                        value='restart_ser',
                        id="submit"))
        TableManageServer.AddRow([
            render2.Admin(ManagerActionForm),
            render2.Admin(ServerActionForm)
        ])
        SessionTrack = {}
        for session in self.InstanceList:
            ActionForm = form.Form(
                form.Button('kill: %d' % (session), value=session,
                            id="submit"))
            SessionIns = ActionForm()
            SessionTrack[session] = SessionIns
            TableManageSessions.AddRow([
                session, self.InstanceList[session].LastAccessTime,
                render2.Admin(SessionTrack[session])
            ])
        for Table in [
                TableFreeSessionView, TableManageSessions, TableManageServer
        ]:
            TableBase.AddRow([Table])

        return TableBase.GetFormattedHtml()
Ejemplo n.º 5
0
def GetHtmlOut(session, formMgr, tableName, table):
    BaseTb = HtmlTable([tableName], tableName + '_base')
    xyTable = HtmlTable(['X', 'Y'], tableName + '_data')
    for xOrY in table:
        xyTable.AddRow([xOrY[0], xOrY[1]])
    xyAddToTable = HtmlTable(['Add To Table'], '%s_addTb' % (tableName))
    testTextBox = GlobalFormMgr.GetTextBox('noSession', 'xAddTb', '')
    testTextBox2 = GlobalFormMgr.GetTextBox('noSession', 'yAddTb', '')
    testButton1 = GlobalFormMgr.GetButton('noSession', 'submit', tableName,
                                          tableName + '_base', tableName)
    testButton2 = GlobalFormMgr.GetButton('noSession', 'delete', tableName,
                                          tableName + '_base', tableName)
    #RenderedForm = GlobalFormMgr.GetRenderedForm('noSession', [testTextBox,testTextBox2, testButton1, testButton2], tableName,'/getposttest/', 'POST', True)
    InputTable = HtmlTable(
        [testTextBox, testTextBox2,
         HtmlTable([testButton1, testButton2])], tableName, '/getposttest/',
        'POST')
    xyAddToTable.AddRow([InputTable])
    BaseTb.AddRow([xyTable])
    BaseTb.AddRow([xyAddToTable])
    return BaseTb.GetFormattedHtml()
Ejemplo n.º 6
0
 def GetHtmlTable(self,
                  NewHtmlTable,
                  divId=None,
                  action=None,
                  method=None,
                  ajax=True):
     table = HtmlTable(NewHtmlTable, divId, action, method, ajax)
     if divId is not None:
         if ' ' in divId:
             divId = ''.join(divId.split(' '))
             self.divGetHtml[divId] = table.GetFormattedHtml
         else:
             self.divGetHtml[divId] = table.GetFormattedHtml
     return table
Ejemplo n.º 7
0
def htmlify(data, type='table'):
    if isinstance(data, list):
        table = HtmlTable(cellpadding=2)
        for row in data:
            if isinstance(row, list):
                for i, col in enumerate(row):
                    if isinstance(col, list):
                        row[i] = ', '.join(str(c) for c in col)
                table.addRow(row)
            else:
                table.addRow([str(row)])
        return table.getTable()
    if isinstance(data, dict):
        if type == 'table':
            return dict2table(data)
        return dict2dl(data)
    if isinstance(data, (str, unicode)) and '\033[' in data:
        from utils import system_call
        return system_call("echo '%s' | aha" % data, 1)

    return p(data)
Ejemplo n.º 8
0
def dict2table(data):
    table = HtmlTable()
    for k, v in sorted(data.items()):
        table.addRow([k or " ", str(v)])
    return table.getTable()
Ejemplo n.º 9
0
    def POST(self):
        TableBase = HtmlTable(['Admin'])
        TableFreeSessionView = HtmlTable(
            ['# Active Sessions', '# Available Sessions for New Connections'])
        SessCount = webInsMgr.GetCurrentCount()
        TableFreeSessionView.AddRow(
            [SessCount, webInsMgr.MaxInstances - SessCount])
        TableManageSessions = HtmlTable(
            ['Session Number', 'Last Active Time', 'Action'])
        TableManageServer = HtmlTable(['Restart Manager', 'Restart Server'])
        ManagerActionForm = form.Form(
            form.Button('RestartMan',
                        type="submit",
                        value='restart_man',
                        id="submit"))
        ServerActionForm = form.Form(
            form.Button('RestartSer',
                        type="submit",
                        value='restart_ser',
                        id="submit"))
        TableManageServer.AddRow([
            render2.Admin(ManagerActionForm),
            render2.Admin(ServerActionForm)
        ])
        SessionTrack = {}

        to_clean = []

        for session in webInsMgr.InstanceList:
            ActionForm = form.Form(
                form.Button('kill: %d' % (session), value=session,
                            id="submit"))
            SessionIns = ActionForm()
            SessionTrack[session] = SessionIns
            if SessionTrack[session].validates():
                for item in SessionTrack[session].d:
                    if not SessionTrack[session].d[item] == None:
                        to_clean.append(int(SessionTrack[session].d[item]))
                pass
            else:
                pass
        for clean_up_item in to_clean:
            webInsMgr.CleanUpSession(clean_up_item)
        for session in webInsMgr.InstanceList:
            TableManageSessions.AddRow([
                session, webInsMgr.InstanceList[session].LastAccessTime,
                render2.Admin(SessionTrack[session])
            ])

        for Table in [
                TableFreeSessionView, TableManageSessions, TableManageServer
        ]:
            TableBase.AddRow([Table])

        Manager = ManagerActionForm()
        Server = ServerActionForm()
        if not Manager.validates() or not Server.validates():
            return render2.AdminBase(TableBase.GetFormattedHtml())
        else:
            print(Manager.d)
            print(Server.d)

            for item in Manager.d:
                if not Manager.d[item] == None:
                    print("Restart Manager called")
                    webInsMgr.RestartManager()
                    webInsMgr.CleanCache()
            for item in Server.d:
                if not Server.d[item] == None:
                    import os
                    os.system(
                        'echo place-holder for restart of ignition service')

            TableBase = HtmlTable(['Admin'])
            TableFreeSessionView = HtmlTable([
                '# Active Sessions', '# Available Sessions for New Connections'
            ])
            SessCount = webInsMgr.GetCurrentCount()
            TableFreeSessionView.AddRow(
                [SessCount, webInsMgr.MaxInstances - SessCount])
            TableManageSessions = HtmlTable(
                ['Session Number', 'Last Active Time', 'Action'])
            TableManageServer = HtmlTable(
                ['Restart Manager', 'Restart Server'])
            ManagerActionForm = form.Form(
                form.Button('RestartMan',
                            type="submit",
                            value='restart_man',
                            id="submit"))
            ServerActionForm = form.Form(
                form.Button('RestartSer',
                            type="submit",
                            value='restart_ser',
                            id="submit"))
            TableManageServer.AddRow([
                render2.Admin(ManagerActionForm),
                render2.Admin(ServerActionForm)
            ])
            SessionTrack = {}
            for session in webInsMgr.InstanceList:
                ActionForm = form.Form(
                    form.Button('kill: %d' % (session),
                                value=session,
                                id="submit"))
                SessionIns = ActionForm()
                SessionTrack[session] = SessionIns
                TableManageSessions.AddRow([
                    session, webInsMgr.InstanceList[session].LastAccessTime,
                    render2.Admin(SessionTrack[session])
                ])
            for Table in [
                    TableFreeSessionView, TableManageSessions,
                    TableManageServer
            ]:
                TableBase.AddRow([Table])

            return render2.AdminBase(TableBase.GetFormattedHtml())
Ejemplo n.º 10
0
    def my_database(self,
                    c_code="",
                    c_title="",
                    c_level="",
                    c_unit="",
                    c_score="",
                    edit="",
                    delete="",
                    option=""):
        dbase = Model()
        grades = GradeGenerator()

        users = dbase.view_user()
        my_link = dbase.view_user()[0]
        if my_link[3] == "UG":
            user_cat = "Undergraduate"
        else:
            user_cat = "Postgraduate"

        dbase_content = dbase.view_user_database()

        if dbase_content == []:
            if c_code == "" and c_level == "" and c_unit == "" and c_score == "":
                all_contents = "<section class=\"mt-3\"><p class=\"text-center text-info\">Your Courses are not available yet for calculating your CGPA</p></section>"
            else:
                c_grade = grades.generate_4_points(c_score)
                dbase.insert_user_database(c_code, c_title, c_level, c_unit,
                                           c_score, c_grade)
                all_contents = "<section class=\"mt-3\"><p class=\"text-center text-success\">Your Database has been initialized. Click \"View Updated Courses\" to continue.</p></section>"
        elif dbase_content != []:

            dbase_general_summary = dbase.general_summary()[0]
            tcourses = dbase_general_summary[0]
            tunits = dbase_general_summary[1]
            tcgpa = round(dbase_general_summary[2] / tunits, 2)

            #BREAKDOWN
            dbase_breakdown_summary = dbase.breakdown_summary()
            if dbase_breakdown_summary == []:
                display_breakdown_summary = ""
            else:
                display_all_summary = []
                for eachsummary in dbase_breakdown_summary:
                    tgpa = round(eachsummary[3] / eachsummary[2], 2)
                    eachline = "<label><strong>" + str(
                        eachsummary[0]
                    ) + " Level</strong><br/> Courses <span><em>" + str(
                        eachsummary[1]
                    ) + "</em></span>, Total Units: <span><em>" + str(
                        eachsummary[2]
                    ) + "</em></span>, GPA: <span><em><strong>" + str(
                        tgpa) + "</strong></em></span></label><br/>"
                    display_all_summary.append(eachline)

                display_breakdown_summary_inner = "".join(display_all_summary)
                display_breakdown_summary = """
    <label><strong><u>CATEGORY</u></strong></label>: %s<br/>
    <label><strong><u>BREAKDOWN</u></strong></label><br/>
    %s
                """ % (user_cat, display_breakdown_summary_inner)

                if my_link[3] == "UG":
                    designate = grades.grade_scale_4_points(tcgpa)
                else:
                    designate = grades.grade_scale_msc_points(tcgpa)

            go = HtmlTable()
            go.add_headers([
                "Course Code", "Course Title", "Course Level", "Course Unit",
                "Course Score", "Course Grade"
            ])
            go.add_rows(dbase_content)
            all_table = go.show_table()

            if c_code == "" and c_level == "" and c_unit == "" and c_score == "" and edit == "" and delete == "" and option == "":
                all_contents = self.display.database_summary(
                    display_breakdown_summary, tcourses, tunits, tcgpa,
                    designate, all_table)
            elif c_code != "" and c_level != "" and c_unit != "" and c_score != "" and edit == "" and delete == "" and option == "":
                try:
                    c_grade = grades.generate_4_points(c_score)
                    dbase.insert_user_database(c_code, c_title, c_level,
                                               c_unit, c_score, c_grade)
                except Exception as e:
                    double_entry_error = """
                    <section class="text-center col-sm-8 mt-2 mx-auto">
                        <label class="text-danger">Double Entry Error: Your Database already has a course with the code %s</label><br/>
                        <labe><a href=\"my_database\" class=\"btn btn-info w-50\">Bact to my Database</a></label>
                    </section>
                    """ % (c_code)
                    all_contents = double_entry_error
                else:
                    all_contents = self.display.database_summary(
                        display_breakdown_summary, tcourses, tunits, tcgpa,
                        designate, all_table)
            elif c_code == "" and c_level == "" and c_unit == "" and c_score == "" and edit != "" and delete == "" and option == "off":
                one_course = dbase.select_user_course(edit)[0]
                edit_content = """<h3 class=\"display-5 d-inline-block w-75\"><i class="fas fa-edit"></i>Editing a Course</h3><a href=\"my_database\" class=\"btn btn-info w-25\"><i class="fas fa-backward"></i>Back</a>
                <section class="col-sm-6 mt-2 mx-auto">
                    <form action="my_database?edit=%s&option=on" method="post">
                      <section>
                        <section class="form-group">
                          <label for="c_code">Course Code: <sup class="text-danger">*</sup></label>
                          <input type="text" name="c_code" class="form-control form-control-lg" value="%s" required>
                        </section>
                        <section class="form-group">
                          <label for="c_title">Course Title: </label>
                          <input type="text" name="c_title" class="form-control form-control-lg" value="%s">
                        </section>
                        <section class="form-group">
                          <label for="c_level">Course Level: </label>
                          <input type="number" name="c_level" class="form-control form-control-lg" value="%s" maxlength="3" required>
                        </section>
                        <section class="form-group">
                          <label for="c_unit">Course Unit: <sup class="text-danger">*</sup></label>
                          <input type="number" name="c_unit" class="form-control form-control-lg" value="%s" maxlength="1" required>
                          <span class="invalid-feedback"></span>
                        </section>
                        <section class="form-group">
                          <label for="c_score">My Score: <sup class="text-danger">*</sup></label>
                          <input type="number" name="c_score" class="form-control form-control-lg" value="%s" maxlength="3" required>
                          <span class="invalid-feedback"></span>
                        </section>
                      </section>

                          <input type="submit" value="Update Course in My Database" class="btn btn-warning btn-block">
                      </section>
                    </form>
                </section>
                """ % (one_course[1], one_course[1], one_course[2],
                       one_course[3], one_course[4], one_course[5])
                all_contents = self.display.database_summary(
                    display_breakdown_summary, tcourses, tunits, tcgpa,
                    designate, edit_content)
            elif c_code != "" and c_level != "" and c_unit != "" and c_score != "" and edit != "" and delete == "" and option == "on":
                #EDITING A COURSE
                course_id = dbase.select_user_course(edit)[0][0]
                upc_grade = grades.generate_4_points(c_score)
                dbase.update_user_database(course_id, c_code, c_title, c_level,
                                           c_unit, c_score, upc_grade)
                edit_content = """<h3 class=\"display-5 d-inline-block w-75\">Editing a Course</h3><a href=\"my_database\" class=\"btn btn-info w-25\">My Database</a>
                <section class="col-sm-6 mt-2 mx-auto">
                    <label class="text-success">Course Updated Successfully!!!</label>
                </section>
                """
                all_contents = self.display.database_summary(
                    display_breakdown_summary, tcourses, tunits, tcgpa,
                    designate, edit_content)
            elif c_code == "" and c_level == "" and c_unit == "" and c_score == "" and edit == "" and delete != "" and option == "off":
                #DISPLAY COURSE TO DELETE
                one_course = dbase.select_user_course(delete)[0]
                delete_content = """
                <h3 class=\"display-5 d-inline-block w-75\"><i class="fas fa-trash-alt"></i>Deleting a Course</h3><a href=\"my_database\" class=\"btn btn-info w-25\"><i class="fas fa-backward"></i>Back</a>
                <section class="col-sm-6 mt-2 mx-auto">
                    <label>Course Title: %s</label><br/>
                    <label>Course Code: %s</label><br/>
                    <label>Course Level: %s</label><br/>
                    <label>Course Units: %s</label><br/>
                    <label>Course Score: %s</label><br/>
                    <a href=\"?delete=%s&option=on\" class="btn btn-warning">Delete This Course</a>
                </section>
                """ % (one_course[2], one_course[1], one_course[3],
                       one_course[4], one_course[5], one_course[1])
                all_contents = self.display.database_summary(
                    display_breakdown_summary, tcourses, tunits, tcgpa,
                    designate, delete_content)
            elif c_code == "" and c_level == "" and c_unit == "" and c_score == "" and edit == "" and delete != "" and option == "on":
                #DELETING COURSE
                dbase.delete_user_database(delete)
                delete_content = """<h3 class=\"display-5 d-inline-block w-75\">Deleting a Course</h3><a href=\"my_database\" class=\"btn btn-info w-25\">My Database</a>
                <section class="col-sm-6 mt-2 mx-auto">
                    <label class="text-success">Course Deleted Successfully!!!</label>
                </section>
                """
                all_contents = self.display.database_summary(
                    display_breakdown_summary, tcourses, tunits, tcgpa,
                    designate, delete_content)

        return self.display.page_open(), self.display.page_nav(
            my_link[2]), self.display.database_form(
            ), all_contents, self.display.page_close()