diff gpp/forums/views/main.py @ 286:72fd300685d5

For #95. You can now make posts with no text in the body if you have attachments. And now if you create a new topic with an attachment, and the POST fails (say you forgot the topic title), we will now re-attach attachments. Also fixed a bug in the smiley code that would arise if it was asked to markup an empty string.
author Brian Neal <bgneal@gmail.com>
date Sat, 23 Oct 2010 20:19:46 +0000
parents 8fd4984d5c3b
children c92fb89dbc7d
line wrap: on
line diff
--- a/gpp/forums/views/main.py	Thu Oct 14 02:39:35 2010 +0000
+++ b/gpp/forums/views/main.py	Sat Oct 23 20:19:46 2010 +0000
@@ -68,7 +68,7 @@
     """
     for topic in topics:
         if topic.post_count > POSTS_PER_PAGE:
-            pp = DiggPaginator(range(topic.post_count), POSTS_PER_PAGE, 
+            pp = DiggPaginator(range(topic.post_count), POSTS_PER_PAGE,
                     body=2, tail=3, margin=1)
             topic.page_range = pp.page(1).page_range
         else:
@@ -142,7 +142,7 @@
     page_nav = render_to_string('forums/pagination.html', {'page': page})
 
     can_moderate = _can_moderate(forum, request.user)
-    
+
     return render_to_response('forums/forum_index.html', {
         'forum': forum,
         'feed': feed,
@@ -252,7 +252,7 @@
                                             kwargs={'tid': topic.pk}))
     else:
         form = NewTopicForm(request.user, forum)
-    
+
     return render_to_response('forums/new_topic.html', {
         'forum': forum,
         'form': form,
@@ -305,7 +305,7 @@
             },
             context_instance=RequestContext(request))
 
-    return HttpResponseBadRequest("Invalid post.");
+    return HttpResponseBadRequest("Oops, did you forget some text?");
 
 
 def goto_post(request, post_id):
@@ -374,8 +374,7 @@
             post.save()
 
             # Save any attachments
-            attach_proc = AttachmentProcessor(request.POST.getlist('attachment'))
-            attach_proc.save_attachments(post)
+            form.attach_proc.save_attachments(post)
 
             return HttpResponseRedirect(post.get_absolute_url())
     else:
@@ -512,8 +511,7 @@
                 post.save()
 
                 # Save any attachments
-                attach_proc = AttachmentProcessor(request.POST.getlist('attachment'))
-                attach_proc.save_attachments(post)
+                form.attach_proc.save_attachments(post)
 
                 _bump_post_count(request.user)
                 _update_last_visit(request.user, topic)
@@ -651,7 +649,7 @@
                 if form.is_valid():
                     _bulk_move(topic_ids, forum, form.cleaned_data['forums'])
                     return HttpResponseRedirect(url)
-    
+
     if form is None:
         form = MoveTopicForm(request.user, hide_label=True)
 
@@ -803,7 +801,7 @@
 
 
 def _user_posts(request, target_user, req_user, page_title):
-    """Displays a list of posts made by the target user. 
+    """Displays a list of posts made by the target user.
     req_user is the user trying to view the posts. Only the forums
     req_user can see are searched.
     """
@@ -981,7 +979,7 @@
         for post in posts:
             post.topic = new_topic
             post.save()
-        
+
         topic.post_count_update()
         topic.save()
         new_topic.post_count_update()