Commit a7e544d050ec2c4ae90a2215bbb8793f88561a5a
1 parent
345b2731
Exists in
master
and in
28 other branches
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
... | ... | @@ -145,8 +145,12 @@ class ManageUserSubscriptionsView(UserProfileBaseMixin, DetailView): |
145 | 145 | for email in user.emails.values_list('address', flat=True): |
146 | 146 | lists = self.request.POST.getlist(email) |
147 | 147 | info_messages = user.update_subscription(email, lists) |
148 | - for message in info_messages: | |
149 | - messages.success(request, _(message)) | |
148 | + for operation_status, message in info_messages: | |
149 | + if operation_status: | |
150 | + messages.success(request, _(message)) | |
151 | + else: | |
152 | + messages.error(request, _(message)) | |
153 | + | |
150 | 154 | |
151 | 155 | return redirect('user_profile', username=user.username) |
152 | 156 | ... | ... |