23 |
23 |
('homepage', _('Homepage'))
|
24 |
24 |
)
|
25 |
25 |
|
|
26 |
UNSUBSCRIBE_LINK_PLACEHOLDER = '##UNSUBSCRIBE_LINK_PLACEHOLDER##'
|
|
27 |
|
26 |
28 |
logger = logging.getLogger(__name__)
|
27 |
29 |
|
28 |
30 |
|
... | ... | |
96 |
98 |
total_sent = 0
|
97 |
99 |
handler = HTML2Text()
|
98 |
100 |
template = loader.get_template('corbo/announce.html')
|
99 |
|
m = Message(subject=self.announce.title, mail_from=settings.CORBO_DEFAULT_FROM_EMAIL)
|
|
101 |
message = Message(subject=self.announce.title, mail_from=settings.CORBO_DEFAULT_FROM_EMAIL,
|
|
102 |
html=template.render(Context({'content': self.announce.text,
|
|
103 |
'unsubscribe_link_placeholder': UNSUBSCRIBE_LINK_PLACEHOLDER})))
|
100 |
104 |
html_tree = HTMLTree(self.announce.text)
|
101 |
105 |
storage = DefaultStorage()
|
102 |
106 |
for img in html_tree.xpath('//img/@src'):
|
103 |
107 |
img_path = img.lstrip(storage.base_url)
|
104 |
|
m.attach(filename=transform_image_src(img), data=storage.open(img_path))
|
|
108 |
message.attach(filename=transform_image_src(img), data=storage.open(img_path))
|
|
109 |
|
|
110 |
message.transformer.apply_to_images(func=transform_image_src)
|
|
111 |
# perform transformations in message html, like inline css parsing
|
|
112 |
message.transformer.load_and_transform()
|
|
113 |
# mark all attached images as inline
|
|
114 |
message.transformer.make_all_images_inline()
|
|
115 |
message.transformer.save()
|
105 |
116 |
for s in subscriptions:
|
106 |
117 |
if not s.identifier:
|
107 |
118 |
continue
|
... | ... | |
109 |
120 |
'identifier': s.identifier})
|
110 |
121 |
unsubscribe_link = urlparse.urljoin(settings.SITE_BASE_URL, reverse('unsubscribe',
|
111 |
122 |
kwargs={'unsubscription_token': unsubscribe_token}))
|
112 |
|
message = template.render(Context({'unsubscribe_link': unsubscribe_link,
|
113 |
|
'content': self.announce.text}))
|
114 |
|
m.html = message
|
115 |
|
# transform all images sources in order to use image names only
|
116 |
|
m.transformer.apply_to_images(func=transform_image_src)
|
117 |
|
# perform transformations in message html, like inline css parsing
|
118 |
|
m.transformer.load_and_transform(load_images=False)
|
119 |
|
# mark all attached images as inline
|
120 |
|
m.transformer.make_all_images_inline()
|
121 |
|
m.transformer.save()
|
|
123 |
message.html = message.html.replace(UNSUBSCRIBE_LINK_PLACEHOLDER, unsubscribe_link)
|
122 |
124 |
handler.body_width = 0
|
123 |
|
m.text = handler.handle(m.html)
|
124 |
|
sent = m.send(to=s.identifier)
|
|
125 |
message.text = handler.handle(message.html)
|
|
126 |
sent = message.send(to=s.identifier)
|
125 |
127 |
if sent:
|
126 |
128 |
total_sent += 1
|
127 |
129 |
logger.info('Announce "%s" sent to %s', self.announce.title, s.identifier)
|