constituency.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:electioncharts 作者: mickeykedia 项目源码 文件源码
def get_constituency_result_1(db,constituency_id):
    cursor = db.cursor()
    cursor.execute('''SELECT ca.id, ca.fullname, p.id, p.name, r.time_start, r.votes, p.symbol
      FROM results r, candidate_constituency c_c, candidate ca, constituency co, party p 
      where c_c.constituency_id=co.id and c_c.candidate_id=ca.id 
      and c_c.party_id=p.id and r.candidate_id=ca.id and r.constituency_id=co.id 
      and r.active=1  and c_c.election="2014" and r.constituency_id='''+ constituency_id +''' order 
      by r.votes desc;''')
    output={'total_votes':0}
    results=[]
    for row in cursor.fetchall():
        temp_map={}
        temp_map['candidate_id']=row[0]
        temp_map['candidate_name']=cgi.escape(row[1]).title()
        temp_map['party_id']=row[2]
        temp_map['party_name']=cgi.escape(row[3]).title()
        temp_map['votes']=row[5]
        temp_map['party_symbol']=row[6]
        output['total_votes']=output['total_votes']+row[5]
        results.append(temp_map)
    output['result_list']=results
    return output
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号