Esempio n. 1
0
def post_comment(key):
	battle = Battle.get(key)
	now = datetime.now()
	if request.form.has_key('leftbox'):
		comment = request.form.get('leftbox')
		left_comment = Comment(parent=battle, comment=comment, author=users.get_current_user(), side="left", when=now)
		if request.files['left_image']:
			image_file = request.files['left_image']
			headers = image_file.headers['Content-Type']
			blob_key = parse_options_header(headers)[1]['blob-key']
			left_comment.blob_key = blob_key
			left_comment.image_url = images.get_serving_url(blob_key)
		left_comment.put()
		send_emails(key, comment)
	elif request.form.has_key('rightbox'):
		comment = request.form.get('rightbox')
		right_comment = Comment(parent=battle, comment=comment, author=users.get_current_user(), side="right", when=now)
		if request.files['right_image']:
			image_file = request.files['right_image']
			headers = image_file.headers['Content-Type']
			blob_key = parse_options_header(headers)[1]['blob-key']
			right_comment.blob_key = blob_key
			right_comment.image_url = images.get_serving_url(blob_key)
		right_comment.put()
		send_emails(key, comment)
	return left_right(key)
Esempio n. 2
0
def vote_battle(battle_key,up_or_down):
	vote = 1 if up_or_down == "up" else -1
	battle = Battle.get(battle_key)
	if check_for_user_vote_battle(battle, vote):
		battle.votes = battle.votes + vote
		battle.put()
	votes = battle.votes
	return jsonify(votes=votes)
Esempio n. 3
0
def send_emails(key,comment):
	battle = Battle.get(key)
	message = mail.EmailMessage(sender="*****@*****.**",
								subject="An update on Battle " + battle.left + " vs " + battle.right)
	for subscriber in battle.subscribers:
		message.to = subscriber
		message.body = comment + "\n by " + users.get_current_user().nickname()
		message.send()
Esempio n. 4
0
def left_right(key):
	upload_url = blobstore.create_upload_url('/post_comment/'+key)
	battle = Battle.get(key)
	left_comments = Comment.all().ancestor(battle).order('-votes').filter('side =','left')
	right_comments = Comment.all().ancestor(battle).order('-votes').filter('side =','right')
	if battle.expirationDate and battle.expirationDate < datetime.now():
			return render_template('results.html',battle=battle,leftf=battle.left,rightf=battle.right,lc=left_comments,rc=right_comments)
	return render_template('battle.html',battle=battle,key=key,
		leftf=battle.left,rightf=battle.right,
		lc=left_comments,rc=right_comments,upload_url=upload_url,current_user=users.get_current_user().email())
Esempio n. 5
0
def edit_battle(key):
	battle = Battle.get(key)
	if battle.author != users.get_current_user():
		return messages("You cannot edit this battle as you are not its owner")

	left = request.form.get('left')
	right = request.form.get('right')
	date = request.form.get('date')
	tags = ""
	
	if battle.tags:
		for t in battle.tags:
			tags = tags + t + ','
	
	if request.method == 'POST':
		if check_existing_battle(left,right,battle):
			return Response(status=400)
		if date != 'None' and date != '':
			battle.expirationDate = datetime.strptime(date,"%m/%d/%Y")
		battle.left = left
		battle.right = right
		form_tags = []
		for t in request.form.get('tags').split(','):
			form_tags.append(t.strip())
		battle.tags = []
		for tag in form_tags:
			if not tag == '':
				battle.tags.append(tag)
		battle.put()
		return Response(status=200)

	if battle.expirationDate:
		battle_date = battle.expirationDate.strftime("%m/%d/%Y")
	else:
		battle_date = 'None'
	return render_template('edit_battle.html',battle=battle,tags=tags,date=battle_date)
Esempio n. 6
0
def unsubscribe(key):
	battle = Battle.get(key)
	battle.subscribers.remove(str(users.get_current_user().email()))
	battle.put()
	return Response(status=200)
Esempio n. 7
0
def remove_battle(key):
	battle = Battle.get(key)
	if battle.author != users.get_current_user():
		return messages("You cannot delete this battle as you are not its owner")
	db.delete(battle)
	return redirect('/yourbattles')
Esempio n. 8
0
def subscribe(key):
	battle = Battle.get(key)
	if not battle.subscribers.__contains__(users.get_current_user().email()):
		battle.subscribers.append(str(users.get_current_user().email()))
		battle.put()
	return Response(status=200)