Ejemplo n.º 1
0
def add_recipe_comment(request, rid='', comment=''):
	dajax = Dajax()
	if request.user.is_authenticated() and request.method == 'POST':
		if rid == '':
			messages.error(request, "That recipe doesn't exist.")
			dajax.redirect('/recipe')
			return dajax.json()
		else:
			try:
				recipe = Recipe.objects.get(id=rid)
			except:
				messages.error(request, "That recipe doesn't exist.")
				if 'HTTP_REFERER' in request.META:
					dajax.redirect(request.META['HTTP_REFERER'])
				else:
					dajax.redirect('/recipe')
				return dajax.json()
		if comment == '':
			messages.error(request, "Your comments have to actually say something.")
			if 'HTTP_REFERER' in request.META:
				dajax.redirect(request.META['HTTP_REFERER'])
			else:
				dajax.redirect('/recipe')
			return dajax.json()
		comment = Comment(original_poster=request.user, receiving_recipe=recipe, comment=comment)
		comment.save()
		messages.success(request, "Comment posted successfully!")
	else:
		messages.error(request, "You must be logged in to comment.")
	if 'HTTP_REFERER' in request.META:
		dajax.redirect(request.META['HTTP_REFERER'])
	else:
		dajax.redirect('/recipe')
	return dajax.json()
Ejemplo n.º 2
0
def add_comment(request, username='', comment=''):
	dajax = Dajax()
	if request.user.is_authenticated():
		if username == '' or username == request.user.username:
			messages.error(request, "Sadly, you can't add comments to your own profile.")
			dajax.redirect('/user')
			return dajax.json()
		else:
			try:
				user = User.objects.get(username=username)
			except:
				messages.error(request, "That user doesn't exist.")
				if 'HTTP_REFERER' in request.META:
					dajax.redirect(request.META['HTTP_REFERER'])
				else:
					dajax.redirect('/home')
				return dajax.json()
		if comment == '':
			messages.error(request, "Your comments have to actually say something.")
			dajax.redirect(request.META['HTTP_REFERER'])
			return dajax.json()
		comment = Comment(original_poster=request.user, receiving_user=user, comment=comment)
		comment.save()
		messages.success(request, "Comment posted successfully!")
	else:
		messages.error(request, "You must be logged in to comment.")
	if 'HTTP_REFERER' in request.META:
		dajax.redirect(request.META['HTTP_REFERER'])
	else:
		dajax.redirect('/home')
	return dajax.json()