comparison gpp/forums/views/main.py @ 566:4b9970ad0edb

For bitbucket issue #6, try to improve quoting messages.
author Brian Neal <bgneal@gmail.com>
date Sun, 04 Mar 2012 14:52:24 -0600
parents 98b373ca09f3
children
comparison
equal deleted inserted replaced
565:6a265b5768ca 566:4b9970ad0edb
16 from django.shortcuts import get_object_or_404 16 from django.shortcuts import get_object_or_404
17 from django.shortcuts import render_to_response 17 from django.shortcuts import render_to_response
18 from django.template.loader import render_to_string 18 from django.template.loader import render_to_string
19 from django.template import RequestContext 19 from django.template import RequestContext
20 from django.views.decorators.http import require_POST 20 from django.views.decorators.http import require_POST
21 from django.utils.text import wrap
22 from django.db.models import F 21 from django.db.models import F
23 22
24 import antispam 23 import antispam
25 import antispam.utils 24 import antispam.utils
26 from bio.models import UserProfile, BadgeOwnership 25 from bio.models import UserProfile, BadgeOwnership
27 from core.paginator import DiggPaginator 26 from core.paginator import DiggPaginator
28 from core.functions import email_admins 27 from core.functions import email_admins, quote_message
29 28
30 from forums.models import (Forum, Topic, Post, FlaggedPost, TopicLastVisit, 29 from forums.models import (Forum, Topic, Post, FlaggedPost, TopicLastVisit,
31 ForumLastVisit, Attachment) 30 ForumLastVisit, Attachment)
32 from forums.forms import (NewTopicForm, NewPostForm, PostForm, MoveTopicForm, 31 from forums.forms import (NewTopicForm, NewPostForm, PostForm, MoveTopicForm,
33 SplitTopicForm) 32 SplitTopicForm)
618 else: 617 else:
619 quote_id = request.GET.get('quote') 618 quote_id = request.GET.get('quote')
620 if quote_id: 619 if quote_id:
621 quote_post = get_object_or_404(Post.objects.select_related(), 620 quote_post = get_object_or_404(Post.objects.select_related(),
622 pk=quote_id) 621 pk=quote_id)
623 form = PostForm(initial={'body': _quote_message(quote_post.user.username, 622 form = PostForm(initial={'body': quote_message(quote_post.user.username,
624 quote_post.body)}) 623 quote_post.body)})
625 else: 624 else:
626 form = PostForm() 625 form = PostForm()
627 else: 626 else:
628 form = None 627 form = None
999 profile = user.get_profile() 998 profile = user.get_profile()
1000 profile.forum_post_count += 1 999 profile.forum_post_count += 1
1001 profile.save(content_update=False) 1000 profile.save(content_update=False)
1002 1001
1003 1002
1004 def _quote_message(who, message):
1005 """
1006 Builds a message reply by quoting the existing message in a
1007 typical email-like fashion. The quoting is compatible with Markdown.
1008 """
1009 header = '*%s wrote:*\n\n' % (who, )
1010 lines = wrap(message, 55).split('\n')
1011 for i, line in enumerate(lines):
1012 lines[i] = '> ' + line
1013 return header + '\n'.join(lines) + '\n\n'
1014
1015
1016 def _move_topic(topic, old_forum, new_forum): 1003 def _move_topic(topic, old_forum, new_forum):
1017 if new_forum != old_forum: 1004 if new_forum != old_forum:
1018 topic.forum = new_forum 1005 topic.forum = new_forum
1019 topic.save() 1006 topic.save()
1020 # Have to adjust foreign keys to last_post, denormalized counts, etc.: 1007 # Have to adjust foreign keys to last_post, denormalized counts, etc.: