def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') # Get stats for last 30 days today = datetime.datetime.utcnow() #today -= datetime.timedelta(days=365) #debug # the upper boundary is excluded in the search, add one day end_date = today + datetime.timedelta(days=1) begin_date = end_date - datetime.timedelta(days=32) store = get_store(request) mlist = store.get_list(mlist_fqdn) if mlist is None: raise Http404("No archived mailing-list by that name.") threads_result = store.get_threads( list_name=mlist.name, start=begin_date, end=end_date) threads = [] participants = set() for thread_obj in threads_result: # Votes set_thread_votes(thread_obj, request.user) thread = Thread(thread_obj.thread_id, thread_obj.subject, thread_obj.participants, len(thread_obj), thread_obj.date_active.replace(tzinfo=utc), thread_obj.likes, thread_obj.dislikes, thread_obj.likestatus, get_category_widget(None, thread_obj.category)[0], is_thread_unread(request, mlist.name, thread_obj), ) # Statistics on how many participants and threads this month participants.update(thread.participants) threads.append(thread) # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: t.length, reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if settings.USE_MOCKUPS: authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # Top posters top_posters = [] for poster in store.get_top_participants(list_name=mlist.name, start=begin_date, end=end_date, limit=5): top_posters.append({"name": poster[0], "email": poster[1], "count": poster[2]}) # Popular threads pop_threads = sorted([ t for t in threads if t.likes - t.dislikes > 0 ], key=lambda t: t.likes - t.dislikes, reverse=True) # Threads by category threads_by_category = {} for thread in active_threads: if not thread.category: continue # don't use defaultdict, use .setdefault(): # http://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict if len(threads_by_category.setdefault(thread.category, [])) >= 5: continue threads_by_category[thread.category].append(thread) # List activity # Use get_messages and not get_threads to count the emails, because # recently active threads include messages from before the start date emails_in_month = store.get_messages(list_name=mlist.name, start=begin_date, end=end_date) # graph dates = defaultdict(lambda: 0) # no activity by default # populate with all days before adding data. for single_date in daterange(begin_date, end_date): dates[single_date.strftime("%Y-%m-%d")] = 0 for email in emails_in_month: date_str = email.date.strftime("%Y-%m-%d") dates[date_str] = dates[date_str] + 1 days = dates.keys() days.sort() evolution = [dates[d] for d in days] if not evolution: evolution.append(0) archives_baseurl = reverse("archives_latest", kwargs={'mlist_fqdn': mlist.name}) archives_baseurl = archives_baseurl.rpartition("/")[0] context = { 'view_name': 'overview', 'mlist' : mlist, 'top_threads': top_threads[:5], 'most_active_threads': active_threads[:5], 'top_author': authors, 'top_posters': top_posters, 'pop_threads': pop_threads[:5], 'threads_by_category': threads_by_category, 'months_list': get_months(store, mlist.name), 'evolution': evolution, 'days': days, 'archives_baseurl': archives_baseurl, 'num_threads': len(threads), 'num_participants': len(participants), } return render(request, "overview.html", context)
def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') # Get stats for last 30 days today = datetime.datetime.utcnow() #today -= datetime.timedelta(days=365) #debug # the upper boundary is excluded in the search, add one day end_date = today + datetime.timedelta(days=1) begin_date = end_date - datetime.timedelta(days=32) store = get_store(request) mlist = store.get_list(mlist_fqdn) if mlist is None: raise Http404("No archived mailing-list by that name.") threads_result = store.get_threads( list_name=mlist.name, start=begin_date, end=end_date) threads = [] participants = set() for thread_obj in threads_result: # Votes set_thread_votes(thread_obj, request.user) thread = Thread(thread_obj.thread_id, thread_obj.subject, thread_obj.participants, len(thread_obj), thread_obj.date_active.replace(tzinfo=utc), thread_obj.likes, thread_obj.dislikes, thread_obj.likestatus, get_category_widget(None, thread_obj.category)[0], is_thread_unread(request, mlist.name, thread_obj), ) # Statistics on how many participants and threads this month participants.update(thread.participants) threads.append(thread) # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: t.length, reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if settings.USE_MOCKUPS: authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # Top posters top_posters = [] for poster in store.get_top_participants(list_name=mlist.name, start=begin_date, end=end_date, limit=5): top_posters.append({"name": poster[0], "email": poster[1], "count": poster[2]}) # Popular threads pop_threads = sorted([ t for t in threads if t.likes - t.dislikes > 0 ], key=lambda t: t.likes - t.dislikes, reverse=True) # Threads by category threads_by_category = {} for thread in active_threads: if not thread.category: continue # don't use defaultdict, use .setdefault(): # http://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict if len(threads_by_category.setdefault(thread.category, [])) >= 5: continue threads_by_category[thread.category].append(thread) # List activity # Use get_messages and not get_threads to count the emails, because # recently active threads include messages from before the start date emails_in_month = store.get_messages(list_name=mlist.name, start=begin_date, end=end_date) # graph dates = defaultdict(lambda: 0) # no activity by default # populate with all days before adding data. for single_date in daterange(begin_date, end_date): dates[single_date.strftime("%Y-%m-%d")] = 0 for email in emails_in_month: date_str = email.date.strftime("%Y-%m-%d") dates[date_str] = dates[date_str] + 1 days = dates.keys() days.sort() evolution = [dates[d] for d in days] if not evolution: evolution.append(0) archives_baseurl = reverse("archives_latest", kwargs={'mlist_fqdn': mlist.name}) archives_baseurl = archives_baseurl.rpartition("/")[0] context = { 'view_name': 'overview', 'mlist' : mlist, 'top_threads': top_threads[:5], 'most_active_threads': active_threads[:5], 'top_author': authors, 'top_posters': top_posters, 'pop_threads': pop_threads[:5], 'threads_by_category': threads_by_category, 'months_list': get_months(store, mlist.name), 'evolution': evolution, 'days': days, 'archives_baseurl': archives_baseurl, 'num_threads': len(threads), 'num_participants': len(participants), } return render(request, "overview.html", context)
def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') mlist = get_object_or_404(MailingList, name=mlist_fqdn) threads = [] for thread_obj in mlist.recent_threads: thread_obj.category_widget = get_category_widget( None, thread_obj.category)[0] threads.append(thread_obj) # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: t.emails_count, reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if settings.USE_MOCKUPS: authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # Popular threads pop_threads = [] for t in threads: votes = t.get_votes() if votes["likes"] - votes["dislikes"] > 0: pop_threads.append(t) def _get_thread_vote_result(t): votes = t.get_votes() return votes["likes"] - votes["dislikes"] pop_threads.sort(key=_get_thread_vote_result, reverse=True) # Threads by category threads_by_category = {} for thread in active_threads: if not thread.category: continue # don't use defaultdict, use .setdefault(): # http://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict if len(threads_by_category.setdefault(thread.category, [])) >= 5: continue threads_by_category[thread.category].append(thread) # Personalized discussion groups: flagged/favorited threads and threads by user if request.user.is_authenticated(): favorites = [ f.thread for f in Favorite.objects.filter( thread__mailinglist=mlist, user=request.user) ] mm_user_id = request.user.hyperkitty_profile.get_mailman_user_id() threads_posted_to = [] if mm_user_id is not None: for thread in threads: senders = set([e.sender.mailman_id for e in thread.emails.all()]) if mm_user_id in senders: threads_posted_to.append(thread) else: favorites = [] threads_posted_to = [] # Empty messages # TODO: translate this empty_messages = { "flagged": 'You have not flagged any discussions (yet).', "posted": 'You have not posted to this list (yet).', "active": 'No discussions this month (yet).', "popular": 'No vote has been cast this month (yet).', } context = { 'view_name': 'overview', 'mlist' : mlist, 'top_threads': top_threads[:20], 'most_active_threads': active_threads[:20], 'top_author': authors, 'pop_threads': pop_threads[:20], 'threads_by_category': threads_by_category, 'months_list': get_months(mlist), 'flagged_threads': favorites, 'threads_posted_to': threads_posted_to, 'empty_messages': empty_messages, } return render(request, "hyperkitty/overview.html", context)
def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') mlist = get_object_or_404(MailingList, name=mlist_fqdn) threads = mlist.recent_threads # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: t.emails_count, reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if getattr(settings, 'USE_MOCKUPS', False): from hyperkitty.lib.mockup import generate_top_author authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # Popular threads pop_threads = [] for t in threads: votes = t.get_votes() if votes["likes"] - votes["dislikes"] > 0: pop_threads.append(t) def _get_thread_vote_result(t): votes = t.get_votes() return votes["likes"] - votes["dislikes"] pop_threads.sort(key=_get_thread_vote_result, reverse=True) # Threads by category threads_by_category = {} for thread in active_threads: if not thread.category: continue # don't use defaultdict, use .setdefault(): # http://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict if len(threads_by_category.setdefault(thread.category, [])) >= 5: continue threads_by_category[thread.category].append(thread) # Personalized discussion groups: flagged/favorited threads and threads by # user. if request.user.is_authenticated(): favorites = [ f.thread for f in Favorite.objects.filter(thread__mailinglist=mlist, user=request.user) ] mm_user_id = get_mailman_user_id(request.user) threads_posted_to = [] if mm_user_id is not None: for thread in threads: senders = set( [e.sender.mailman_id for e in thread.emails.all()]) if mm_user_id in senders: threads_posted_to.append(thread) else: favorites = [] threads_posted_to = [] # Empty messages # TODO: translate this empty_messages = { "flagged": 'You have not flagged any discussions (yet).', "posted": 'You have not posted to this list (yet).', "active": 'No discussions this month (yet).', "popular": 'No vote has been cast this month (yet).', } # Export button recent_dates = [d.strftime("%Y-%m-%d") for d in mlist.get_recent_dates()] recent_url = "%s?start=%s&end=%s" % (reverse( "hk_list_export_mbox", kwargs={ "mlist_fqdn": mlist.name, "filename": "%s-%s-%s" % (mlist.name, recent_dates[0], recent_dates[1]) }), recent_dates[0], recent_dates[1]) today = datetime.date.today() month_dates = get_display_dates(today.year, today.month, None) month_url = "%s?start=%s&end=%s" % (reverse( "hk_list_export_mbox", kwargs={ "mlist_fqdn": mlist.name, "filename": "%s-%s" % (mlist.name, today.strftime("%Y-%m")) }), month_dates[0].strftime("%Y-%m-%d"), month_dates[1].strftime("%Y-%m-%d")) export = {"recent": recent_url, "month": month_url} context = { 'view_name': 'overview', 'mlist': mlist, 'top_threads': top_threads[:20], 'most_active_threads': active_threads[:20], 'top_author': authors, 'pop_threads': pop_threads[:20], 'threads_by_category': threads_by_category, 'months_list': get_months(mlist), 'flagged_threads': favorites, 'threads_posted_to': threads_posted_to, 'empty_messages': empty_messages, 'export': export, } return render(request, "hyperkitty/overview.html", context)
def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') store = get_store(request) mlist = store.get_list(mlist_fqdn) if mlist is None: raise Http404("No archived mailing-list by that name.") begin_date, end_date = mlist.get_recent_dates() threads_result = store.get_threads( list_name=mlist.name, start=begin_date, end=end_date) threads = [] for thread_obj in threads_result: # Votes set_thread_votes(thread_obj) thread_obj.category_widget = get_category_widget( None, thread_obj.category)[0] thread_obj.unread = is_thread_unread(request, mlist.name, thread_obj) threads.append(thread_obj) # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: len(t), reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if settings.USE_MOCKUPS: authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # Top posters top_posters = [] for poster in store.get_top_participants(list_name=mlist.name, start=begin_date, end=end_date, limit=5): top_posters.append({"name": poster[0], "email": poster[1], "count": poster[2]}) # Popular threads pop_threads = sorted([ t for t in threads if t.likes - t.dislikes > 0 ], key=lambda t: t.likes - t.dislikes, reverse=True) # Threads by category threads_by_category = {} for thread in active_threads: if not thread.category: continue # don't use defaultdict, use .setdefault(): # http://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict if len(threads_by_category.setdefault(thread.category, [])) >= 5: continue threads_by_category[thread.category].append(thread) context = { 'view_name': 'overview', 'mlist' : mlist, 'top_threads': top_threads[:5], 'most_active_threads': active_threads[:5], 'top_author': authors, 'top_posters': top_posters, 'pop_threads': pop_threads[:5], 'threads_by_category': threads_by_category, 'months_list': get_months(store, mlist.name), } return render(request, "overview.html", context)
def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') search_form = SearchForm(auto_id=False) # Get stats for last 30 days today = datetime.datetime.utcnow() # the upper boundary is excluded in the search, add one day end_date = today + datetime.timedelta(days=1) begin_date = end_date - datetime.timedelta(days=32) store = get_store(request) mlist = store.get_list(mlist_fqdn) threads_result = store.get_threads(list_name=mlist.name, start=begin_date, end=end_date) threads = [] Thread = namedtuple('Thread', ["thread_id", "subject", "participants", "length", "date_active"]) participants = set() for thread_obj in threads_result: thread = Thread(thread_obj.thread_id, thread_obj.subject, thread_obj.participants, len(thread_obj), thread_obj.date_active) # Statistics on how many participants and threads this month participants.update(thread.participants) threads.append(thread) # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: t.length, reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if settings.USE_MOCKUPS: authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # List activity # Use get_messages and not get_threads to count the emails, because # recently active threads include messages from before the start date emails_in_month = store.get_messages(list_name=mlist.name, start=begin_date, end=end_date) dates = defaultdict(lambda: 0) # no activity by default # populate with all days before adding data. for single_date in daterange(begin_date, end_date): dates[single_date.strftime("%Y-%m-%d")] = 0 for email in emails_in_month: date_str = email.date.strftime("%Y-%m-%d") dates[date_str] = dates[date_str] + 1 days = dates.keys() days.sort() evolution = [dates[d] for d in days] if not evolution: evolution.append(0) archives_baseurl = reverse("archives_latest", kwargs={'mlist_fqdn': mlist.name}) archives_baseurl = archives_baseurl.rpartition("/")[0] # threads per category is the top thread titles in each category if settings.USE_MOCKUPS: threads_per_category = generate_thread_per_category() else: threads_per_category = {} context = { 'mlist' : mlist, 'search_form': search_form, 'top_threads': top_threads[:5], 'most_active_threads': active_threads[:5], 'top_author': authors, 'threads_per_category': threads_per_category, 'months_list': get_months(store, mlist.name), 'evolution': evolution, 'days': days, 'archives_baseurl': archives_baseurl, } return render(request, "recent_activities.html", context)
def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') mlist = get_object_or_404(MailingList, name=mlist_fqdn) threads = [] for thread_obj in mlist.recent_threads: thread_obj.category_widget = get_category_widget( None, thread_obj.category)[0] threads.append(thread_obj) # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: t.emails_count, reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if settings.USE_MOCKUPS: authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # Popular threads pop_threads = [] for t in threads: votes = t.get_votes() if votes["likes"] - votes["dislikes"] > 0: pop_threads.append(t) def _get_thread_vote_result(t): votes = t.get_votes() return votes["likes"] - votes["dislikes"] pop_threads.sort(key=_get_thread_vote_result, reverse=True) # Threads by category threads_by_category = {} for thread in active_threads: if not thread.category: continue # don't use defaultdict, use .setdefault(): # http://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict if len(threads_by_category.setdefault(thread.category, [])) >= 5: continue threads_by_category[thread.category].append(thread) # Personalized discussion groups: flagged/favorited threads and threads by user if request.user.is_authenticated(): favorites = [ f.thread for f in Favorite.objects.filter(thread__mailinglist=mlist, user=request.user) ] mm_user_id = request.user.hyperkitty_profile.get_mailman_user_id() threads_posted_to = [] if mm_user_id is not None: for thread in threads: senders = set( [e.sender.mailman_id for e in thread.emails.all()]) if mm_user_id in senders: threads_posted_to.append(thread) else: favorites = [] threads_posted_to = [] # Empty messages # TODO: translate this empty_messages = { "flagged": 'You have not flagged any discussions (yet).', "posted": 'You have not posted to this list (yet).', "active": 'No discussions this month (yet).', "popular": 'No vote has been cast this month (yet).', } context = { 'view_name': 'overview', 'mlist': mlist, 'top_threads': top_threads[:20], 'most_active_threads': active_threads[:20], 'top_author': authors, 'pop_threads': pop_threads[:20], 'threads_by_category': threads_by_category, 'months_list': get_months(mlist), 'flagged_threads': favorites, 'threads_posted_to': threads_posted_to, 'empty_messages': empty_messages, } return render(request, "hyperkitty/overview.html", context)
def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') mlist = get_object_or_404(MailingList, name=mlist_fqdn) threads = mlist.recent_threads # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: t.emails_count, reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if getattr(settings, 'USE_MOCKUPS', False): from hyperkitty.lib.mockup import generate_top_author authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # Popular threads pop_threads = [] for t in threads: votes = t.get_votes() if votes["likes"] - votes["dislikes"] > 0: pop_threads.append(t) def _get_thread_vote_result(t): votes = t.get_votes() return votes["likes"] - votes["dislikes"] pop_threads.sort(key=_get_thread_vote_result, reverse=True) # Threads by category threads_by_category = {} for thread in active_threads: if not thread.category: continue # don't use defaultdict, use .setdefault(): # http://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict if len(threads_by_category.setdefault(thread.category, [])) >= 5: continue threads_by_category[thread.category].append(thread) # Personalized discussion groups: flagged/favorited threads and threads by user if request.user.is_authenticated(): favorites = [ f.thread for f in Favorite.objects.filter( thread__mailinglist=mlist, user=request.user) ] mm_user_id = request.user.hyperkitty_profile.get_mailman_user_id() threads_posted_to = [] if mm_user_id is not None: for thread in threads: senders = set([e.sender.mailman_id for e in thread.emails.all()]) if mm_user_id in senders: threads_posted_to.append(thread) else: favorites = [] threads_posted_to = [] # Empty messages # TODO: translate this empty_messages = { "flagged": 'You have not flagged any discussions (yet).', "posted": 'You have not posted to this list (yet).', "active": 'No discussions this month (yet).', "popular": 'No vote has been cast this month (yet).', } # Export button recent_dates = [ d.strftime("%Y-%m-%d") for d in mlist.get_recent_dates() ] recent_url = "%s?start=%s&end=%s" % ( reverse("hk_list_export_mbox", kwargs={ "mlist_fqdn": mlist.name, "filename": "%s-%s-%s" % ( mlist.name, recent_dates[0], recent_dates[1])}), recent_dates[0], recent_dates[1]) today = datetime.date.today() month_dates = get_display_dates(today.year, today.month, None) month_url = "%s?start=%s&end=%s" % ( reverse("hk_list_export_mbox", kwargs={ "mlist_fqdn": mlist.name, "filename": "%s-%s" % (mlist.name, today.strftime("%Y-%m"))}), month_dates[0].strftime("%Y-%m-%d"), month_dates[1].strftime("%Y-%m-%d")) export = {"recent": recent_url, "month": month_url} context = { 'view_name': 'overview', 'mlist' : mlist, 'top_threads': top_threads[:20], 'most_active_threads': active_threads[:20], 'top_author': authors, 'pop_threads': pop_threads[:20], 'threads_by_category': threads_by_category, 'months_list': get_months(mlist), 'flagged_threads': favorites, 'threads_posted_to': threads_posted_to, 'empty_messages': empty_messages, 'export': export, } return render(request, "hyperkitty/overview.html", context)
def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') search_form = SearchForm(auto_id=False) # Get stats for last 30 days today = datetime.datetime.utcnow() # the upper boundary is excluded in the search, add one day end_date = today + datetime.timedelta(days=1) begin_date = end_date - datetime.timedelta(days=32) store = get_store(request) mlist = store.get_list(mlist_fqdn) threads_result = store.get_threads(list_name=mlist.name, start=begin_date, end=end_date) threads = [] Thread = namedtuple( 'Thread', ["thread_id", "subject", "participants", "length", "date_active"]) participants = set() for thread_obj in threads_result: thread = Thread(thread_obj.thread_id, thread_obj.subject, thread_obj.participants, len(thread_obj), thread_obj.date_active) # Statistics on how many participants and threads this month participants.update(thread.participants) threads.append(thread) # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: t.length, reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if settings.USE_MOCKUPS: authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # List activity # Use get_messages and not get_threads to count the emails, because # recently active threads include messages from before the start date emails_in_month = store.get_messages(list_name=mlist.name, start=begin_date, end=end_date) dates = defaultdict(lambda: 0) # no activity by default # populate with all days before adding data. for single_date in daterange(begin_date, end_date): dates[single_date.strftime("%Y-%m-%d")] = 0 for email in emails_in_month: date_str = email.date.strftime("%Y-%m-%d") dates[date_str] = dates[date_str] + 1 days = dates.keys() days.sort() evolution = [dates[d] for d in days] if not evolution: evolution.append(0) archives_baseurl = reverse("archives_latest", kwargs={'mlist_fqdn': mlist.name}) archives_baseurl = archives_baseurl.rpartition("/")[0] # threads per category is the top thread titles in each category if settings.USE_MOCKUPS: threads_per_category = generate_thread_per_category() else: threads_per_category = {} context = { 'mlist': mlist, 'search_form': search_form, 'top_threads': top_threads[:5], 'most_active_threads': active_threads[:5], 'top_author': authors, 'threads_per_category': threads_per_category, 'months_list': get_months(store, mlist.name), 'evolution': evolution, 'days': days, 'archives_baseurl': archives_baseurl, } return render(request, "recent_activities.html", context)
def overview(request, mlist_fqdn=None): if not mlist_fqdn: return redirect('/') store = get_store(request) mlist = store.get_list(mlist_fqdn) if mlist is None: raise Http404("No archived mailing-list by that name.") begin_date, end_date = mlist.get_recent_dates() threads_result = store.get_threads( list_name=mlist.name, start=begin_date, end=end_date) threads = [] for thread_obj in threads_result: thread_obj.category_widget = get_category_widget( None, thread_obj.category)[0] thread_obj.unread = is_thread_unread(request, mlist.name, thread_obj) threads.append(thread_obj) # top threads are the one with the most answers top_threads = sorted(threads, key=lambda t: len(t), reverse=True) # active threads are the ones that have the most recent posting active_threads = sorted(threads, key=lambda t: t.date_active, reverse=True) # top authors are the ones that have the most kudos. How do we determine # that? Most likes for their post? if settings.USE_MOCKUPS: authors = generate_top_author() authors = sorted(authors, key=lambda author: author.kudos) authors.reverse() else: authors = [] # Top posters top_posters = [] for poster in store.get_top_participants(list_name=mlist.name, start=begin_date, end=end_date, limit=5): top_posters.append({"name": poster[0], "email": poster[1], "count": poster[2]}) # Popular threads pop_threads = sorted([ t for t in threads if t.likes - t.dislikes > 0 ], key=lambda t: t.likes - t.dislikes, reverse=True) # Threads by category threads_by_category = {} for thread in active_threads: if not thread.category: continue # don't use defaultdict, use .setdefault(): # http://stackoverflow.com/questions/4764110/django-template-cant-loop-defaultdict if len(threads_by_category.setdefault(thread.category, [])) >= 5: continue threads_by_category[thread.category].append(thread) context = { 'view_name': 'overview', 'mlist' : mlist, 'top_threads': top_threads[:5], 'most_active_threads': active_threads[:5], 'top_author': authors, 'top_posters': top_posters, 'pop_threads': pop_threads[:5], 'threads_by_category': threads_by_category, 'months_list': get_months(store, mlist.name), } return render(request, "overview.html", context)