Commit 4aebe5e144bff62e3e1af7865f605c5b07f16da7
1 parent
e2f67731
Exists in
master
and in
39 other branches
Listing membership on user profile
Showing
3 changed files
with
21 additions
and
1 deletions
Show diff stats
src/accounts/models.py
1 | 1 | |
2 | 2 | import urlparse |
3 | +import requests | |
3 | 4 | |
4 | 5 | from django.db import models |
6 | +from django.conf import settings | |
5 | 7 | from django.contrib.auth.models import AbstractUser |
6 | 8 | from django.core.urlresolvers import reverse |
7 | 9 | |
... | ... | @@ -24,6 +26,15 @@ class User(AbstractUser): |
24 | 26 | def facebook_link(self): |
25 | 27 | return urlparse.urljoin('https://www.facebook.com', self.facebook) |
26 | 28 | |
29 | + def mailinglists(self): | |
30 | + list_set = set() | |
31 | + for email in self.emails.all(): | |
32 | + lists = requests.get(settings.MAILMAN_API_URL, timeout=1, | |
33 | + params={'address': email.address}) | |
34 | + list_set.update(lists.json()) | |
35 | + return tuple(list_set) | |
36 | + | |
37 | + | |
27 | 38 | # We need to have `email` field set as unique but Django does not |
28 | 39 | # support field overriding (at least not until 1.6). |
29 | 40 | # The following workaroud allows to change email field to unique | ... | ... |
src/accounts/templates/accounts/user_detail.html
... | ... | @@ -60,6 +60,15 @@ |
60 | 60 | {% endif %} |
61 | 61 | {% endif %} |
62 | 62 | </ul> |
63 | + | |
64 | + {% if user_.mailinglists %} | |
65 | + <b>{% trans 'Subscribes: ' %}</b> | |
66 | + {% for list in user_.mailinglists %} | |
67 | + <span class="label label-primary">{{ list }}</span> | |
68 | + {% endfor %} | |
69 | + {% endif %} | |
70 | + | |
71 | + <div class="divider"></div> | |
63 | 72 | </div> |
64 | 73 | |
65 | 74 | <div class="col-lg-4 col-md-4 col-sm-8"> | ... | ... |
src/accounts/views.py
... | ... | @@ -8,11 +8,11 @@ from collections import OrderedDict |
8 | 8 | from django.contrib import messages |
9 | 9 | from django.db.models import Count |
10 | 10 | from django.contrib.auth import get_user_model |
11 | -from django.views.generic import DetailView, UpdateView | |
12 | 11 | from django.utils.translation import ugettext as _ |
13 | 12 | from django.shortcuts import render, redirect |
14 | 13 | from django.core.urlresolvers import reverse |
15 | 14 | from django.core.exceptions import PermissionDenied |
15 | +from django.views.generic import DetailView, UpdateView | |
16 | 16 | |
17 | 17 | from haystack.query import SearchQuerySet |
18 | 18 | ... | ... |