本文整理汇总了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)