From 579bd91b14f8d2926f64aa6032b41145f90b46fe Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Fri, 12 Jul 2013 11:13:54 +0200 Subject: Revive the 'discussions by category' widget on the overview page --- hyperkitty/lib/__init__.py | 24 +++++++--- .../static/hyperkitty/css/hyperkitty-overview.css | 33 ++++++++++++++ .../hyperkitty/css/hyperkitty-threadslist.css | 51 ---------------------- hyperkitty/templates/recent_activities.html | 25 +++++------ hyperkitty/templates/threads/summary_thread.html | 17 +++----- hyperkitty/views/list.py | 21 +++++---- 6 files changed, 80 insertions(+), 91 deletions(-) diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py index 6dbfbea..a25dcd7 100644 --- a/hyperkitty/lib/__init__.py +++ b/hyperkitty/lib/__init__.py @@ -180,17 +180,29 @@ def paginate(objects, page_num, max_page_range=10, paginator=None): return objects -def get_category_widget(request, current_category=None): +def get_category_widget(request=None, current_category=None): + """ + Returns the category form and the applicable category object (or None if no + category is set for this thread). + + If current_category is not provided or None, try to deduce it from the POST + request. + if request is not provided or None, don't return the category form, return + None instead. + """ categories = [ (c.name, c.name.upper()) for c in ThreadCategory.objects.all() ] \ + [("", "no category")] - if request.method == "POST": - category_form = CategoryForm(request.POST) + if request: + if request.method == "POST": + category_form = CategoryForm(request.POST) + else: + category_form = CategoryForm(initial={"category": current_category or ""}) + category_form["category"].field.choices = categories else: - category_form = CategoryForm(initial={"category": current_category or ""}) - category_form["category"].field.choices = categories - if request.method == "POST" and category_form.is_valid(): + category_form = None + if request and request.method == "POST" and category_form.is_valid(): # is_valid() must be called after the choices have been set current_category = category_form.cleaned_data["category"] diff --git a/hyperkitty/static/hyperkitty/css/hyperkitty-overview.css b/hyperkitty/static/hyperkitty/css/hyperkitty-overview.css index 1fef97c..ff43917 100644 --- a/hyperkitty/static/hyperkitty/css/hyperkitty-overview.css +++ b/hyperkitty/static/hyperkitty/css/hyperkitty-overview.css @@ -54,6 +54,17 @@ margin: 1em 0; } +#recent-activities .thread-stats { + margin-left: 3em; +} +#recent-activities .thread-stats ul { + margin: 0; +} +#recent-activities .thread-stats .category { + margin-right: 2em; +} + +/* .category { font-variant: small-caps; font-weight: bold; @@ -77,6 +88,7 @@ .category_entry li { padding-bottom: 10px; } +*/ .maker { color: rgb(102, 102, 102); @@ -98,3 +110,24 @@ .score{ font-weight: bold; } + + +/* Threads by category */ + +#discussion-by-category h4 { + font-size: 105%; + line-height: 105%; + margin: 1.5em 0 0.5em 0; +} +#discussion-by-category h4.first { + margin-top: 0; +} +#discussion-by-category .thread { + margin: 0 0 0 2em; +} +#discussion-by-category .thread-stats { + margin-left: 0; +} +#discussion-by-category .thread .category { + display: none; +} diff --git a/hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css b/hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css index 19dd239..7331f90 100644 --- a/hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css +++ b/hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css @@ -146,54 +146,3 @@ margin-top: 0.5em; } */ - - - -/* - * Thread types - */ - -.type { - font-variant: small-caps; - font-weight: bold; - color: white; - padding: 3px; - -webkit-border-radius: 5px 5px 5px 5px; - -moz-border-radius: 5px 5px 5px 5px; - border-radius: 5px 5px 5px 5px; - vertical-align: top; - width: 110px; - text-align:center; -} - -.type a { - color: white; -} - -.type_question { - background-color: rgb(179, 128, 255); -} - -.type_agenda { - background-color: rgb(42, 127, 255); -} - -.type_todo { - background-color: rgb(200, 171, 55); -} - -.type_dead { - background-color: rgb(0, 0, 0); -} - -.type_announcement { - background-color: rgb(170, 212, 0); -} - -.type_policy { - background-color: rgb(200, 55, 171); -} - -.type_test { - background-color: rgb(200, 171, 55); -} diff --git a/hyperkitty/templates/recent_activities.html b/hyperkitty/templates/recent_activities.html index 3a475e4..64d3db8 100644 --- a/hyperkitty/templates/recent_activities.html +++ b/hyperkitty/templates/recent_activities.html @@ -119,20 +119,17 @@
- {% if threads_per_category %} -
-

Discussion by topic the last 30 days

- {% for category, thread in threads_per_category.items %} -
-

{{category}}

-
    - {% for email in thread %} -
  • - {{email.title}} -
  • - {% endfor %} -
-
+ {% if threads_by_category %} +
+

Discussion by category

+ {% for category, threads in threads_by_category.items %} +

{{ category.name|upper }} +

+ {% for thread in threads %} + {% include "threads/summary_thread.html" %} + {% endfor %} {% endfor %}
{% endif %} diff --git a/hyperkitty/templates/threads/summary_thread.html b/hyperkitty/templates/threads/summary_thread.html index 87a5433..82c9398 100644 --- a/hyperkitty/templates/threads/summary_thread.html +++ b/hyperkitty/templates/threads/summary_thread.html @@ -3,23 +3,16 @@ {% load storm %}
- #{{counter}} + {% if counter %}#{{counter}}{% endif %} {{ thread.subject|strip_subject:mlist }} -
+
    - {% if thread.category_tag %} -
  • - {{thread.category}} -
  • - {% endif %} {% if thread.category %} -
  • - {{thread.category}} -
  • + + {{ thread.category.name|upper }} + {% endif %}
  • {{ thread.participants|length }} diff --git a/hyperkitty/views/list.py b/hyperkitty/views/list.py index 23a668e..50c1aff 100644 --- a/hyperkitty/views/list.py +++ b/hyperkitty/views/list.py @@ -43,7 +43,7 @@ if settings.USE_MOCKUPS: Thread = namedtuple('Thread', [ "thread_id", "subject", "participants", "length", "date_active", - "likes", "dislikes", "likestatus", + "likes", "dislikes", "likestatus", "category", ]) @@ -172,7 +172,9 @@ def overview(request, mlist_fqdn=None): thread_obj.participants, len(thread_obj), thread_obj.date_active.replace(tzinfo=utc), thread_obj.likes, thread_obj.dislikes, - thread_obj.likestatus) + thread_obj.likestatus, + get_category_widget(None, thread_obj.category)[0], + ) # Statistics on how many participants and threads this month participants.update(thread.participants) threads.append(thread) @@ -226,11 +228,14 @@ def overview(request, mlist_fqdn=None): 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 = {} + # Threads by category + threads_by_category = {} + for thread in active_threads: + if not thread.category: + continue + if len(threads_by_category.setdefault(thread.category, [])) > 5: + continue + threads_by_category[thread.category].append(thread) context = { 'mlist' : mlist, @@ -239,7 +244,7 @@ def overview(request, mlist_fqdn=None): 'top_author': authors, 'top_posters': top_posters, 'pop_threads': pop_threads, - 'threads_per_category': threads_per_category, + 'threads_by_category': threads_by_category, 'months_list': get_months(store, mlist.name), 'evolution': evolution, 'days': days, -- cgit