comparison gpp/messages/utils.py @ 1:dbd703f7d63a

Initial import of sg101 stuff from private repository.
author gremmie
date Mon, 06 Apr 2009 02:43:12 +0000
parents
children 538a1bd2f1f4
comparison
equal deleted inserted replaced
0:900ba3c7b765 1:dbd703f7d63a
1 """
2 This file contains various helper utility functions for the messages
3 application.
4 """
5
6 from django.utils.text import wrap
7
8
9 def reply_subject(subject):
10 """
11 Builds a subject line for a reply.
12 If the subject already starts with Re: then return the subject.
13 Otherwise, prepend Re: to the subject and return it.
14 """
15 if subject.startswith('Re: '):
16 return subject
17 return 'Re: ' + subject
18
19
20 def quote_message(who, date, message):
21 """
22 Builds a message reply by quoting the existing message in a
23 typical email-like fashion. The quoting is compatible with Markdown.
24 """
25 header = '> On %s, %s wrote:\n>\n' % (date.strftime('%a, %b %d %Y, %I:%M %p'), who)
26 lines = wrap(message, 55).split('\n')
27 for i, line in enumerate(lines):
28 lines[i] = '> ' + line
29 return header + '\n'.join(lines)