本文整理汇总了Python中models.Vote.put方法的典型用法代码示例。如果您正苦于以下问题:Python Vote.put方法的具体用法?Python Vote.put怎么用?Python Vote.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Vote
的用法示例。
在下文中一共展示了Vote.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def update(self, votes, addCat):
# Delete the old votes and replace them with the request data.
# This avoids cases where the form data doesn't match the
# current database (e.g. from the back button or a cloned
# window).
if self.ballot:
db.delete(votes)
ballot = self.ballot
else:
ballot = Ballot(voter=self.voter, year=self.year)
ballot.anonymous = bool(self.request.get('anonymous'))
ballot.preamble = self.request.get('preamble')
ballot.postamble = self.request.get('postamble')
numVotes = dict()
for cat in Ballot.categories:
numVotes[cat] = int(self.request.get(cat + 's'))
ballot.honorable = numVotes['honorable']
if addCat == 'honorable':
ballot.honorable += 10
ballot.notable = numVotes['notable']
if addCat == 'notable':
ballot.notable += 10
ballot.put()
for cat in Ballot.categories:
for rank in range(1, numVotes[cat]+1):
artist = self.request.get('%s%dartist' % (cat, rank))
title = self.request.get('%s%dtitle' % (cat, rank))
comments = self.request.get('%s%dcomments' % (cat, rank))
if artist or title or comments:
vote = Vote(parent=ballot, ballot=ballot,
category=cat, rank=rank,
artist=artist, title=title, comments=comments)
vote.put()
示例2: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def post(self):
loser = db.get(str(self.request.get('loser')))
winner = db.get(str(self.request.get('winner')))
vote = Vote(winner=winner, loser=loser)
#To store username if the user is logged in
client = OAuthClient("twitter", self)
logged_in = client.get_cookie()
if logged_in:
info = client.get("/account/verify_credentials")
vote.name = info["screen_name"]
else:
vote.name = 'Guest'
#TODO: Stop spam-voting for same key from same ip repeatedly
vote.ip = self.request.remote_addr
if check_vote_spam(vote.ip, winner):
self.redirect('/msg=You+appear+to+be+votespamming,+please+stop+or+try+again+later')
else:
vote.put()
#Wins and losses
loser.losses = loser.losses+1
loser.win_percentage = loser.calc_win_percentage()
loser.put()
winner.wins = winner.wins+1
winner.win_percentage = winner.calc_win_percentage()
winner.put()
#Redirect so that people cannot repost twice
self.redirect('/?w=%s&l=%s' % (winner.key().id(), loser.key().id()))
示例3: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def post(self):
url = self.request.get("url")
title = sanitizeHtml(self.request.get("title"))
message = sanitizeHtml(self.request.get("message"))
session = get_current_session()
if session.has_key("user") and len(title) > 0:
user = session["user"]
# decide if its a message or a link, if its a link we need a try/catch around the save, the link might be invalid
if len(message) == 0:
try:
post = Post(url=url, title=title, message=message, user=user)
post.put()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
Post.remove_cached_count_from_memcache()
self.redirect("/noticia/" + str(post.key()))
except db.BadValueError:
self.redirect("/agregar")
else:
post = Post(title=title, message=message, user=user)
post.put()
post.url = "http://" + urlparse(self.request.url).netloc + "/noticia/" + str(post.key())
post.put()
Post.remove_cached_count_from_memcache()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect("/noticia/" + str(post.key()))
else:
self.redirect("/")
示例4: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def post(self):
url = self.request.get('url')
title = sanitizeHtml(self.request.get('title'))
message = sanitizeHtml(self.request.get('message'))
session = get_current_session()
if session.has_key('user') and len(title) > 0:
user = session['user']
# decide if its a message or a link, if its a link we need a try/catch around the save, the link might be invalid
if len(message) == 0:
try:
post = Post(url=url,title=title,message=message, user=user)
post.put()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect('/noticia/' + str(post.key()));
except db.BadValueError:
self.redirect('/agregar')
else:
post = Post(title=title,message=message, user=user)
post.put()
post.url = "http://" + urlparse(self.request.url).netloc + "/noticia/" + str(post.key())
post.put()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect('/noticia/' + str(post.key()));
else:
self.redirect('/')
示例5: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def post(self, post_id):
session = get_current_session()
if session.has_key('user'):
message = helper.sanitizeHtml(self.request.get('message'))
user = session['user']
key = self.request.get('comment_key')
if len(message) > 0 and key == keys.comment_key:
try:
post = Post.all().filter('nice_url =', helper.parse_post_id( post_id ) ).get()
if post == None: #If for some reason the post doesn't have a nice url, we try the id. This is also the case of all old stories
post = db.get( helper.parse_post_id( post_id ) )
post.remove_from_memcache()
comment = Comment(message=message,user=user,post=post)
comment.put()
helper.killmetrics("Comment","Root", "posted", session, "",self)
vote = Vote(user=user, comment=comment, target_user=user)
vote.put()
Notification.create_notification_for_comment_and_user(comment,post.user)
self.redirect('/noticia/' + post_id)
except db.BadKeyError:
self.redirect('/')
else:
self.redirect('/noticia/' + post_id)
else:
self.redirect('/login')
示例6: vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def vote(request, id):
"""
Add a vote for a feedback message, but not twice from the same IP.
"""
referer = request.META.get('HTTP_REFERER', '/feedback/')
redirect = HttpResponseRedirect(referer)
# Check if the selected feedback exists.
feedback = Feedback.get_by_id(int(id))
if feedback is None:
logging.debug("Feedback '%s' not found." % id)
return redirect
# Check if this feedback was posted from the same IP.
ip = request.META.get('REMOTE_ADDR', '0.0.0.0')
if feedback.ip == ip:
logging.debug("Feedback '%s' was posted from the same IP." % id)
return redirect
# Check if this IP has already voted for this feedback.
already = Vote.all().filter('feedback', feedback).filter('ip', ip).count()
if already:
logging.debug("Feedback '%s' was already voted %d times from this IP."
% (id, already))
return redirect
# Register this vote to prevent double voting.
vote = Vote(feedback=feedback, ip=ip)
vote.put()
# Increase the points for this feedback.
feedback.points += 1
feedback.put()
return redirect
示例7: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def post(self):
session = get_current_session()
url = self.request.get("url")
title = helper.sanitizeHtml(self.request.get("title"))
message = helper.sanitizeHtml(self.request.get("message"))
nice_url = helper.sluglify(title)
if session.has_key("user"):
if len(nice_url) > 0:
user = session["user"]
if len(message) == 0: # is it a post or a message?
# Check that we don't have the same URL within the last 'check_days'
since_date = date.today() - timedelta(days=7)
q = Post.all().filter("created >", since_date).filter("url =", url).count()
url_exists = q > 0
q = Post.all().filter("nice_url", nice_url).count()
nice_url_exist = q > 0
try:
if not url_exists:
if not nice_url_exist:
post = Post(url=url, title=title, message=message, user=user, nice_url=nice_url)
post.put()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
Post.remove_cached_count_from_memcache()
self.redirect("/noticia/" + str(post.nice_url))
else:
session["post_error"] = "Este titulo ha sido usado en una noticia anterior"
self.redirect("/agregar")
else:
session["post_error"] = "Este link ha sido entregado en los ultimo 7 dias"
self.redirect("/agregar")
except db.BadValueError:
session["post_error"] = "El formato del link no es valido"
self.redirect("/agregar")
else:
q = Post.all().filter("nice_url", nice_url).count()
nice_url_exist = q > 0
if not nice_url_exist:
post = Post(title=title, message=message, user=user, nice_url=nice_url)
post.put()
post.url = helper.base_url(self) + "/noticia/" + post.nice_url
post.put()
Post.remove_cached_count_from_memcache()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect("/noticia/" + post.nice_url)
else:
session["post_error"] = "Este titulo ha sido usado en una noticia anterior"
self.redirect("/agregar")
else:
session["post_error"] = "Necesitas agregar un titulo"
self.redirect("/agregar")
else:
self.redirect("/login")
示例8: increase_vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def increase_vote(item, owner, cur_votes):
if item == None:
return cur_votes
# Check duplicate
q = db.GqlQuery("SELECT * FROM Vote WHERE item = :1 AND owner = :2", item, owner)
if q.count() > 0:
ret = """<span id="vote_result">%d</span> <span id="vote_message" style="color: #666666;">(已推薦過)</span>""" % (cur_votes, )
return ret
vote = Vote(owner=owner, item=item)
vote.put()
ret = """<span id="vote_result" style="color: #EB7F00; text-weight: bold">%d</span>""" % (item.vote_set.count(), )
return ret
示例9: get
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def get(self, post_id):
session = get_current_session()
if session.has_key("user"):
user = session["user"]
try:
post = db.get(post_id)
if not post.already_voted():
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
post.remove_from_memcache()
post.user.remove_from_memcache()
self.response.out.write("Ok")
else:
self.response.out.write("No")
except db.BadValueError:
self.response.out.write("Bad")
else:
self.response.out.write("Bad")
示例10: get
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def get(self,comment_id):
session = get_current_session()
if session.has_key('user'):
user = session['user']
try:
comment = db.get(comment_id)
if not comment.already_voted():
vote = Vote(user=user, comment=comment, target_user=comment.user)
vote.put()
comment.remove_from_memcache()
comment.user.remove_from_memcache()
self.response.out.write('Ok')
else:
self.response.out.write('No')
except db.BadValueError:
self.response.out.write('Bad')
else:
self.response.out.write('Bad')
示例11: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def post(self):
title = self.request.get('title')
description = self.request.get('description')
owner = int(self.request.get('uid'))
# Check duplicate
q = db.GqlQuery("SELECT * FROM Item WHERE title = :1", title)
if q.count(1) > 0:
self.response.out.write(simplejson.dumps({'result': 'duplicated', 'title': title}))
return
# Not duplicated
item = Item(title=title, description=description, owner=owner)
key = item.put()
vote = Vote(item=item, owner=owner)
vote.put()
self.response.out.write(simplejson.dumps({'result': 'added', 'title': title, 'key': key.id()}))
示例12: get
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def get(self,post_id):
session = get_current_session()
if session.has_key('user'):
user = session['user']
try:
post = db.get(post_id)
if not post.already_voted():
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
post.remove_from_memcache()
post.user.remove_from_memcache()
helper.killmetrics("Vote","News", "do", session, "",self)
self.response.out.write('Ok')
else:
self.response.out.write('No')
except db.BadValueError:
self.response.out.write('Bad')
else:
self.response.out.write('Bad')
示例13: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def post(self):
session = get_current_session()
url = self.request.get('url')
title = helper.sanitizeHtml(self.request.get('title'))
message = helper.sanitizeHtml(self.request.get('message'))
if session.has_key('user'):
if len(title) > 0:
user = session['user']
if len(message) == 0: #is it a post or a message?
#Check that we don't have the same URL within the last 'check_days'
since_date = date.today() - timedelta(days=7)
q = Post.all().filter("created >", since_date).filter("url =", url).count()
url_exists = q > 0
try:
if not url_exists:
post = Post(url=url,title=title,message=message, user=user)
post.put()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
Post.remove_cached_count_from_memcache()
self.redirect('/noticia/' + str(post.key()));
else:
session['post_error'] = "Este link ha sido entregado en los ultimo 7 dias"
self.redirect('/agregar')
except db.BadValueError:
session['post_error'] = "El formato del link no es valido"
self.redirect('/agregar')
else:
post = Post(title=title,message=message, user=user)
post.put()
post.url = helper.base_url(self) + "/noticia/" + str(post.key())
post.put()
Post.remove_cached_count_from_memcache()
vote = Vote(user=user, post=post, target_user=post.user)
vote.put()
self.redirect('/noticia/' + str(post.key()));
else:
session['post_error'] = "Necesitas agregar un titulo"
self.redirect('/agregar')
else:
self.redirect('/login')
示例14: vote
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def vote(netid, talk_id, direction):
app.logger.info(dir(netid))
app.logger.info(netid)
votes = Vote.all()
votes.filter('talk_id =', talk_id)
votes.filter('netid =', netid)
votes_res = votes.fetch(1)
netid = str(netid)
if len(votes.fetch(1)) < 1 or (votes_res[0].direction != 'up' and votes_res[0].direction != 'down'):
# User has not voted before
new_vote = Vote(direction=direction, netid=str(netid), talk_id=talk_id)
talk = Talk.get_by_id(talk_id)
if direction == 'up':
talk.votes += 1
elif direction == 'down':
talk.votes -= 1
talk.put()
new_vote.put()
app.logger.info("Did a vote")
return redirect(url_for('index'))
elif votes_res[0].direction != direction:
# The user has voted and is changing
vote = votes_res[0]
vote.direction = direction
talk = Talk.get_by_id(talk_id)
if direction == 'up':
talk.votes += 2
elif direction == 'down':
talk.votes -= 2
talk.put()
vote.put()
app.logger.info("Did a exist vote")
return redirect(url_for('index'))
else:
# User is not allowed to vote
return redirect(url_for('index'))
示例15: post
# 需要导入模块: from models import Vote [as 别名]
# 或者: from models.Vote import put [as 别名]
def post(self,comment_id):
session = get_current_session()
if session.has_key('user'):
message = helper.sanitizeHtml(self.request.get('message'))
user = session['user']
if len(message) > 0:
try:
parentComment = db.get(comment_id)
comment = Comment(message=message,user=user,post=parentComment.post, father=parentComment)
comment.put()
helper.killmetrics("Comment","Child", "posted", session, "",self)
comment.post.remove_from_memcache()
vote = Vote(user=user, comment=comment, target_user=user)
vote.put()
Notification.create_notification_for_comment_and_user(comment,parentComment.user)
self.redirect('/noticia/' + str(parentComment.post.key()))
except db.BadKeyError:
self.redirect('/')
else:
self.redirect('/responder/' + comment_id)
else:
self.redirect('/login')