Mercurial > public > sg101
annotate gpp/messages/utils.py @ 265:1ba2c6bf6eb7
Closing #98. Animated GIFs were losing their transparency and animated properties when saved as avatars. Reworked the avatar save process to only run the avatar through PIL if it is too big. This preserves the original uploaded file if it is within the desired size settings. This may still mangle big animated gifs. If this becomes a problem, then maybe look into calling the PIL Image.resize() method directly. Moved the PIL image specific functions from bio.forms to a new module: core.image for better reusability in the future.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 24 Sep 2010 02:12:09 +0000 |
parents | dbd703f7d63a |
children | 538a1bd2f1f4 |
rev | line source |
---|---|
gremmie@1 | 1 """ |
gremmie@1 | 2 This file contains various helper utility functions for the messages |
gremmie@1 | 3 application. |
gremmie@1 | 4 """ |
gremmie@1 | 5 |
gremmie@1 | 6 from django.utils.text import wrap |
gremmie@1 | 7 |
gremmie@1 | 8 |
gremmie@1 | 9 def reply_subject(subject): |
gremmie@1 | 10 """ |
gremmie@1 | 11 Builds a subject line for a reply. |
gremmie@1 | 12 If the subject already starts with Re: then return the subject. |
gremmie@1 | 13 Otherwise, prepend Re: to the subject and return it. |
gremmie@1 | 14 """ |
gremmie@1 | 15 if subject.startswith('Re: '): |
gremmie@1 | 16 return subject |
gremmie@1 | 17 return 'Re: ' + subject |
gremmie@1 | 18 |
gremmie@1 | 19 |
gremmie@1 | 20 def quote_message(who, date, message): |
gremmie@1 | 21 """ |
gremmie@1 | 22 Builds a message reply by quoting the existing message in a |
gremmie@1 | 23 typical email-like fashion. The quoting is compatible with Markdown. |
gremmie@1 | 24 """ |
gremmie@1 | 25 header = '> On %s, %s wrote:\n>\n' % (date.strftime('%a, %b %d %Y, %I:%M %p'), who) |
gremmie@1 | 26 lines = wrap(message, 55).split('\n') |
gremmie@1 | 27 for i, line in enumerate(lines): |
gremmie@1 | 28 lines[i] = '> ' + line |
gremmie@1 | 29 return header + '\n'.join(lines) |