diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-07-12 11:13:54 +0200 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-07-12 11:13:54 +0200 |
commit | 579bd91b14f8d2926f64aa6032b41145f90b46fe (patch) | |
tree | 4fb79092d0a278d2625a8807fdda06a5717b01be | |
parent | 65146a1229604b059e1d637761e9096068a05ab3 (diff) | |
download | hyperkitty-579bd91b14f8d2926f64aa6032b41145f90b46fe.tar.gz hyperkitty-579bd91b14f8d2926f64aa6032b41145f90b46fe.tar.xz hyperkitty-579bd91b14f8d2926f64aa6032b41145f90b46fe.zip |
Revive the 'discussions by category' widget on the overview page
-rw-r--r-- | hyperkitty/lib/__init__.py | 24 | ||||
-rw-r--r-- | hyperkitty/static/hyperkitty/css/hyperkitty-overview.css | 33 | ||||
-rw-r--r-- | hyperkitty/static/hyperkitty/css/hyperkitty-threadslist.css | 51 | ||||
-rw-r--r-- | hyperkitty/templates/recent_activities.html | 25 | ||||
-rw-r--r-- | hyperkitty/templates/threads/summary_thread.html | 17 | ||||
-rw-r--r-- | 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 @@ <div class="span6"> - {% if threads_per_category %} - <section id="discussion-by-topic" class="widget"> - <h3>Discussion by topic the last 30 days</h3> - {% for category, thread in threads_per_category.items %} - <div> - <h3 class="category type_{{category}}"> {{category}} </h3> - <ul class="category_entry"> - {% for email in thread %} - <li> - {{email.title}} - </li> - {% endfor %} - </ul> - </div> + {% if threads_by_category %} + <section id="discussion-by-category" class="widget"> + <h3>Discussion by category</h3> + {% for category, threads in threads_by_category.items %} + <h4 class="label{% if forloop.first %} first{% endif %}" + style="background-color:{{category.color}}" + >{{ category.name|upper }} + </h4> + {% for thread in threads %} + {% include "threads/summary_thread.html" %} + {% endfor %} {% endfor %} </section> {% 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 %} <div class="thread"> - <span class="thread-id">#{{counter}}</span> + {% if counter %}<span class="thread-id">#{{counter}}</span>{% endif %} <span class="thread-title"><a name="{{thread.thread_id}}" href="{% url 'thread' threadid=thread.thread_id mlist_fqdn=mlist.name %}" >{{ thread.subject|strip_subject:mlist }}</a></span> - <div class="thread_stats"> + <div class="thread-stats"> <ul class="inline-block"> - {% if thread.category_tag %} - <li class="type type_{{thread.category_tag}}"> - <a href="{% url 'search_tag' mlist_fqdn=mlist.name tag=thread.category_tag %}" - >{{thread.category}}</a> - </li> - {% endif %} {% if thread.category %} - <li class="type type_{{thread.category|lower}}"> - <a href="{% url 'search_tag' mlist_fqdn=mlist.name tag=thread.category|lower %}" - >{{thread.category}}</a> - </li> + <span class="label category" style="background-color:{{thread.category.color}}"> + {{ thread.category.name|upper }} + </span> {% endif %} <li class="participant"> {{ 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, |