def discussion(request, discussion_id): discussion = CommunityDiscussions.objects.select_related().get(id=discussion_id) replies = CommunityDiscussionReplies.objects.select_related().filter(discussion=discussion_id) total = CommunityDiscussions.objects.filter(community=discussion.community).count() users = CommunityUsers.objects.filter(community=discussion.community).count() mems = CommunityUsers.objects.select_related().filter(user=request.user, community=discussion.community) views_connect = view_counter_store() views_connect.set_item("discussion", discussion_id, 1, {"community": str(discussion.community.id)}) poll_connect = poll_store() has_poll = poll_connect.poll_exists("discussion", discussion_id) trending = get_trending(discussion.community.id) data = { "discussion": discussion, "replies": replies, "community": discussion.community, "has_poll": has_poll, "total_discussions": total, "total_users": users, "trending": trending, "mem": mems[0] if mems.count() else None, } if has_poll: data.update({"poll": poll_data("discussion", discussion_id, request.user.id)}) return render_to_response("communities/discussion.html", data)
def discussion_delete(request, discussion_id): discussion = CommunityDiscussions.objects.get(id=discussion_id) redirect_url = reverse("community_view", args=[discussion.community.id]) # try: view_connect = view_counter_store() view_connect.delete_item("discussion", discussion_id) poll_connect = poll_store() if poll_connect.poll_exists("discussion", discussion_id): poll_connect.delete_poll("discussion", discussion_id) discussion.delete() # except Exception as e: # log.warning('There was an error deleting a discussion: {0}'.format(e)) return redirect(redirect_url)