changeset 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 6a265b5768ca
children 0a8e6a9ccf53
files gpp/core/functions.py gpp/forums/views/main.py gpp/messages/forms.py gpp/messages/utils.py gpp/messages/views.py
diffstat 5 files changed, 29 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/gpp/core/functions.py	Sun Mar 04 13:20:40 2012 -0600
+++ b/gpp/core/functions.py	Sun Mar 04 14:52:24 2012 -0600
@@ -103,3 +103,15 @@
     except ValueError:
         n = 1
     return n
+
+
+def quote_message(who, message):
+    """
+    Builds a message reply by quoting the existing message in a
+    typical email-like fashion. The quoting is compatible with Markdown.
+    """
+    msg = "> %s" % message.replace('\n', '\n> ')
+    if msg.endswith('\n> '):
+        msg = msg[:-2]
+
+    return "*%s wrote:*\n\n%s\n\n" % (who, msg)
--- a/gpp/forums/views/main.py	Sun Mar 04 13:20:40 2012 -0600
+++ b/gpp/forums/views/main.py	Sun Mar 04 14:52:24 2012 -0600
@@ -18,14 +18,13 @@
 from django.template.loader import render_to_string
 from django.template import RequestContext
 from django.views.decorators.http import require_POST
-from django.utils.text import wrap
 from django.db.models import F
 
 import antispam
 import antispam.utils
 from bio.models import UserProfile, BadgeOwnership
 from core.paginator import DiggPaginator
-from core.functions import email_admins
+from core.functions import email_admins, quote_message
 
 from forums.models import (Forum, Topic, Post, FlaggedPost, TopicLastVisit,
         ForumLastVisit, Attachment)
@@ -620,7 +619,7 @@
             if quote_id:
                 quote_post = get_object_or_404(Post.objects.select_related(),
                         pk=quote_id)
-                form = PostForm(initial={'body': _quote_message(quote_post.user.username,
+                form = PostForm(initial={'body': quote_message(quote_post.user.username,
                     quote_post.body)})
             else:
                 form = PostForm()
@@ -1001,18 +1000,6 @@
     profile.save(content_update=False)
 
 
-def _quote_message(who, message):
-    """
-    Builds a message reply by quoting the existing message in a
-    typical email-like fashion. The quoting is compatible with Markdown.
-    """
-    header = '*%s wrote:*\n\n' % (who, )
-    lines = wrap(message, 55).split('\n')
-    for i, line in enumerate(lines):
-        lines[i] = '> ' + line
-    return header + '\n'.join(lines) + '\n\n'
-
-
 def _move_topic(topic, old_forum, new_forum):
     if new_forum != old_forum:
         topic.forum = new_forum
--- a/gpp/messages/forms.py	Sun Mar 04 13:20:40 2012 -0600
+++ b/gpp/messages/forms.py	Sun Mar 04 14:52:24 2012 -0600
@@ -10,7 +10,6 @@
 from django.template.loader import render_to_string
 
 from core.functions import send_mail
-from core.functions import get_full_name
 from core.widgets import AutoCompleteUserInput
 from messages.models import Message
 from messages.models import Options
--- a/gpp/messages/utils.py	Sun Mar 04 13:20:40 2012 -0600
+++ b/gpp/messages/utils.py	Sun Mar 04 14:52:24 2012 -0600
@@ -1,29 +1,16 @@
 """
 This file contains various helper utility functions for the messages
 application.
+
 """
 
-from django.utils.text import wrap
-
 
 def reply_subject(subject):
-   """
-   Builds a subject line for a reply.
-   If the subject already starts with Re: then return the subject.
-   Otherwise, prepend Re: to the subject and return it.
-   """
-   if subject.startswith('Re: '):
-      return subject
-   return 'Re: ' + subject
-
-
-def quote_message(who, date, message):
-   """
-   Builds a message reply by quoting the existing message in a
-   typical email-like fashion. The quoting is compatible with Markdown.
-   """
-   header = '> On %s, %s wrote:\n>\n' % (date.strftime('%a, %b %d %Y, %I:%M %p'), who)
-   lines = wrap(message, 55).split('\n')
-   for i, line in enumerate(lines):
-      lines[i] = '> ' + line
-   return header + '\n'.join(lines) + '\n\n'
+    """
+    Builds a subject line for a reply.
+    If the subject already starts with Re: then return the subject.
+    Otherwise, prepend Re: to the subject and return it.
+    """
+    if subject.startswith('Re: '):
+        return subject
+    return 'Re: ' + subject
--- a/gpp/messages/views.py	Sun Mar 04 13:20:40 2012 -0600
+++ b/gpp/messages/views.py	Sun Mar 04 14:52:24 2012 -0600
@@ -12,15 +12,15 @@
 from django.http import HttpResponse
 from django.http import HttpResponseForbidden
 from django.http import HttpResponseNotAllowed
-from django.http import HttpResponseRedirect
 from django.shortcuts import get_object_or_404
 from django.shortcuts import render
 import django.utils.simplejson as json
 
 from messages.models import Message, Options
 from messages.forms import OptionsForm, ComposeForm
-from messages.utils import reply_subject, quote_message
+from messages.utils import reply_subject
 from messages import MSG_BOX_LIMIT
+from core.functions import quote_message
 
 
 MSGS_PER_PAGE = 20      # message pagination value
@@ -98,7 +98,7 @@
     paginator = Paginator(msg_list, MSGS_PER_PAGE)
     try:
         msgs = paginator.page(_get_page(request))
-    except EmptyPage, InvalidPage:
+    except (EmptyPage, InvalidPage):
         msgs = paginator.page(paginator.num_pages)
 
     return render(request, 'messages/inbox_tab.html', {
@@ -121,7 +121,7 @@
     paginator = Paginator(msg_list, MSGS_PER_PAGE)
     try:
         msgs = paginator.page(_get_page(request))
-    except EmptyPage, InvalidPage:
+    except (EmptyPage, InvalidPage):
         msgs = paginator.page(paginator.num_pages)
 
     return render(request, 'messages/outbox_tab.html', {
@@ -142,7 +142,7 @@
     paginator = Paginator(msg_list, MSGS_PER_PAGE)
     try:
         msgs = paginator.page(_get_page(request))
-    except EmptyPage, InvalidPage:
+    except (EmptyPage, InvalidPage):
         msgs = paginator.page(paginator.num_pages)
 
     return render(request, 'messages/trash_tab.html', {
@@ -175,8 +175,7 @@
                     receiver=msg.receiver.username,
                     content=msg.html,
                     re_subject=reply_subject(msg.subject),
-                    re_content=quote_message(msg.sender.username, msg.send_date,
-                                             msg.message))
+                    re_content=quote_message(msg.sender.username, msg.message))
 
     result = json.dumps(msg_dict, ensure_ascii=False)
     return HttpResponse(result, content_type='application/json')