Projet

Général

Profil

0001-announces-send-command-10805.patch

Serghei Mihai, 06 mai 2016 17:36

Télécharger (3,05 ko)

Voir les différences:

Subject: [PATCH] announces send command (#10805)

 corbo/models.py   | 24 ++++++++++++++++++++++++
 corbo/settings.py |  3 +++
 requirements.txt  |  1 +
 setup.py          |  1 +
 4 files changed, 29 insertions(+)
corbo/models.py
1
from datetime import datetime
2
import logging
3
from html2text import HTML2Text
4

  
1 5
from django.utils import timezone
2 6
from django.conf import settings
3 7
from django.db import models
8
from django.core.mail import send_mail
4 9
from django.utils.translation import ugettext_lazy as _
5 10

  
6 11
from ckeditor.fields import RichTextField
......
10 15
    ('homepage', _('Homepage'))
11 16
)
12 17

  
18
logger = logging.getLogger(__name__)
19

  
13 20
class Category(models.Model):
14 21
    name = models.CharField(max_length=64, blank=False, null=False)
15 22
    ctime = models.DateTimeField(auto_now_add=True)
......
62 69
                id=self.announce.id, time=self.deliver_time)
63 70
        return u'announce {id} to deliver'.format(id=self.announce.id)
64 71

  
72
    def send(self):
73
        subscriptions = self.announce.category.subscription_set.all()
74
        total_sent = 0
75
        destinations = [s.identifier for s in subscriptions]
76
        handler = HTML2Text()
77
        subject = self.announce.title
78
        text_message = handler.handle(self.announce.text)
79
        for destination in destinations:
80
            if send_mail(subject, text_message,
81
                      settings.CORBO_DEFAULT_FROM_EMAIL,
82
                      [destination], html_message=self.announce.text):
83
                total_sent += 1
84
        logger.debug('announce "%s" delivered to %s destinations', subject, total_sent)
85
        self.result = total_sent
86
        self.deliver_time = timezone.now()
87
        self.save()
88

  
65 89
    class Meta:
66 90
        verbose_name = _('sent')
67 91
        ordering = ('-deliver_time',)
corbo/settings.py
104 104
RSS_LINK = ''
105 105
RSS_LINK_TEMPLATE = '/#announce{0}'
106 106

  
107
# default mass emails expeditor
108
CORBO_DEFAULT_FROM_EMAIL = 'webmaster@localhost'
109

  
107 110
# django-mellon settings
108 111
MELLON_ATTRIBUTE_MAPPING = {
109 112
    'username': '{attributes[username][0]}',
requirements.txt
1 1
Django>=1.7, <1.8
2 2
django-ckeditor<4.5.3
3 3
djangorestframework
4
html2text
4 5
-e git+http://repos.entrouvert.org/gadjo.git/#egg=gadjo
setup.py
96 96
    install_requires=['django>=1.7, <1.8',
97 97
        'django-ckeditor<4.5.3',
98 98
        'djangorestframework',
99
        'html2text',
99 100
        'gadjo'
100 101
        ],
101 102
    zip_safe=False,
102
-