From 3759498f4ecf5cae88eecf197b1f2cf075bc0565 Mon Sep 17 00:00:00 2001 From: Aurélien Bompard Date: Fri, 17 May 2013 16:00:14 +0200 Subject: Load the lists descriptions from Mailman dynamically --- hyperkitty/static/js/hyperkitty.js | 32 ++++++++++++++++++++++++++++++++ hyperkitty/templates/index.html | 26 +++++++++++++++----------- hyperkitty/urls.py | 1 + hyperkitty/views/pages.py | 28 ++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 11 deletions(-) diff --git a/hyperkitty/static/js/hyperkitty.js b/hyperkitty/static/js/hyperkitty.js index a06aa79..62bacf4 100644 --- a/hyperkitty/static/js/hyperkitty.js +++ b/hyperkitty/static/js/hyperkitty.js @@ -377,6 +377,38 @@ function update_thread_replies(url) { } +/* + * List descriptions on the front page + */ +function update_list_properties(url) { + $.ajax({ + dataType: "json", + url: url, + success: function(data) { + $(".all-lists .mailinglist").each(function() { + var name = $(this).find(".list-address").text(); + if (!data[name]) { + return; + } + if (data[name]["display_name"]) { + $(this).find(".list-name").text(data[name]["display_name"]); + } + if (data[name]["description"]) { + $(this).find(".list-description") + .text(data[name]["description"]); + } + }); + }, + error: function(jqXHR, textStatus, errorThrown) { + //alert(jqXHR.responseText); + }, + complete: function(jqXHR, textStatus) { + $(".all-lists .mailinglist img.ajaxloader").remove(); + } + }); +} + + /* * Misc. */ diff --git a/hyperkitty/templates/index.html b/hyperkitty/templates/index.html index aed1abb..2efe320 100644 --- a/hyperkitty/templates/index.html +++ b/hyperkitty/templates/index.html @@ -16,18 +16,11 @@
{% for mlist in all_lists %} {% if forloop.counter|divisibleby:"4" %} @@ -45,4 +38,15 @@ {% endblock %} +{% block additionaljs %} + + + +{% endblock %} + {# vim: set noet: #} diff --git a/hyperkitty/urls.py b/hyperkitty/urls.py index 9199de0..336d84c 100644 --- a/hyperkitty/urls.py +++ b/hyperkitty/urls.py @@ -41,6 +41,7 @@ urlpatterns = patterns('hyperkitty.views', # Index url(r'^/$', 'pages.index', name='index'), url(r'^$', 'pages.index', name='root'), + url(r'^lists-properties$', 'pages.list_properties', name='list_properties'), # Account #url(r'^accounts/login/$', login_view, {'template_name': 'login.html', 'SSL': True}, name='user_login'), diff --git a/hyperkitty/views/pages.py b/hyperkitty/views/pages.py index d3f2b0b..6ec7f7b 100644 --- a/hyperkitty/views/pages.py +++ b/hyperkitty/views/pages.py @@ -17,10 +17,18 @@ # HyperKitty. If not, see . # # Author: Aamir Khan +# Author: Aurelien Bompard # + +import urllib2 + +import django.utils.simplejson as json + from django.shortcuts import render from django.conf import settings +from django.http import HttpResponse +from mailmanclient import Client from hyperkitty.lib import get_store from forms import SearchForm @@ -35,3 +43,23 @@ def index(request): 'search_form': SearchForm(auto_id=False), } return render(request, "index.html", context) + + +def list_properties(request): + """Get JSON encoded list properties""" + store = get_store(request) + lists = store.get_lists() + client = Client('%s/3.0' % settings.MAILMAN_REST_SERVER, + settings.MAILMAN_API_USER, settings.MAILMAN_API_PASS) + props = {} + for ml in lists: + try: + mm_list = client.get_list(ml.name) + except urllib2.HTTPError: + continue + props[ml.name] = { + "display_name": mm_list.display_name, + "description": mm_list.settings["description"], + } + return HttpResponse(json.dumps(props), + mimetype='application/javascript') -- cgit