将数据从循环的jinja类中的特定类发送到模式

时间:2019-05-03 22:53:47

标签: javascript python jquery sqlalchemy flask-sqlalchemy

我想将烧瓶路径中的特定数据发送到另一个模板,或更具体地说是模式。 我希望能够从数据中选择动态创建的div之一 通过按``详细信息''按钮从烧瓶传递数据,并将其关联的数据(例如(位置名称))发送到模态,该模态随显示的数据表一起弹出。问题是我无法从循环烧瓶数据中选择任何特定的数据/类以发送回模板或更多我不知道的模板。

不确定在关联的div中按下按钮时是否需要JS或Jquery来选择div顶部的位置名称,这样我就可以将该数据发送到模板以便以任何方式查询,然后就可以解决了。发送。请尽可能提供帮助。

这是从用户查看的内容。这是在db中每个不同位置编号之间创建的动态内容:

enter image description here

在按详细信息按钮时,请指向正确的方向 -从

上单击的元素中选择关联的数据

这是html的示例。我写的html太长了,无法粘贴,但这是一般的想法。我需要能够访问位置名称或按下详细信息按钮时执行的x操作,并将其发送到模板或模态。

{% for totals, x, answered, no_answer in location %}
<div class='test'>
    <div>location {{x.did}}<div>
    <div>{{totals}}</div>
    <div>{{answered}}</div>
    <div> {{no_answer}} </div>
</div>

-然后将数据发送到按“详细信息”按钮时弹出的模式。

这是已查询数据以发送到模板的路由

 @app.route('/', methods = ['POST', 'GET'])
    def reports():
    form = ReportConfig()
    location = Cdr.query.with_entities(Cdr.did).distinct().all()

    totals = []
    answered = []
    no_answer = []

    for x in location:
        test = str(x.did)
        totalcalls = connection.execute(f"SELECT COUNT(calldate) FROM cdr WHERE did='{test}'")
        answered_count = connection.execute(f"SELECT COUNT(calldate) FROM cdr WHERE did='{test}' AND disposition='ANSWERED'")
        no = connection.execute(f"SELECT COUNT(calldate) FROM cdr WHERE did='{test}' AND disposition='NO ANSWER'")

        answer_num = [row[0] for row in answered_count]
        print(answer_num[0])

        nono = [row[0] for row in no]
        print(nono[0])

        total = [row[0] for row in totalcalls]
        print(total[0])

        totals.append(total[0])
        answered.append(answer_num[0])
        no_answer.append(nono[0])

    if request.method == 'POST':
        print('You have validated mane')
        form = ReportConfig()
        start_date = request.form['start_date']
        end_date = request.form['end_date']
        location = Cdr.query.with_entities(Cdr.did).distinct().all()    

        totals = []
        answered = []       
        no_answer = []

        for x in location:
            test = str(x.did)
            totalcalls = connection.execute(f"SELECT COUNT(calldate) FROM cdr WHERE did='{test}' and calldate between '{start_date} 08:00:00' and '{end_date} 08:00:00'")
            answered_count = connection.execute(f"SELECT COUNT(calldate) FROM cdr WHERE did='{test}' AND disposition='ANSWERED' AND calldate between '{start_date} 08:00:00' and '{end_date} 08:00:00'")
            no = connection.execute(f"SELECT COUNT(calldate) FROM cdr WHERE did='{test}' AND disposition='NO ANSWER' AND calldate between '{start_date} 08:00:00' and '{end_date} 08:00:00'")

            answer_num = [row[0] for row in answered_count]
            print(answer_num[0])

            nono = [row[0] for row in no]
            print(nono[0])

            total = [row[0] for row in totalcalls]
            print(total[0])

            totals.append(total[0])
            answered.append(answer_num[0])
            no_answer.append(nono[0])
            print(start_date, end_date)
        return render_template('reports.html', form=form, location=zip(totals, location, answered, no_answer))
    return render_template('reports.html', title='Home', form=form, location=zip(totals, location, answered, no_answer))

0 个答案:

没有答案