summaryrefslogtreecommitdiffstats
path: root/hyperkitty
diff options
context:
space:
mode:
Diffstat (limited to 'hyperkitty')
-rw-r--r--hyperkitty/api.py2
-rw-r--r--hyperkitty/templates/month_view.html55
-rw-r--r--hyperkitty/templates/recent_activities.html64
-rw-r--r--hyperkitty/templates/threads/right_col.html9
-rw-r--r--hyperkitty/views/list.py67
-rw-r--r--hyperkitty/views/thread.py28
6 files changed, 104 insertions, 121 deletions
diff --git a/hyperkitty/api.py b/hyperkitty/api.py
index 6c80f0d..1fc8212 100644
--- a/hyperkitty/api.py
+++ b/hyperkitty/api.py
@@ -51,7 +51,7 @@ class ThreadResource(View):
def get(self, request, mlist_fqdn, threadid):
list_name = mlist_fqdn.split('@')[0]
store = get_store(request)
- thread = store.get_messages_in_thread(list_name, threadid)
+ thread = store.get_thread(list_name, threadid)
if not thread:
return HttpResponse(status=404)
else:
diff --git a/hyperkitty/templates/month_view.html b/hyperkitty/templates/month_view.html
index 97bd2e8..f3d0935 100644
--- a/hyperkitty/templates/month_view.html
+++ b/hyperkitty/templates/month_view.html
@@ -25,43 +25,46 @@
{% endif %}
</div>
- {% for email in threads %}
+ {% for thread in threads %}
<!-- New thread -->
<div class="thread">
<div class="notsaved">
- <span class="thread_title"><a name="{{email.thread_id}}"
- href="{% url thread threadid=email.thread_id, mlist_fqdn=list_address %}">{{ email.subject|strip_subject:mlist }}</a></span>
- <span class="thread_date">{{email.date|timesince }}</span>
+ <span class="thread_title"><a name="{{thread.thread_id}}"
+ href="{% url thread threadid=thread.thread_id, mlist_fqdn=list_address %}"
+ >{{ thread.starting_email.subject|strip_subject:mlist }}</a></span>
+ <span class="thread_date">{{thread.date_active|timesince }}</span>
</div>
<div class="thread_content">
- {% if email.category_tag %}
- <div class="inline-block type type_{{email.category_tag}}">
- <a href="{% url search_tag mlist_fqdn=list_address, tag=email.category_tag %}">{{email.category}}</a>
+ {% if thread.category_tag %}
+ <div class="inline-block type type_{{thread.category_tag}}">
+ <a href="{% url search_tag mlist_fqdn=list_address, tag=thread.category_tag %}"
+ >{{thread.category}}</a>
</div>
{% endif %}
- {% if email.category %}
- <div class="inline-block type type_{{email.category|lower}}">
- <a href="{% url search_tag mlist_fqdn=list_address, tag=email.category|lower %}">{{email.category}}</a>
+ {% if thread.category %}
+ <div class="inline-block type type_{{thread.category|lower}}">
+ <a href="{% url search_tag mlist_fqdn=list_address, tag=thread.category|lower %}"
+ >{{thread.category}}</a>
</div>
{% endif %}
<div class="inline-block gravatar">
- {% if email.sender_email %}
- {% gravatar_img_for_email email.sender_email 40 %}
+ {% if thread.starting_email.sender_email %}
+ {% gravatar_img_for_email thread.starting_email.sender_email 40 %}
<br />
{% endif %}
- {{email.sender_name}}
+ {{ thread.starting_email.sender_name }}
</div>
<div class="thread_email">
- <span class="expander"> {{email.content}} </span>
+ <span class="expander">{{ thread.starting_email.content }}</span>
</div>
</div>
<div class="thread_info">
<ul class="tags inline">
- {% if email.tags|length %}
+ {% if thread.tags|length %}
<li>
Tags:
</li>
- {% for tag in email.tags %}
+ {% for tag in thread.tags %}
<li>
<a href="{% url search_tag mlist_fqdn=list_address, tag=tag %}">{{tag}}</a>
</li>
@@ -70,16 +73,16 @@
</ul>
<ul class="inline-block">
<li class="participant">
- {{email.participants|length}} participants
+ {{ thread.participants|length }} participants
</li>
<li class="discussion">
- {{email.answers}} comments
+ {{ thread|length }} comments
</li>
</ul>
- {% if use_mockups %}
- <ul class="inline-block" messageid="{{email.message_id_hash}}">
- <li class="likestatus {{email.likestatus}}">
- +{{email.avglike}}/-{{email.avgdislike}}
+ {% if use_mockups %}
+ <ul class="inline-block" messageid="{{ thread.thread_id }}">
+ <li class="likestatus {{ thread.likestatus }}">
+ +{{ thread.avglike }}/-{{ thread.avgdislike }}
</li>
<li class="voteup">
<a class="youlike" href="#like">Like</a>
@@ -88,9 +91,9 @@
<a class="youdislike" href="#dislike">Dislike</a>
</li>
</ul>
- <a href="{% url thread threadid=email.thread_id, mlist_fqdn=list_address %}"
- class="btn">Show discussion</a>
- {% endif %}
+ <a href="{% url thread threadid=thread.thread_id, mlist_fqdn=list_address %}"
+ class="btn">Show discussion</a>
+ {% endif %}
</div>
</div>
<!-- End of thread -->
@@ -113,7 +116,7 @@
userCollapseText : 'View Less',
expandText : 'View More'
});
- });
+ });
</script>
{% endblock %}
diff --git a/hyperkitty/templates/recent_activities.html b/hyperkitty/templates/recent_activities.html
index 50e9057..f946bb9 100644
--- a/hyperkitty/templates/recent_activities.html
+++ b/hyperkitty/templates/recent_activities.html
@@ -81,34 +81,37 @@
</section>
<section id="most_active">
<h2>Recently active discussions</h2>
- {% for email in most_active_threads %}
+ {% for thread in most_active_threads %}
<!-- Start thread -->
<div class="thread">
<span class="thread_id">#{{forloop.counter}}</span>
- <span class="thread_title"> <a name="{{email.thread_id}}"
- href="{% url thread threadid=email.thread_id, mlist_fqdn=list_address %}">{{ email.subject|strip_subject:mlist }}</a> </span>
+ <span class="thread_title"><a name="{{thread.thread_id}}"
+ href="{% url thread threadid=thread.thread_id, mlist_fqdn=list_address %}"
+ >{{ thread.starting_email.subject|strip_subject:mlist }}</a></span>
<div class="thread_stats">
<ul class="inline-block">
- {% if email.category_tag %}
- <li class="type type_{{email.category_tag}}">
- <a href="{% url search_tag mlist_fqdn=list_address, tag=email.category_tag %}">{{email.category}}</a>
+ {% if thread.category_tag %}
+ <li class="type type_{{thread.category_tag}}">
+ <a href="{% url search_tag mlist_fqdn=list_address, tag=thread.category_tag %}"
+ >{{thread.category}}</a>
</li>
{% endif %}
- {% if email.category %}
- <li class="type type_{{email.category|lower}}">
- <a href="{% url search_tag mlist_fqdn=list_address, tag=email.category|lower %}">{{email.category}}</a>
+ {% if thread.category %}
+ <li class="type type_{{thread.category|lower}}">
+ <a href="{% url search_tag mlist_fqdn=list_address, tag=thread.category|lower %}"
+ >{{thread.category}}</a>
</li>
{% endif %}
- {% if use_mockups %}
+ {% if use_mockups %}
<li class="likestatus neutral">
+0/-0
</li>
{% endif %}
<li class="participant">
- {{email.participants|length}}
+ {{ thread.participants|length }}
</li>
<li class="discussion">
- {{email.answers}}
+ {{ thread|length }}
</li>
</ul>
</div>
@@ -119,34 +122,37 @@
<section id="top_discussion">
<h2>Top discussions the last 30 days</h2>
- {% for email in top_threads %}
+ {% for thread in top_threads %}
<!-- Start thread -->
<div class="thread">
<span class="thread_id">#{{forloop.counter}}</span>
- <span class="thread_title"> <a name="{{email.thread_id}}"
- href="{% url thread threadid=email.thread_id, mlist_fqdn=list_address %}">{{ email.subject|strip_subject:mlist }}</a> </span>
+ <span class="thread_title"> <a name="{{thread.thread_id}}"
+ href="{% url thread threadid=thread.thread_id, mlist_fqdn=list_address %}"
+ >{{ thread.starting_email.subject|strip_subject:mlist }}</a> </span>
<div class="thread_stats">
<ul class="inline-block">
- {% if email.category_tag %}
- <li class="type type_{{email.category_tag}}">
- <a href="{% url search_tag mlist_fqdn=list_address, tag=email.category_tag %}">{{email.category}}</a>
+ {% if thread.category_tag %}
+ <li class="type type_{{thread.category_tag}}">
+ <a href="{% url search_tag mlist_fqdn=list_address, tag=thread.category_tag %}"
+ >{{ thread.category }}</a>
</li>
{% endif %}
- {% if email.category %}
- <li class="type type_{{email.category|lower}}">
- <a href="{% url search_tag mlist_fqdn=list_address, tag=email.category|lower %}">{{email.category}}</a>
+ {% if thread.category %}
+ <li class="type type_{{thread.category|lower}}">
+ <a href="{% url search_tag mlist_fqdn=list_address, tag=thread.category|lower %}"
+ >{{ thread.category }}</a>
</li>
{% endif %}
- {% if use_mockups %}
+ {% if use_mockups %}
<li class="likestatus neutral">
+0/-0
</li>
- {% endif %}
+ {% endif %}
<li class="participant">
- {{email.participants|length}}
+ {{ thread.participants|length }}
</li>
<li class="discussion">
- {{email.answers}}
+ {{ thread|length }}
</li>
</ul>
</div>
@@ -155,7 +161,7 @@
{% endfor %}
</section>
- {% if top_author %}
+ {% if top_author %}
<section id="discussion_marker">
<h2>Prominent discussion maker</h2>
{% for author in top_author %}
@@ -181,9 +187,9 @@
<h2>Tag cloud</h2>
</section>
- {% endif %}
+ {% endif %}
- {% if threads_per_category %}
+ {% if threads_per_category %}
<section id="discussion_by_topic">
<h2>Discussion by topic the last 30 days</h2>
{% for category, thread in threads_per_category.items %}
@@ -199,7 +205,7 @@
</div>
{% endfor %}
</section>
- {% endif %}
+ {% endif %}
</section>
diff --git a/hyperkitty/templates/threads/right_col.html b/hyperkitty/templates/threads/right_col.html
index 253aa10..1b1cf76 100644
--- a/hyperkitty/templates/threads/right_col.html
+++ b/hyperkitty/templates/threads/right_col.html
@@ -1,4 +1,5 @@
{% load gravatar %}
+{% load hk_generic %}
<!-- right column -->
<section id="thread_overview_info">
@@ -47,12 +48,12 @@
</form>
</div>
<div id="participants">
- <span id="participants_title"> participants </span>({{participants|length}})
+ <span id="participants_title">participants</span> ({{participants|length}})
<ul>
- {% for key,value in participants.items %}
+ {% for name, email in participants.items|sort %}
<li>
- {% gravatar_img_for_email value.email 20%}
- {{key}}
+ {% gravatar_img_for_email email 20 %}
+ {{ name }}
</li>
{% endfor %}
</ul>
diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py
index 36805d0..8fda41d 100644
--- a/hyperkitty/views/list.py
+++ b/hyperkitty/views/list.py
@@ -45,10 +45,6 @@ logger = logging.getLogger(__name__)
if settings.USE_MOCKUPS:
from hyperkitty.lib.mockup import generate_top_author, generate_thread_per_category
-# @TODO : Move this into settings.py
-MONTH_PARTICIPANTS = 284
-MONTH_DISCUSSIONS = 82
-
def archives(request, mlist_fqdn, year=None, month=None, day=None):
@@ -96,12 +92,8 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
participants = set()
cnt = 0
for thread in threads:
- # Statistics on how many participants and threads this month
- participants.add(thread.sender_name)
- thread.participants = store.get_thread_participants(mlist_fqdn,
- thread.thread_id)
- thread.answers = store.get_thread_length(mlist_fqdn,
- thread.thread_id)
+ print "*"*10, len(thread), thread.thread_id, thread.starting_email is None
+ participants.update(thread.participants)
highestlike = 0
highestdislike = 0
@@ -109,12 +101,11 @@ def archives(request, mlist_fqdn, year=None, month=None, day=None):
totalvotes = 0
totallikes = 0
totaldislikes = 0
- messages = store.get_messages_in_thread(mlist_fqdn, thread.thread_id)
- for message in messages:
+ for message_id in thread.email_ids:
# Extract all the votes for this message
try:
- votes = Rating.objects.filter(messageid=message.message_id)
+ votes = Rating.objects.filter(messageid=message_id)
except Rating.DoesNotExist:
votes = {}
@@ -210,33 +201,26 @@ def list(request, mlist_fqdn=None):
participants = set()
dates = {}
- cnt = 0
- for msg in threads:
- month = msg.date.month
+ for thread in threads:
+ month = thread.date_active.month
if month < 10:
month = '0%s' % month
- day = msg.date.day
+ day = thread.date_active.day
if day < 10:
day = '0%s' % day
- key = '%s%s%s' % (msg.date.year, month, day)
+ key = '%s%s%s' % (thread.date_active.year, month, day)
if key in dates:
dates[key] = dates[key] + 1
else:
dates[key] = 1
# Statistics on how many participants and threads this month
- participants.add(msg.sender_name)
- msg.participants = store.get_thread_participants(mlist_fqdn,
- msg.thread_id)
- msg.answers = store.get_thread_length(mlist_fqdn,
- msg.thread_id)
- threads[cnt] = msg
- cnt = cnt + 1
+ participants.update(thread.participants)
# top threads are the one with the most answers
- top_threads = sorted(threads, key=lambda entry: entry.answers, reverse=True)
+ top_threads = sorted(threads, key=lambda entry: len(entry), reverse=True)
# active threads are the ones that have the most recent posting
- active_threads = sorted(threads, key=lambda entry: entry.date, reverse=True)
+ active_threads = sorted(threads, key=lambda entry: entry.date_active, reverse=True)
archives_length = get_months(store, mlist_fqdn)
@@ -253,8 +237,6 @@ def list(request, mlist_fqdn=None):
days = dates.keys()
days.sort()
dates_string = ["%s/%s/%s" % (key[0:4], key[4:6], key[6:8]) for key in days]
- #print days
- #print dates_string
evolution = [dates[key] for key in days]
if not evolution:
evolution.append(0)
@@ -285,7 +267,7 @@ def list(request, mlist_fqdn=None):
def _search_results_page(request, mlist_fqdn, threads, search_type,
- page=1, num_threads=25, limit=None):
+ page=1, num_threads=25, limit=None):
search_form = SearchForm(auto_id=False)
t = loader.get_template('search.html')
list_name = mlist_fqdn.split('@')[0]
@@ -305,19 +287,11 @@ def _search_results_page(request, mlist_fqdn, threads, search_type,
store = get_store(request)
cnt = 0
- for msg in threads.object_list:
- msg.email = msg.sender_email.strip()
+ for thread in threads.object_list:
+ #msg.email = msg.sender_email.strip()
# Statistics on how many participants and threads this month
- participants.add(msg.sender_name)
- if msg.thread_id:
- msg.participants = store.get_thread_participants(mlist_fqdn,
- msg.thread_id)
- msg.answers = store.get_thread_length(mlist_fqdn,
- msg.thread_id)
- else:
- msg.participants = 0
- msg.answers = 0
- threads.object_list[cnt] = msg
+ participants.update(thread.participants)
+ threads.object_list[cnt] = thread
cnt = cnt + 1
c = RequestContext(request, {
@@ -347,7 +321,7 @@ def search(request, mlist_fqdn):
def search_keyword(request, mlist_fqdn, target, keyword, page=1):
- ## Should we remove the code below?
+ ## Should we remove the code below?
## If urls.py does it job we should never need it
store = get_store(request)
if not keyword:
@@ -371,7 +345,7 @@ def search_keyword(request, mlist_fqdn, target, keyword, page=1):
def search_tag(request, mlist_fqdn, tag=None, page=1):
- '''Returns emails having a particular tag'''
+ '''Returns threads having a particular tag'''
store = get_store(settings.KITTYSTORE_URL)
list_name = mlist_fqdn.split('@')[0]
@@ -382,9 +356,8 @@ def search_tag(request, mlist_fqdn, tag=None, page=1):
thread_ids = {}
threads = []
- for thread in thread_ids:
- threads_tmp = store.get_messages_in_thread(mlist_fqdn, thread.threadid)
- threads.append(threads_tmp[0])
+ for thread_id in thread_ids:
+ threads.append(store.get_thread(mlist_fqdn, thread_id))
return _search_results_page(request, mlist_fqdn, threads,
'Tag search', page, limit=50)
diff --git a/hyperkitty/views/thread.py b/hyperkitty/views/thread.py
index 06997a4..4edd7f7 100644
--- a/hyperkitty/views/thread.py
+++ b/hyperkitty/views/thread.py
@@ -25,6 +25,8 @@ from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.template import RequestContext, loader
from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger, InvalidPage
+from django.core.urlresolvers import reverse
+from django.utils.datastructures import SortedDict
from django.contrib.auth.decorators import (login_required,
permission_required,
user_passes_test)
@@ -35,23 +37,20 @@ from forms import *
from hyperkitty.lib import get_months, get_store, stripped_subject
-def thread_index (request, mlist_fqdn, threadid):
+def thread_index(request, mlist_fqdn, threadid):
''' Displays all the email for a given thread identifier '''
search_form = SearchForm(auto_id=False)
t = loader.get_template('thread.html')
store = get_store(request)
- messages = store.get_messages_in_thread(mlist_fqdn, threadid)
- if not messages:
+ thread = store.get_thread(mlist_fqdn, threadid)
+ if not thread:
raise Http404
prev_thread, next_thread = store.get_thread_neighbors(mlist_fqdn, threadid)
participants = {}
cnt = 0
- for message in messages:
- # @TODO: Move this logic inside KittyStore?
- message.sender_email = message.sender_email.strip()
-
+ for message in thread.emails:
# Extract all the votes for this message
try:
votes = Rating.objects.filter(messageid=message.message_id)
@@ -82,11 +81,12 @@ def thread_index (request, mlist_fqdn, threadid):
# Statistics on how many participants and messages this month
- participants[message.sender_name] = {'email': message.sender_email}
+ participants[message.sender_name] = message.sender_email
cnt = cnt + 1
archives_length = get_months(store, mlist_fqdn)
- from_url = '/thread/%s/%s/' % (mlist_fqdn, threadid)
+ from_url = reverse("thread", kwargs={"mlist_fqdn":mlist_fqdn,
+ "threadid":threadid})
tag_form = AddTagForm(initial={'from_url' : from_url})
try:
@@ -96,11 +96,11 @@ def thread_index (request, mlist_fqdn, threadid):
# Extract relative dates
today = datetime.date.today()
- days_old = today - messages[0].date.date()
- days_inactive = today - messages[-1].date.date()
+ days_old = today - thread.starting_email.date.date()
+ days_inactive = today - thread.last_email.date.date()
mlist = store.get_list(mlist_fqdn)
- subject = stripped_subject(mlist, messages[0].subject)
+ subject = stripped_subject(mlist, thread.starting_email.subject)
c = RequestContext(request, {
'mlist' : mlist,
@@ -113,8 +113,8 @@ def thread_index (request, mlist_fqdn, threadid):
'month': 'Thread',
'participants': participants,
'answers': cnt,
- 'first_mail': messages[0],
- 'replies': messages[1:],
+ 'first_mail': thread.starting_email,
+ 'replies': list(thread.emails)[1:],
'neighbors': (prev_thread, next_thread),
'archives_length': archives_length,
'days_inactive': days_inactive.days,