Esempio n. 1
0
 def handle(self, *args, **options):
     self.options = options
     testing = True if 1 < len(args) else False
     sys.stdout = Unbuffered(sys.stdout)
     issue_number = args[0]
     context = read_newsletter_context(issue_number)
     # context['imgpath_prefix'] = 'cid:'
     newsletter_context_vars(context, issue_number)
     # subject = Header((u'[試寄] ' if testing else '') + context['params']['title'], 'utf-8')
     from_email = '"Mozilla Taiwan" <*****@*****.**>'
     text_content = render_to_string('newsletter/%s/mail.txt' % issue_number, context)
     html_content = render_to_string('newsletter/%s/index.html' % issue_number, context)
     mail_content = premailer.transform(html_content)
     soup = BeautifulSoup(html_content)
     subject = Header((u'[測試] ' if testing else '') + soup.title.string, 'utf-8')
     # headers = {'Reply-To': '*****@*****.**'}
     headers = {}
     # charset = 'utf-8'
     # image_path = 'bedrock/newsletter/templates/newsletter/%s/images/' % issue_number
     # images = [f for f in listdir(image_path) if not f.startswith('.') and isfile(join(image_path, f))]
     if not testing:
         with open('subscriptions.txt') as file:
             subscriptions = file.readlines()
             for subscription in subscriptions:
                 self.send_mail(subject, headers, from_email, (subscription.rstrip(), ),
                                text_content, mail_content, issue_number)
                 sleep(10)
     elif args[1] == 'presend':
         for mail_address in NEWSLETTER_PRESEND_LIST:
             self.send_mail(subject, headers, from_email, (mail_address, ), text_content, mail_content, issue_number)
             sleep(10)
     else:
         self.send_mail(subject, headers, from_email, (args[1], ), text_content, mail_content, issue_number)
Esempio n. 2
0
def issue(request, issue_number=None, path=None):
    if not path or path == 'index.html':
        context = read_newsletter_context(issue_number, False)
        newsletter_context_vars(context, issue_number)
        return l10n_utils.render(request,
                                 'newsletter/%s/index.html' % issue_number,
                                 context)
    elif path == 'mail.txt':
        context = read_newsletter_context(issue_number, False)
        newsletter_context_vars(context, issue_number)
        response = render_to_string('newsletter/%s/mail.txt' % issue_number, context)
        return HttpResponse(response, content_type='text/plain')
    elif path == 'email.gif':
        track_page('/newsletter/%s/email' % issue_number)
        response = HttpResponse('', content_type='image/gif')
        response['Pragma'] = 'no-cache'
        response['Cache-Control'] = 'private, no-cache, no-cache=Set-Cookie, proxy-revalidate'
        response['Expires'] = 'Wed, 17 Sep 1975 21:32:10 GMT'
        response.write('R0lGODlhAQABAID/AP///wAAACwAAAAAAQABAAACAkQBADs='.decode('base64'))
        return response
    else:
        return serve(request, path, 'bedrock/newsletter/templates/newsletter/%s' % issue_number)