Commit a9bdea95041e2062f9a83fa5a9ba7eeffc769db9
Exists in
master
and in
39 other branches
Merge branch 'master' of github.com:TracyWebTech/colab
Showing
6 changed files
with
46 additions
and
7 deletions
Show diff stats
TODO.rst
| 1 | 1 | TODO |
| 2 | 2 | ----- |
| 3 | 3 | |
| 4 | +Gestão de listas | |
| 5 | +================ | |
| 6 | +* Sincronizar informações de membership do mailman com o django | |
| 7 | +* Usar informações do banco de dados local ao inves de fazer queries constantes | |
| 8 | + | |
| 9 | +Updates | |
| 10 | +====== | |
| 11 | +* Update Django to 1.7 and remove south dependency | |
| 12 | + | |
| 13 | +Async | |
| 14 | +===== | |
| 15 | +* Usar celery para tornar tasks como envio de emails asincronas. | |
| 16 | + | |
| 17 | + | |
| 4 | 18 | Envio de emails |
| 5 | 19 | =============== |
| 6 | 20 | * Não perder o email em caso de falha de envio. Exibir o erro mas trazer a mensagem de volta para o usuário |
| 21 | +* Permitir apenas que usuarios pertencentes a lista enviem mensagens | |
| 22 | + | |
| 7 | 23 | |
| 8 | 24 | Planet |
| 9 | 25 | ====== | ... | ... |
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 | ... | ... |
src/super_archives/templates/superarchives/includes/message.html
| ... | ... | @@ -53,7 +53,7 @@ |
| 53 | 53 | <form method="POST"> |
| 54 | 54 | {% csrf_token %} |
| 55 | 55 | <p> |
| 56 | - <textarea placeholder="{% trans 'Send a message' %}" rows="5" class="form-control"></textarea> | |
| 56 | + <textarea name="emailbody" placeholder="{% trans 'Send a message' %}" rows="5" class="form-control"></textarea> | |
| 57 | 57 | </p> |
| 58 | 58 | <div class="col-lg-9 col-md-8 col-sm-8 col-xs-7"> |
| 59 | 59 | <p class="quiet">{% trans "After sending a message it will take few minutes before it shows up in here. Why don't you grab a coffee?" %}</p> | ... | ... |
src/super_archives/views.py
| ... | ... | @@ -79,10 +79,10 @@ def thread_post(request, mailinglist, thread_token): |
| 79 | 79 | raise http.Http404 |
| 80 | 80 | |
| 81 | 81 | data = {} |
| 82 | - data['email_from'] = '{} <{}>'.format(request.user.get_full_name(), | |
| 82 | + data['from'] = '{} <{}>'.format(request.user.get_full_name(), | |
| 83 | 83 | request.user.email) |
| 84 | 84 | data['subject'] = thread.message_set.first().subject_clean |
| 85 | - data['body'] = request.POST.get('body', '').strip() | |
| 85 | + data['body'] = request.POST.get('emailbody', '').strip() | |
| 86 | 86 | |
| 87 | 87 | url = urlparse.urljoin(settings.MAILMAN_API_URL, mailinglist + '/sendmail') |
| 88 | 88 | |
| ... | ... | @@ -103,10 +103,13 @@ def thread_post(request, mailinglist, thread_token): |
| 103 | 103 | "in the meanwhile.")) |
| 104 | 104 | else: |
| 105 | 105 | if not error_msg: |
| 106 | - if resp and resp.status_code == 400: | |
| 107 | - error_msg = _('You cannot send an empty email') | |
| 106 | + if resp is not None: | |
| 107 | + if resp.status_code == 400: | |
| 108 | + error_msg = _('You cannot send an empty email') | |
| 109 | + elif resp.status_code == 404: | |
| 110 | + error_msg = _('Mailing list does not exist') | |
| 108 | 111 | else: |
| 109 | - error_msg = _('Unkown error trying to connect to Mailman API') | |
| 112 | + error_msg = _('Unkown error trying to connect to Mailman API') | |
| 110 | 113 | messages.error(request, error_msg) |
| 111 | 114 | |
| 112 | 115 | return thread_get(request, mailinglist, thread_token) | ... | ... |