Commit 11f37eda97d4b05796fb82d01be1581b26daa761
1 parent
c57dd273
Added informative messages for subscription and unsubscription on email lists
Signed-off-by: Charles Oliveira <18oliveira.charles@gmail.com> Signed-off-by: Matheus Fernandes <matheus.souza.fernandes@gmail.com>
Showing
2 changed files
with
15 additions
and
15 deletions
Show diff stats
colab/accounts/utils/mailman.py
... | ... | @@ -22,39 +22,35 @@ def subscribe(listname, address): |
22 | 22 | url = get_url(listname) |
23 | 23 | try: |
24 | 24 | result = requests.put(url, timeout=TIMEOUT, data={'address': address}) |
25 | - if result.status_code is not 200: | |
26 | - return False, '%s: %s' % (listname, result.json()) | |
25 | + return True, '%s: %s' % (listname, result.json()) | |
27 | 26 | except: |
28 | 27 | LOGGER.exception('Unable to subscribe user') |
29 | - return False, 'Unable to subscribe user' | |
30 | - return True, 'Success' | |
28 | + return False, 'Error: Unable to subscribe user' | |
31 | 29 | |
32 | 30 | |
33 | 31 | def unsubscribe(listname, address): |
34 | 32 | url = get_url(listname) |
35 | 33 | try: |
36 | - requests.delete(url, timeout=TIMEOUT, data={'address': address}) | |
34 | + result = requests.delete(url, timeout=TIMEOUT, data={'address': address}) | |
35 | + return True, '%s: %s' % (listname, result.json()) | |
37 | 36 | except: |
38 | 37 | LOGGER.exception('Unable to unsubscribe user') |
39 | - return False | |
40 | - return True | |
38 | + return False, 'Error: Unable to unsubscribe user' | |
41 | 39 | |
42 | 40 | |
43 | 41 | def update_subscription(address, lists): |
44 | 42 | current_lists = mailing_lists(address=address) |
45 | - error_messages = [] | |
43 | + info_messages = [] | |
46 | 44 | |
47 | 45 | for maillist in current_lists: |
48 | 46 | if maillist not in lists: |
49 | - unsubscribe(maillist, address) | |
47 | + info_messages.append(unsubscribe(maillist, address)) | |
50 | 48 | |
51 | 49 | for maillist in lists: |
52 | 50 | if maillist not in current_lists: |
53 | - subscribed, message = subscribe(maillist, address) | |
54 | - if not subscribed: | |
55 | - error_messages.append(message) | |
51 | + info_messages.append(subscribe(maillist, address)) | |
56 | 52 | |
57 | - return error_messages | |
53 | + return info_messages | |
58 | 54 | |
59 | 55 | |
60 | 56 | def mailing_lists(**kwargs): | ... | ... |
colab/accounts/views.py
... | ... | @@ -140,8 +140,12 @@ class ManageUserSubscriptionsView(UserProfileBaseMixin, DetailView): |
140 | 140 | for email in user.emails.values_list('address', flat=True): |
141 | 141 | lists = self.request.POST.getlist(email) |
142 | 142 | info_messages = user.update_subscription(email, lists) |
143 | - for message in info_messages: | |
144 | - messages.success(request, _(message)) | |
143 | + for operation_status, message in info_messages: | |
144 | + if operation_status: | |
145 | + messages.success(request, _(message)) | |
146 | + else: | |
147 | + messages.error(request, _(message)) | |
148 | + | |
145 | 149 | |
146 | 150 | return redirect('user_profile', username=user.username) |
147 | 151 | ... | ... |