From b6b540c44917744098805e5f70207289a3755eac Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Fri, 9 Nov 2012 13:54:13 +0100 Subject: Use the new thread object in KittyStore --- hyperkitty/api.py | 2 +- hyperkitty/templates/month_view.html | 55 ++++++++++++----------- hyperkitty/templates/recent_activities.html | 64 ++++++++++++++------------- hyperkitty/templates/threads/right_col.html | 9 ++-- hyperkitty/views/list.py | 67 +++++++++-------------------- hyperkitty/views/thread.py | 28 ++++++------ 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 %} - {% for email in threads %} + {% for thread in threads %}
- {{ email.subject|strip_subject:mlist }} - {{email.date|timesince }} + {{ thread.starting_email.subject|strip_subject:mlist }} + {{thread.date_active|timesince }}
- {% if email.category_tag %} -
- {{email.category}} + {% if thread.category_tag %} + {% endif %} - {% if email.category %} -
- {{email.category}} + {% if thread.category %} + {% endif %}
- {% 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 %}
{% endif %} - {{email.sender_name}} + {{ thread.starting_email.sender_name }}
- {{email.content}} + {{ thread.starting_email.content }}
    - {% if email.tags|length %} + {% if thread.tags|length %}
  • Tags:
  • - {% for tag in email.tags %} + {% for tag in thread.tags %}
  • {{tag}}
  • @@ -70,16 +73,16 @@
  • - {{email.participants|length}} participants + {{ thread.participants|length }} participants
  • - {{email.answers}} comments + {{ thread|length }} comments
- {% if use_mockups %} -
    -
  • - +{{email.avglike}}/-{{email.avgdislike}} + {% if use_mockups %} +
      +
    • + +{{ thread.avglike }}/-{{ thread.avgdislike }}
    • Like @@ -88,9 +91,9 @@ Dislike
    - Show discussion - {% endif %} + Show discussion + {% endif %}
@@ -113,7 +116,7 @@ userCollapseText : 'View Less', expandText : 'View More' }); - }); + }); {% 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 @@

Recently active discussions

- {% for email in most_active_threads %} + {% for thread in most_active_threads %}
#{{forloop.counter}} - {{ email.subject|strip_subject:mlist }} + {{ thread.starting_email.subject|strip_subject:mlist }}
    - {% if email.category_tag %} -
  • - {{email.category}} + {% if thread.category_tag %} +
  • + {{thread.category}}
  • {% endif %} - {% if email.category %} -
  • - {{email.category}} + {% if thread.category %} +
  • + {{thread.category}}
  • {% endif %} - {% if use_mockups %} + {% if use_mockups %}
  • +0/-0
  • {% endif %}
  • - {{email.participants|length}} + {{ thread.participants|length }}
  • - {{email.answers}} + {{ thread|length }}
@@ -119,34 +122,37 @@

Top discussions the last 30 days

- {% for email in top_threads %} + {% for thread in top_threads %}
#{{forloop.counter}} - {{ email.subject|strip_subject:mlist }} + {{ thread.starting_email.subject|strip_subject:mlist }}
    - {% if email.category_tag %} -
  • - {{email.category}} + {% if thread.category_tag %} +
  • + {{ thread.category }}
  • {% endif %} - {% if email.category %} -
  • - {{email.category}} + {% if thread.category %} +
  • + {{ thread.category }}
  • {% endif %} - {% if use_mockups %} + {% if use_mockups %}
  • +0/-0
  • - {% endif %} + {% endif %}
  • - {{email.participants|length}} + {{ thread.participants|length }}
  • - {{email.answers}} + {{ thread|length }}
@@ -155,7 +161,7 @@ {% endfor %}
- {% if top_author %} + {% if top_author %}

Prominent discussion maker

{% for author in top_author %} @@ -181,9 +187,9 @@

Tag cloud

- {% endif %} + {% endif %} - {% if threads_per_category %} + {% if threads_per_category %}

Discussion by topic the last 30 days

{% for category, thread in threads_per_category.items %} @@ -199,7 +205,7 @@
{% endfor %}
- {% endif %} + {% endif %} 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 %}
@@ -47,12 +48,12 @@
- participants ({{participants|length}}) + participants ({{participants|length}})
    - {% for key,value in participants.items %} + {% for name, email in participants.items|sort %}
  • - {% gravatar_img_for_email value.email 20%} - {{key}} + {% gravatar_img_for_email email 20 %} + {{ name }}
  • {% endfor %}
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, -- cgit