当前位置: 首页>>代码示例>>Python>>正文


Python Vote.hash_digest方法代码示例

本文整理汇总了Python中models.Vote.hash_digest方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.hash_digest方法的具体用法?Python Vote.hash_digest怎么用?Python Vote.hash_digest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Vote的用法示例。


在下文中一共展示了Vote.hash_digest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: polling_station_vote

# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import hash_digest [as 别名]
def polling_station_vote(ballot_id):
    ballot = db.session.query(Ballot).get(ballot_id)
    if ballot is None:
        abort(404)
    permit_voting(ballot)

    input_options = pickle.loads(request.form["input_options_data"])
    try:
        validate_options(input_options, ballot)
    except ValidationError as e:
        flash(unicode(e), "danger")
        return redirect(url_for('polling_station_item', ballot_id=ballot_id))
    except ValueError as e:
        flash(u"Některý z hlasů má neplatnou hodnotu", "danger")
        return redirect(url_for('polling_station_item', ballot_id=ballot_id))

    try:
        vote_timestamp = session.get(
            "vote_timestamp_{}".format(ballot_id), False)
        if not vote_timestamp:
            raise ValidationError()
        hash_base = compute_hash_base(ballot_id, g.user.id,
                                      input_options, vote_timestamp)
        hash_salt = request.form["hash_salt"]
        h = hashlib.sha1()
        h.update(hash_base.encode("utf-8"))
        h.update(hash_salt.encode("utf-8"))
        hash_digest = h.hexdigest()
    except Exception as e:
        flash(u"Chyba při výpočtu kontrolního řetězce", "danger")
        return redirect(url_for('polling_station_item', ballot_id=ballot_id))

    for (option_id, value) in input_options.items():
        vote = Vote()
        vote.ballot_option_id = option_id
        vote.value = value
        vote.hash_digest = hash_digest
        db.session.add(vote)

    voter = Voter()
    voter.ballot_id = ballot_id
    voter.name = g.user.name
    voter.email = g.user.email
    voter.person_id = g.user.id
    voter.voted_at = datetime.datetime.now()
    voter.remote_addr = request.remote_addr
    voter.user_agent = request.user_agent.string
    db.session.add(voter)

    send_mail = "send_confirmation_email" in request.form
    email_body = send_vote_confirmation(ballot, voter, hash_digest,
                                        hash_salt, vote_timestamp, send_mail)

    db.session.commit()

    return render_template(
        'polling_station_vote.html', ballot=ballot,
        hash_digest=hash_digest, email_body=email_body, really_send=send_mail)
开发者ID:svobodni,项目名称:ballot_box,代码行数:60,代码来源:views.py


注:本文中的models.Vote.hash_digest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。