Commit 4f73094e51134df6fd43d303bb3a4330646e60be
1 parent
85a58d88
Exists in
master
and in
39 other branches
Hiding replies in threads
Showing
4 changed files
with
81 additions
and
4 deletions
Show diff stats
requirements.txt
1 | -#https://www.djangoproject.com/download/1.6b4/tarball/ | ||
2 | -Django==1.5.2 | 1 | +https://www.djangoproject.com/download/1.6b4/tarball/ |
2 | +#Django==1.5.2 | ||
3 | South==0.8.1 | 3 | South==0.8.1 |
4 | psycopg2==2.5.1 | 4 | psycopg2==2.5.1 |
5 | django-piston==0.2.3 | 5 | django-piston==0.2.3 |
@@ -8,6 +8,7 @@ chardet==1.0.1 | @@ -8,6 +8,7 @@ chardet==1.0.1 | ||
8 | python-dateutil==1.5 | 8 | python-dateutil==1.5 |
9 | django-cliauth==0.9 | 9 | django-cliauth==0.9 |
10 | django-mobile==0.3.0 | 10 | django-mobile==0.3.0 |
11 | +html2text | ||
11 | 12 | ||
12 | gunicorn | 13 | gunicorn |
13 | gevent | 14 | gevent |
src/super_archives/templates/message-thread.html
1 | {% extends "base.html" %} | 1 | {% extends "base.html" %} |
2 | -{% load i18n append_to_get gravatar %} | 2 | +{% load i18n append_to_get gravatar superarchives %} |
3 | 3 | ||
4 | {% trans "Anonymous" as anonymous %} | 4 | {% trans "Anonymous" as anonymous %} |
5 | 5 | ||
@@ -149,7 +149,7 @@ | @@ -149,7 +149,7 @@ | ||
149 | 149 | ||
150 | </div> | 150 | </div> |
151 | <div class="panel-body"> | 151 | <div class="panel-body"> |
152 | - <pre>{{ email.body }}</pre> | 152 | + {% display_message email emails %} |
153 | </div> | 153 | </div> |
154 | </div> | 154 | </div> |
155 | </div> | 155 | </div> |
src/super_archives/templates/superarchives/tags/display_message.html
0 → 100644
@@ -0,0 +1,71 @@ | @@ -0,0 +1,71 @@ | ||
1 | + | ||
2 | +import re | ||
3 | + | ||
4 | +from django import template | ||
5 | + | ||
6 | +from html2text import html2text | ||
7 | + | ||
8 | + | ||
9 | +register = template.Library() | ||
10 | +TEMPLATE_PATH = 'superarchives/tags/' | ||
11 | + | ||
12 | + | ||
13 | +EXTENDED_PUNCTUATION = '!"#$%&\'()*+,-./:;=?@[\\]^_`{|}~ \t\n\r\x0b\x0c' | ||
14 | +RE_WRAPPED_BY_HTML = re.compile(r'^<[a-z]+[^>]*>.*</[a-z]+[^>]*>$', | ||
15 | + re.MULTILINE|re.IGNORECASE|re.DOTALL) | ||
16 | + | ||
17 | + | ||
18 | +def join(block): | ||
19 | + block_txt = u''.join(block) | ||
20 | + | ||
21 | + if RE_WRAPPED_BY_HTML.match(block_txt.strip()): | ||
22 | + return html2text(block_txt) | ||
23 | + | ||
24 | + return block_txt | ||
25 | + | ||
26 | +def is_reply(line, message, thread): | ||
27 | + clean_line = line.strip() | ||
28 | + if clean_line.startswith('>'): | ||
29 | + return True | ||
30 | + | ||
31 | + for other_msg in thread: | ||
32 | + if other_msg == message: | ||
33 | + return False | ||
34 | + | ||
35 | + clean_body = other_msg.body.replace('\r', ' ')\ | ||
36 | + .replace('\n', ' ') | ||
37 | + if clean_line.strip('> ') in clean_body: | ||
38 | + return True | ||
39 | + | ||
40 | + return False | ||
41 | + | ||
42 | + | ||
43 | +@register.inclusion_tag(TEMPLATE_PATH + 'display_message.html', | ||
44 | + takes_context=False) | ||
45 | +def display_message(email, thread): | ||
46 | + message = email.body | ||
47 | + messages = [] | ||
48 | + | ||
49 | + block = [] | ||
50 | + reply_block = False | ||
51 | + | ||
52 | + for line in message.split('\n'): | ||
53 | + if line.strip(EXTENDED_PUNCTUATION): | ||
54 | + if is_reply(line, email, thread): | ||
55 | + if not reply_block: | ||
56 | + reply_block = True | ||
57 | + messages.append((join(block), 'normal')) | ||
58 | + block = [] | ||
59 | + elif reply_block: | ||
60 | + reply_block = False | ||
61 | + messages.append((join(block), 'reply')) | ||
62 | + block = [] | ||
63 | + | ||
64 | + block.append(line.rstrip() + '\n') | ||
65 | + | ||
66 | + if reply_block: | ||
67 | + messages.append((join(block), 'reply')) | ||
68 | + else: | ||
69 | + messages.append((join(block), 'normal')) | ||
70 | + | ||
71 | + return {'messages': messages} |