Commit a2b437aa6f6b449c3ae438bf57132729e89f5bdf

Authored by Carlos Coêlho
Committed by Charles Oliveira
1 parent 4b043b7a

Updated mailing_lists to mailman-api v2

Signed-off-by: Carlos Oliveira <carlospecter@gmail.com>
colab/accounts/forms.py
... ... @@ -141,8 +141,9 @@ class UserUpdateForm(UserForm):
141 141  
142 142 class ListsForm(forms.Form):
143 143 LISTS_NAMES = ((
144   - listname, u'{} ({})'.format(listname, description)
145   - ) for listname, description in mailman.all_lists(description=True))
  144 + mlist.get('listname'), u'{} ({})'.format(mlist.get('listname'),
  145 + mlist.get('description'))
  146 + ) for mlist in mailman.all_lists())
146 147  
147 148 lists = forms.MultipleChoiceField(label=_(u'Mailing lists'),
148 149 required=False,
... ...
colab/accounts/templates/accounts/user_detail.html
... ... @@ -84,7 +84,6 @@
84 84 {% endif %}
85 85 {% endif %}
86 86 </ul>
87   -
88 87 {% if user_.mailinglists %}
89 88 <b>{% trans 'Groups: ' %}</b>
90 89 {% for list in user_.mailinglists %}
... ...
colab/accounts/utils/mailman.py
... ... @@ -73,9 +73,10 @@ def update_subscription(address, lists):
73 73  
74 74 def mailing_lists(**kwargs):
75 75 url = get_url()
  76 + path = 'lists/'
76 77  
77 78 try:
78   - lists = requests.get(url, timeout=TIMEOUT, params=kwargs)
  79 + lists = requests.get(url + path, timeout=TIMEOUT, params=kwargs)
79 80 except:
80 81 LOGGER.exception('Unable to list mailing lists')
81 82 return []
... ... @@ -98,7 +99,8 @@ def user_lists(user):
98 99 list_set = set()
99 100  
100 101 for email in user.emails.values_list('address', flat=True):
101   - list_set.update(mailing_lists(address=email))
  102 + mlists = mailing_lists(address=email)
  103 + list_set.update(mlist.get('listname') for mlist in mlists)
102 104  
103 105 return tuple(list_set)
104 106  
... ...
colab/accounts/views.py
... ... @@ -163,13 +163,14 @@ class ManageUserSubscriptionsView(UserProfileBaseMixin, DetailView):
163 163 for email in emails:
164 164 lists = []
165 165 lists_for_address = mailman.mailing_lists(address=email)
166   - for listname, description in all_lists:
167   - if listname in lists_for_address:
  166 + for mlist in all_lists:
  167 + if mlist.get('listname') in lists_for_address:
168 168 checked = True
169 169 else:
170 170 checked = False
171 171 lists.append((
172   - {'listname': listname, 'description': description},
  172 + {'listname': mlist.get('listname'),
  173 + 'description': mlist.get('description')},
173 174 checked
174 175 ))
175 176  
... ...