diff --git a/src/accounts/models.py b/src/accounts/models.py index 31d4524..fa4789f 100644 --- a/src/accounts/models.py +++ b/src/accounts/models.py @@ -1,7 +1,9 @@ import urlparse +import requests from django.db import models +from django.conf import settings from django.contrib.auth.models import AbstractUser from django.core.urlresolvers import reverse @@ -24,6 +26,15 @@ class User(AbstractUser): def facebook_link(self): return urlparse.urljoin('https://www.facebook.com', self.facebook) + def mailinglists(self): + list_set = set() + for email in self.emails.all(): + lists = requests.get(settings.MAILMAN_API_URL, timeout=1, + params={'address': email.address}) + list_set.update(lists.json()) + return tuple(list_set) + + # We need to have `email` field set as unique but Django does not # support field overriding (at least not until 1.6). # The following workaroud allows to change email field to unique diff --git a/src/accounts/templates/accounts/user_detail.html b/src/accounts/templates/accounts/user_detail.html index 22a55df..f98cc97 100644 --- a/src/accounts/templates/accounts/user_detail.html +++ b/src/accounts/templates/accounts/user_detail.html @@ -60,6 +60,15 @@ {% endif %} {% endif %} + + {% if user_.mailinglists %} + {% trans 'Subscribes: ' %} + {% for list in user_.mailinglists %} + {{ list }} + {% endfor %} + {% endif %} + +
diff --git a/src/accounts/views.py b/src/accounts/views.py index 18fea73..2135498 100644 --- a/src/accounts/views.py +++ b/src/accounts/views.py @@ -8,11 +8,11 @@ from collections import OrderedDict from django.contrib import messages from django.db.models import Count from django.contrib.auth import get_user_model -from django.views.generic import DetailView, UpdateView from django.utils.translation import ugettext as _ from django.shortcuts import render, redirect from django.core.urlresolvers import reverse from django.core.exceptions import PermissionDenied +from django.views.generic import DetailView, UpdateView from haystack.query import SearchQuerySet -- libgit2 0.21.2