Mercurial > public > sg101
diff gpp/forums/views/main.py @ 285:8fd4984d5c3b
This is a first rough commit for #95, adding the ability to embed YouTube videos in forum posts. Some more polish and testing needs to happen at this point. I wanted to get all these changes off my hard drive and into the repository.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 14 Oct 2010 02:39:35 +0000 |
parents | 21d2ca3b4bf7 |
children | 72fd300685d5 |
line wrap: on
line diff
--- a/gpp/forums/views/main.py Mon Oct 04 01:01:29 2010 +0000 +++ b/gpp/forums/views/main.py Thu Oct 14 02:39:35 2010 +0000 @@ -23,7 +23,7 @@ from core.paginator import DiggPaginator from core.functions import email_admins from forums.models import Forum, Topic, Post, FlaggedPost, TopicLastVisit, \ - ForumLastVisit + ForumLastVisit, Attachment from forums.forms import NewTopicForm, NewPostForm, PostForm, MoveTopicForm, \ SplitTopicForm from forums.unread import get_forum_unread_status, get_topic_unread_status, \ @@ -32,6 +32,7 @@ from bio.models import UserProfile import antispam import antispam.utils +from forums.attachments import AttachmentProcessor ####################################################################### @@ -184,6 +185,16 @@ for post in page.object_list: post.user_profile = user_profiles[post.user.id] + post.attach_list = [] + + # Attach any attachments + post_ids = [post.pk for post in page.object_list] + attachments = Attachment.objects.filter(post__in=post_ids).select_related( + 'embed').order_by('order') + + post_dict = dict((post.pk, post) for post in page.object_list) + for item in attachments: + post_dict[item.post.id].attach_list.append(item.embed) last_page = page_num == paginator.num_pages @@ -283,8 +294,10 @@ post = form.save(request.user, request.META.get("REMOTE_ADDR", "")) post.unread = True post.user_profile = request.user.get_profile() + post.attach_list = post.attachments.all() _bump_post_count(request.user) _update_last_visit(request.user, form.topic) + return render_to_response('forums/display_post.html', { 'post': post, 'can_moderate': _can_moderate(form.topic.forum, request.user), @@ -359,6 +372,11 @@ post = form.save(commit=False) post.touch() post.save() + + # Save any attachments + attach_proc = AttachmentProcessor(request.POST.getlist('attachment')) + attach_proc.save_attachments(post) + return HttpResponseRedirect(post.get_absolute_url()) else: form = PostForm(instance=post) @@ -439,6 +457,9 @@ forum.last_post_pre_delete() forum.save() + # delete any attachments + post.attachments.clear() + # Should be safe to delete the post now: post.delete() @@ -459,6 +480,11 @@ topic.subscribers.clear() topic.bookmarkers.clear() + # delete all attachments + posts = Post.objects.filter(topic=topic) + for post in posts: + post.attachments.clear() + # It should be safe to just delete the topic now. This will # automatically delete all posts in the topic. topic.delete() @@ -484,6 +510,11 @@ post.user = request.user post.user_ip = request.META.get("REMOTE_ADDR", "") post.save() + + # Save any attachments + attach_proc = AttachmentProcessor(request.POST.getlist('attachment')) + attach_proc.save_attachments(post) + _bump_post_count(request.user) _update_last_visit(request.user, topic) return HttpResponseRedirect(post.get_absolute_url())