在python web上单击按钮时执行存储过程

时间:2021-08-25 20:43:16

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.

每行末尾将有一个“删除”按钮,用于删除用户希望的任何行(在数据库中)。删除行应该在存储过程中运行。我在python中有一个执行存储过程的函数。

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.

但是,我不知道如何连接将返回“JobStream Id”和“Date”的按钮,该按钮用作执行存储过程的参数。

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

我使用Cheetah作为Web开发工具来运行python代码。感谢我能得到的任何帮助,在此先感谢。

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

编辑:让我在这里重温一下自己。因此,使用存储过程从数据库中提取在网页中生成的表的数据。我正在尝试添加一个功能(每行的末尾有一个删除按钮),允许用户删除任何行。因此,我需要将html变量传递给我的python变量来运行另一个存储过程,但我无法这样做。希望这能澄清大部分的困惑。谢谢

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>'}]))

1 个解决方案

#1


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.

我不知道Python,但我认为你可以为每一行创建一个表单,并添加一个隐藏字段,其中包含所显示行的id。

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.

上面的代码假设您的数据中有一个id字段。

#1


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.

我不知道Python,但我认为你可以为每一行创建一个表单,并添加一个隐藏字段,其中包含所显示行的id。

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.

上面的代码假设您的数据中有一个id字段。