Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
285:8fd4984d5c3b | 286:72fd300685d5 |
---|---|
66 This attribute will be None if it is a single page topic. This is used | 66 This attribute will be None if it is a single page topic. This is used |
67 by the templates to generate "goto page x" links. | 67 by the templates to generate "goto page x" links. |
68 """ | 68 """ |
69 for topic in topics: | 69 for topic in topics: |
70 if topic.post_count > POSTS_PER_PAGE: | 70 if topic.post_count > POSTS_PER_PAGE: |
71 pp = DiggPaginator(range(topic.post_count), POSTS_PER_PAGE, | 71 pp = DiggPaginator(range(topic.post_count), POSTS_PER_PAGE, |
72 body=2, tail=3, margin=1) | 72 body=2, tail=3, margin=1) |
73 topic.page_range = pp.page(1).page_range | 73 topic.page_range = pp.page(1).page_range |
74 else: | 74 else: |
75 topic.page_range = None | 75 topic.page_range = None |
76 | 76 |
140 | 140 |
141 # we do this for the template since it is rendered twice | 141 # we do this for the template since it is rendered twice |
142 page_nav = render_to_string('forums/pagination.html', {'page': page}) | 142 page_nav = render_to_string('forums/pagination.html', {'page': page}) |
143 | 143 |
144 can_moderate = _can_moderate(forum, request.user) | 144 can_moderate = _can_moderate(forum, request.user) |
145 | 145 |
146 return render_to_response('forums/forum_index.html', { | 146 return render_to_response('forums/forum_index.html', { |
147 'forum': forum, | 147 'forum': forum, |
148 'feed': feed, | 148 'feed': feed, |
149 'page': page, | 149 'page': page, |
150 'page_nav': page_nav, | 150 'page_nav': page_nav, |
250 _bump_post_count(request.user) | 250 _bump_post_count(request.user) |
251 return HttpResponseRedirect(reverse('forums-new_topic_thanks', | 251 return HttpResponseRedirect(reverse('forums-new_topic_thanks', |
252 kwargs={'tid': topic.pk})) | 252 kwargs={'tid': topic.pk})) |
253 else: | 253 else: |
254 form = NewTopicForm(request.user, forum) | 254 form = NewTopicForm(request.user, forum) |
255 | 255 |
256 return render_to_response('forums/new_topic.html', { | 256 return render_to_response('forums/new_topic.html', { |
257 'forum': forum, | 257 'forum': forum, |
258 'form': form, | 258 'form': form, |
259 }, | 259 }, |
260 context_instance=RequestContext(request)) | 260 context_instance=RequestContext(request)) |
303 'can_moderate': _can_moderate(form.topic.forum, request.user), | 303 'can_moderate': _can_moderate(form.topic.forum, request.user), |
304 'can_reply': True, | 304 'can_reply': True, |
305 }, | 305 }, |
306 context_instance=RequestContext(request)) | 306 context_instance=RequestContext(request)) |
307 | 307 |
308 return HttpResponseBadRequest("Invalid post."); | 308 return HttpResponseBadRequest("Oops, did you forget some text?"); |
309 | 309 |
310 | 310 |
311 def goto_post(request, post_id): | 311 def goto_post(request, post_id): |
312 """ | 312 """ |
313 This function calculates what page a given post is on, then redirects | 313 This function calculates what page a given post is on, then redirects |
372 post = form.save(commit=False) | 372 post = form.save(commit=False) |
373 post.touch() | 373 post.touch() |
374 post.save() | 374 post.save() |
375 | 375 |
376 # Save any attachments | 376 # Save any attachments |
377 attach_proc = AttachmentProcessor(request.POST.getlist('attachment')) | 377 form.attach_proc.save_attachments(post) |
378 attach_proc.save_attachments(post) | |
379 | 378 |
380 return HttpResponseRedirect(post.get_absolute_url()) | 379 return HttpResponseRedirect(post.get_absolute_url()) |
381 else: | 380 else: |
382 form = PostForm(instance=post) | 381 form = PostForm(instance=post) |
383 | 382 |
510 post.user = request.user | 509 post.user = request.user |
511 post.user_ip = request.META.get("REMOTE_ADDR", "") | 510 post.user_ip = request.META.get("REMOTE_ADDR", "") |
512 post.save() | 511 post.save() |
513 | 512 |
514 # Save any attachments | 513 # Save any attachments |
515 attach_proc = AttachmentProcessor(request.POST.getlist('attachment')) | 514 form.attach_proc.save_attachments(post) |
516 attach_proc.save_attachments(post) | |
517 | 515 |
518 _bump_post_count(request.user) | 516 _bump_post_count(request.user) |
519 _update_last_visit(request.user, topic) | 517 _update_last_visit(request.user, topic) |
520 return HttpResponseRedirect(post.get_absolute_url()) | 518 return HttpResponseRedirect(post.get_absolute_url()) |
521 else: | 519 else: |
649 elif request.POST.get('move'): | 647 elif request.POST.get('move'): |
650 form = MoveTopicForm(request.user, request.POST, hide_label=True) | 648 form = MoveTopicForm(request.user, request.POST, hide_label=True) |
651 if form.is_valid(): | 649 if form.is_valid(): |
652 _bulk_move(topic_ids, forum, form.cleaned_data['forums']) | 650 _bulk_move(topic_ids, forum, form.cleaned_data['forums']) |
653 return HttpResponseRedirect(url) | 651 return HttpResponseRedirect(url) |
654 | 652 |
655 if form is None: | 653 if form is None: |
656 form = MoveTopicForm(request.user, hide_label=True) | 654 form = MoveTopicForm(request.user, hide_label=True) |
657 | 655 |
658 return render_to_response('forums/mod_forum.html', { | 656 return render_to_response('forums/mod_forum.html', { |
659 'forum': forum, | 657 'forum': forum, |
801 }, | 799 }, |
802 context_instance=RequestContext(request)) | 800 context_instance=RequestContext(request)) |
803 | 801 |
804 | 802 |
805 def _user_posts(request, target_user, req_user, page_title): | 803 def _user_posts(request, target_user, req_user, page_title): |
806 """Displays a list of posts made by the target user. | 804 """Displays a list of posts made by the target user. |
807 req_user is the user trying to view the posts. Only the forums | 805 req_user is the user trying to view the posts. Only the forums |
808 req_user can see are searched. | 806 req_user can see are searched. |
809 """ | 807 """ |
810 forum_ids = Forum.objects.forum_ids_for_user(req_user) | 808 forum_ids = Forum.objects.forum_ids_for_user(req_user) |
811 posts = Post.objects.filter(user=target_user, | 809 posts = Post.objects.filter(user=target_user, |
979 new_topic = Topic(forum=new_forum, name=new_name, user=posts[0].user) | 977 new_topic = Topic(forum=new_forum, name=new_name, user=posts[0].user) |
980 new_topic.save() | 978 new_topic.save() |
981 for post in posts: | 979 for post in posts: |
982 post.topic = new_topic | 980 post.topic = new_topic |
983 post.save() | 981 post.save() |
984 | 982 |
985 topic.post_count_update() | 983 topic.post_count_update() |
986 topic.save() | 984 topic.save() |
987 new_topic.post_count_update() | 985 new_topic.post_count_update() |
988 new_topic.save() | 986 new_topic.save() |
989 topic.forum.sync() | 987 topic.forum.sync() |