Ejemplo n.º 1
0
def archives(request, mlist_fqdn, year=None, month=None, day=None):
    if year is None and month is None:
        today = datetime.date.today()
        return redirect(
            reverse('hk_archives_with_month',
                    kwargs={
                        "mlist_fqdn": mlist_fqdn,
                        'year': today.year,
                        'month': today.month
                    }))

    try:
        begin_date, end_date = get_display_dates(year, month, day)
    except ValueError:
        # Wrong date format, for example 9999/0/0
        raise Http404("Wrong date format")
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    threads = mlist.get_threads_between(begin_date, end_date)
    if day is None:
        list_title = date_format(begin_date, "F Y")
        no_results_text = "for this month"
    else:
        #list_title = date_format(begin_date, settings.DATE_FORMAT)
        list_title = formats.date_format(begin_date)  # works with i18n
        no_results_text = "for this day"
    extra_context = {
        'month': begin_date,
        'month_num': begin_date.month,
        "list_title": list_title.capitalize(),
        "no_results_text": no_results_text,
    }
    if day is None:
        extra_context["participants_count"] = \
            mlist.get_participants_count_for_month(int(year), int(month))
    return _thread_list(request, mlist, threads, extra_context=extra_context)
Ejemplo n.º 2
0
def archives(request, mlist_fqdn, year=None, month=None, day=None):
    if year is None and month is None:
        today = datetime.date.today()
        return redirect(reverse(
                'archives_with_month', kwargs={
                    "mlist_fqdn": mlist_fqdn,
                    'year': today.year,
                    'month': today.month}))

    begin_date, end_date = get_display_dates(year, month, day)
    store = get_store(request)
    mlist = store.get_list(mlist_fqdn)
    threads = store.get_threads(mlist_fqdn, start=begin_date, end=end_date)
    if day is None:
        list_title = date_format(begin_date, "F Y")
        no_results_text = "for this month"
    else:
        #list_title = date_format(begin_date, settings.DATE_FORMAT)
        list_title = formats.date_format(begin_date) # works with i18n
        no_results_text = "for this day"
    extra_context = {
        'month': begin_date,
        'month_num': begin_date.month,
        "list_title": list_title.capitalize(),
        "no_results_text": no_results_text,
    }
    return _thread_list(request, mlist, threads, extra_context=extra_context)
Ejemplo n.º 3
0
def archives(request, mlist_fqdn, year=None, month=None, day=None):
    if year is None and month is None:
        today = datetime.date.today()
        return redirect(reverse(
                'hk_archives_with_month', kwargs={
                    "mlist_fqdn": mlist_fqdn,
                    'year': today.year,
                    'month': today.month}))

    try:
        begin_date, end_date = get_display_dates(year, month, day)
    except ValueError:
        # Wrong date format, for example 9999/0/0
        raise Http404("Wrong date format")
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    threads = mlist.get_threads_between(begin_date, end_date)
    if day is None:
        list_title = date_format(begin_date, "F Y")
        no_results_text = "for this month"
    else:
        #list_title = date_format(begin_date, settings.DATE_FORMAT)
        list_title = formats.date_format(begin_date) # works with i18n
        no_results_text = "for this day"
    extra_context = {
        'month': begin_date,
        'month_num': begin_date.month,
        "list_title": list_title.capitalize(),
        "no_results_text": no_results_text,
    }
    if day is None:
        extra_context["participants_count"] = \
            mlist.get_participants_count_for_month(int(year), int(month))
    return _thread_list(request, mlist, threads, extra_context=extra_context)
Ejemplo n.º 4
0
def archives(request, mlist_fqdn, year=None, month=None, day=None):
    if year is None and month is None:
        today = datetime.date.today()
        return redirect(reverse(
                'archives_with_month', kwargs={
                    "mlist_fqdn": mlist_fqdn,
                    'year': today.year,
                    'month': today.month}))

    begin_date, end_date = get_display_dates(year, month, day)
    store = get_store(request)
    mlist = store.get_list(mlist_fqdn)
    threads = store.get_threads(mlist_fqdn, start=begin_date, end=end_date)
    if day is None:
        list_title = date_format(begin_date, "F Y")
        no_results_text = "for this month"
    else:
        #list_title = date_format(begin_date, settings.DATE_FORMAT)
        list_title = formats.date_format(begin_date) # works with i18n
        no_results_text = "for this day"
    extra_context = {
        'month': begin_date,
        'month_num': begin_date.month,
        "list_title": list_title.capitalize(),
        "no_results_text": no_results_text,
    }
    return _thread_list(request, mlist, threads, extra_context=extra_context)
Ejemplo n.º 5
0
 def test_month_december(self):
     try:
         begin_date, end_date = get_display_dates('2012', '12', None)
     except ValueError as e:
         self.fail(e)
     self.assertEqual(begin_date, datetime.datetime(2012, 12, 1,
                                                    tzinfo=utc))
     self.assertEqual(end_date, datetime.datetime(2013, 1, 1, tzinfo=utc))
Ejemplo n.º 6
0
def archives(request, mlist_fqdn, year=None, month=None, day=None):
    if year is None and month is None:
        today = datetime.date.today()
        return redirect(
            reverse('hk_archives_with_month',
                    kwargs={
                        "mlist_fqdn": mlist_fqdn,
                        'year': today.year,
                        'month': today.month
                    }))

    try:
        begin_date, end_date = get_display_dates(year, month, day)
    except ValueError:
        # Wrong date format, for example 9999/0/0
        raise Http404("Wrong date format")
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    threads = mlist.get_threads_between(begin_date, end_date)
    if day is None:
        list_title = date_format(begin_date, "F Y")
        no_results_text = "for this month"
    else:
        list_title = formats.date_format(begin_date)  # works with i18n
        no_results_text = "for this day"
    # Export button
    export = {
        "url":
        "%s?start=%s&end=%s" % (reverse(
            "hk_list_export_mbox",
            kwargs={
                "mlist_fqdn": mlist.name,
                "filename": "%s-%s" %
                (mlist.name, begin_date.strftime("%Y-%m"))
            }), begin_date.strftime("%Y-%m-%d"),
                                end_date.strftime("%Y-%m-%d")),
        "message":
        _("Download"),
        "title":
        _("This month in gzipped mbox format"),
    }
    extra_context = {
        'month': begin_date,
        'month_num': begin_date.month,
        "list_title": list_title.capitalize(),
        "no_results_text": no_results_text,
        "export": export,
    }
    if day is None:
        extra_context["participants_count"] = \
            mlist.get_participants_count_for_month(int(year), int(month))
    return _thread_list(request, mlist, threads, extra_context=extra_context)
Ejemplo n.º 7
0
def archives(request, mlist_fqdn, year=None, month=None, day=None):
    if year is None and month is None:
        today = datetime.date.today()
        return redirect(reverse(
                'hk_archives_with_month', kwargs={
                    "mlist_fqdn": mlist_fqdn,
                    'year': today.year,
                    'month': today.month}))

    try:
        begin_date, end_date = get_display_dates(year, month, day)
    except ValueError:
        # Wrong date format, for example 9999/0/0
        raise Http404("Wrong date format")
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)
    threads = mlist.get_threads_between(begin_date, end_date)
    if day is None:
        list_title = date_format(begin_date, "F Y")
        no_results_text = "for this month"
    else:
        #list_title = date_format(begin_date, settings.DATE_FORMAT)
        list_title = formats.date_format(begin_date) # works with i18n
        no_results_text = "for this day"
    # Export button
    export = {
        "url": "%s?start=%s&end=%s" % (
            reverse("hk_list_export_mbox", kwargs={
                    "mlist_fqdn": mlist.name,
                    "filename": "%s-%s" % (
                        mlist.name, begin_date.strftime("%Y-%m"))}),
            begin_date.strftime("%Y-%m-%d"),
            end_date.strftime("%Y-%m-%d")),
        "message": _("Download"),
        "title": _("This month in gzipped mbox format"),
    }
    extra_context = {
        'month': begin_date,
        'month_num': begin_date.month,
        "list_title": list_title.capitalize(),
        "no_results_text": no_results_text,
        "export": export,
    }
    if day is None:
        extra_context["participants_count"] = \
            mlist.get_participants_count_for_month(int(year), int(month))
    return _thread_list(request, mlist, threads, extra_context=extra_context)
Ejemplo n.º 8
0
def overview(request, mlist_fqdn=None):
    if not mlist_fqdn:
        return redirect('/')
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)

    # top authors are the ones that have the most kudos.  How do we determine
    # that?  Most likes for their post?
    authors = []

    # Threads by category
    threads_by_category = {}

    # 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_author': authors,
        'threads_by_category': threads_by_category,
        'months_list': get_months(mlist),
        'export': export,
        'posting_enabled': getattr(settings, 'HYPERKITTY_ALLOW_WEB_POSTING',
                                   True),
    }
    return render(request, "hyperkitty/overview.html", context)
Ejemplo n.º 9
0
 def test_day(self):
     begin_date, end_date = get_display_dates('2012', '4', '2')
     self.assertEqual(begin_date, datetime.datetime(2012, 4, 2, tzinfo=utc))
     self.assertEqual(end_date, datetime.datetime(2012, 4, 3, tzinfo=utc))
Ejemplo n.º 10
0
 def test_month(self):
     begin_date, end_date = get_display_dates('2012', '6', None)
     self.assertEqual(begin_date, datetime.datetime(2012, 6, 1, tzinfo=utc))
     self.assertEqual(end_date, datetime.datetime(2012, 7, 1, tzinfo=utc))
Ejemplo n.º 11
0
 def test_day(self):
     begin_date, end_date = get_display_dates('2012', '4', '2')
     self.assertEqual(begin_date, datetime.datetime(2012, 4, 2))
     self.assertEqual(end_date, datetime.datetime(2012, 4, 3))
Ejemplo n.º 12
0
 def test_month_december(self):
     try:
         begin_date, end_date = get_display_dates('2012', '12', None)
     except ValueError, e:
         self.fail(e)
Ejemplo n.º 13
0
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)
Ejemplo n.º 14
0
def archives(request, mlist_fqdn, year=None, month=None, day=None):
    """List of threads in MailingList.

    If year & month is None, we return *all* the threads and render a view with
    all the threads of a MailingList.
    """
    mlist = get_object_or_404(MailingList, name=mlist_fqdn)

    if year is None and month is None:
        # If the year and month is None, we set the begin date to the date of
        # the first email and end date to be today.
        end_date = datetime.date.today()
        # Since we don't need any special filtering, just return *all* the
        # threads ordered by date_active.
        threads = mlist.threads.order_by("-date_active")
        if threads:
            begin_date = Email.objects.order_by('date').first().date
        else:
            begin_date = end_date
        # Set the month and year to be today's.
        year = end_date.year
        month = end_date.month
        # The list title for all the threads.
        list_title = ""
        no_results_text = "for this MailingList"
    else:
        try:
            begin_date, end_date = get_display_dates(year, month, day)
        except ValueError:
            # Wrong date format, for example 9999/0/0
            raise Http404("Wrong date format")

        threads = mlist.get_threads_between(begin_date, end_date)

        if day is None:
            list_title = date_format(begin_date, "F Y")
            no_results_text = _("for this month")
        else:
            list_title = formats.date_format(begin_date)  # works with i18n
            no_results_text = _("for this day")

    # Export button
    export = {
        "url":
        "%s?start=%s&end=%s" %
        (reverse("hk_list_export_mbox",
                 kwargs={
                     "mlist_fqdn": mlist.name,
                     "filename": "%s-%s" %
                     (mlist.name, end_date.strftime("%Y-%m"))
                 }), begin_date.strftime("%Y-%m-%d"),
         end_date.strftime("%Y-%m-%d")),
        "message":
        _("Download"),
        "title":
        _("This month in gzipped mbox format"),
    }
    extra_context = {
        'month': begin_date,
        'month_num': begin_date.month,
        "list_title": list_title.capitalize(),
        "no_results_text": no_results_text,
        "export": export,
    }
    if day is None:
        extra_context["participants_count"] = \
            mlist.get_participants_count_for_month(int(year), int(month))
    return _thread_list(request, mlist, threads, extra_context=extra_context)
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
 def test_month(self):
     begin_date, end_date = get_display_dates('2012', '6', None)
     self.assertEqual(begin_date, datetime.datetime(2012, 6, 1))
     self.assertEqual(end_date, datetime.datetime(2012, 7, 1))
Ejemplo n.º 17
0
 def test_month_december(self):
     try:
         begin_date, end_date = get_display_dates('2012', '12', None)
     except ValueError, e:
         self.fail(e)