1

I am creating a webpage that displays a list of object that exist in a database/table. I have a stored procedure which retrieves the data from the table and associates with each column the data will be parse into a table.

<table id="fileTable" class="display">
    <thead>
        <tr>
            <th>Jobstream Id</th>
            <th>Date</th>
            <th>Server Name</th>
            <th>Request Time</th>
            <th>Status</th>
            <th>StepStatus</th>
            <th>LastUpdate</th>
            <th>DeleteJob</th>
        </tr>
    </thead>
    <tbody>
    #for $i in range(0,$rows.__len__())
        <tr>
            <td>$rows[i].get('JobstreamName')</td>
            <td>$rows[i].get('Date')</td>
            <td>$rows[i].get('ServerName')</td>
            <td>$rows[i].get('RequestTime')</td>
            <td>$rows[i].get('Status')</td>
            <td>$rows[i].get('StepStatus')</td>
            <td>$rows[i].get('LastUpdate')</td>
            <td><input type="submit" value="Delete"/></td>
        </tr>
    #end for
    </tbody>
</table>

There will be a "Delete" button at the end of each row, which serves the purpose of deleting whichever row (in the database) that the user wishes. The deletion of row should be run in a stored procedure. I do have a function in python that would execute the stored-procedure.

However, I have no idea how to connect the button which will return the "JobStream Id" and "Date" that serves as a parameter in executing a stored-procedure.

I am using Cheetah as a web development tools to run the python code. Appreciate any help I could get, Thanks in advance.

EDIT: Let me rephrase myself here. So, the data of the table that is produce in the webpage is being pulled from the database using a stored-procedure. I am trying to add a feature (end of each row there is a delete button) that allow the user to delete any row. Therefore I will need to pass the html variable to my python variable to run another stored-procedure, but i am unable to do so. Hope this clarify most of the confusion. Thanks

Here is the full code:

def getJobStreamStatus(Delete):
    Delete = 'Just a random string'
    user,pwd,server,db =  SPCaller.parseLogin('DMClient@gpdevdb81\\dmresrchdbdev.EquityData')
    db =  DB.dbConn(computerName=server,databaseName=db,userName=user,password=pwd)
    #results = SPCaller.readSPReturnDict('getJobStreamRerunStatus',None, 'DMClient@gpdevdb81\\dmresrchdbdev.EquityData')
    cols, rs = db.getResultSetFromSP('getJobStreamRerunStatus',None)
    #html = []
    definition = """<br><br><br><br><br><br><HR>$title 
    <table id="fileTable" class="display">
        <thead>
            <tr>
                <th>Jobstream Id</th>
                <th>Date</th>
                <th>Server Name</th>
                <th>Request Time</th>
                <th>Status</th>
                <th>StepStatus</th>
                <th>LastUpdate</th>
                <th>DeleteJob</th>
            </tr>
        </thead>
        <tbody>
        #for $i in range(0,$rows.__len__())
            <tr>
            <td>$rows[i].get('JobstreamName')</td>
            <td>$rows[i].get('Date')</td>
            <td>$rows[i].get('ServerName')</td>
            <td>$rows[i].get('RequestTime')</td>
            <td>$rows[i].get('Status')</td>
            <td>$rows[i].get('StepStatus')</td>
            <td>$rows[i].get('LastUpdate')</td>
            <td><input type="button" value="Delete" name='btnEdit' class='btnEdits' /></td>
            </tr>
        #end for
        </tbody>
    </table>
    """ 

    return str(Template(definition, searchList=[{'cols':cols, 'rows':arrToDict(cols,rs),'Delete':Delete,'title':'Showing all jobs in the rerun queue with status <b>waiting: 0, running: 2, and failed: 3</b><br><br>'}]))
Benedict Lee
  • 59
  • 1
  • 9

1 Answers1

0

I don't know Python, but I think you can create a form for each row and add a hidden field with the id of the displayed row.

When the user clicks on the submit button, it will be easy for you to read the value of the hidden field for the request form collection and pass it to the stored procedure:

#for $i in range(0,$rows.__len__())
    <tr>
        <form action = "....">
           <input type="hidden" name="id" value="$rows[i].get('Id')"> 
           <td>$rows[i].get('JobstreamName')</td>
           <td>$rows[i].get('Date')</td>
           <td>$rows[i].get('ServerName')</td>
           <td>$rows[i].get('RequestTime')</td>
           <td>$rows[i].get('Status')</td>
           <td>$rows[i].get('StepStatus')</td>
           <td>$rows[i].get('LastUpdate')</td>
           <td><input type="submit" value="Delete"/></td>
        </form>
    </tr>
#end for

The code above assumes there is an id field in your data.

Paolo Costa
  • 1,989
  • 1
  • 12
  • 15
  • Thanks and sorry for the late reply. So i will need a identity column in my database to keep track of which button is being clicked? One more question, what if i use `input type="button"`? I am really new to this front-end development. – Benedict Lee May 07 '15 at 14:46
  • Type submit will automatically submit the form to the backend (it means it will start a post request against the url you set in the form action attribute, the one that I substituted with dots) If you use type button you will have to manually submit it in javascript – Paolo Costa May 07 '15 at 15:07
  • For the first part, I guess you have a primary key in your database, you just have to put the value in hidden field in order to know in the backend what element was clicked. – Paolo Costa May 07 '15 at 15:08
  • Awesome. Thanks Paolo. That solve part of the problem. But I still need to figure a way to passing variable among from html to python. I am able to passing variable from python to html, but not the other way around. – Benedict Lee May 07 '15 at 15:17
  • Unfortunately I don't know Python. On other technologies (like ASP or ASP.NET that I know) you can read the values passed on a POST request by means of code like this `Request.Form["Id"]` – Paolo Costa May 07 '15 at 15:22