Exemple #1
0
def delete_comment(request, post_id, comment_id):
	c = get_object_or_404(Comment, pk = comment_id)

	if request.user.is_superuser is False:
		if request.user != c.user:
			messages.info(request, 'You do not own this object.')
			return redirect('imageboard:index')

	c.delete()

	# Delete template cache fragments and clear latest activity cache
	cache.delete_many([tf('comment_media', [comment_id]),
					   tf('comment_imagetype', [comment_id])])

	# Update latest activity cache
	_generateActivity()

	messages.success(request, 'Comment Successfully Deleted.')

	return redirect(reverse('imageboard:index') +
					'?page=' +
					str(_getPostPage(post_id, request.user.userprofile.pagination)) +
					'#' + post_id)
Exemple #2
0
def delete_post(request, post_id):
	p = get_object_or_404(Post, pk = post_id)

	if request.user.is_superuser is False:
		if request.user != p.user:
			messages.info(request, 'You do not own this object.')
			return redirect('imageboard:index')

	# Delete template cache fragments for post and children
	cache.delete_many([tf('post_media', [post_id]),
					   tf('post_imagetype', [post_id]),
					   tf('post_link', [post_id, request.user.userprofile.pagination])])
	for c in Comment.objects.all().filter(post_id=post_id):
		cache.delete_many([tf('comment_media', [c.id]),
						   tf('comment_imagetype', [c.id])])

	p.delete()

	# Update latest activity cache
	_generateActivity()

	messages.success(request, 'Post Successfully Deleted.')

	return redirect('imageboard:index')