def get(self): '''no arguments''' today = datetime.today() query = Picture.all().filter('uploaded >', datetime(today.year, today.month, today.day, 0, 0) ) if query.count(): logging.debug('New pictures for newsletter: %s' % query.count()) pictures_today = list(query) query = Subscription.all().filter('active =', True) if query.count(): logging.info('Sending newsletter to %s recipients' % query.count()) recipients = list(query) today = datetime.today() message = mail.EmailMessage() message.sender = '%s (Photoblog) <%s>' % ( conf.mail_from_name, conf.mail_from_address ) message.to = conf.mail_from_address message.bcc = [r.email for r in recipients] message.subject = conf.mail_newsletter_subject message.body = render('newsletter.txt', {'pics':pictures_today}) message.send()
def get(self, key): '''check if the given key is valid''' query = Subscription.all().filter('validation_key =', key) if not query.count(): logging.debug('Subscription failed with key %s' % key) resp = render('abo_subscribe_wrong_key.html') else: subscription = query.get() subscription.active = True subscription.put() logging.info('New subscription: %s' % subscription.email) resp = render('abo_subscribe_complete.html') self.response.out.write(resp)
def get(self, address): '''unsubscribe the given address @param address: urllib.quote_plus() has been used on it''' address = unquote_plus(address) query = Subscription.all().filter('email =', address) if not query.count() == 1: logging.debug('Failed unsubscription: %s' % address) resp = render('abo_unsubscribe_failed.html') else: subscription = query.get() subscription.active = False subscription.put() logging.info('Unsubscribed %s' % address) resp = render('abo_unsubscribe_successful.html') self.response.out.write(resp)
def post(self): '''email address has been entered validate and send the confirmation mail''' to_address_1 = self.request.get('to_1') to_address_2 = self.request.get('to_2') if not to_address_1 == to_address_2: self.redirect('/abo/subscribe?error=mails') else: key = str(uuid().int) logging.error('%s' % key) confirmation_link = '%s/abo/confirm/%s' % (conf.host, key) mail_content = render('subscribe_mail.txt', {'link':confirmation_link, 'host':conf.host, 'sender_mail':conf.mail_from_address, 'sender_name':conf.mail_from_name } ) query = Subscription.all().filter('email =', to_address_1) if query.count(): # email has been submitted before prev_mail = query.get() if prev_mail.active: logging.debug('Repeat subscription: %s' % prev_mail.email) self.redirect('/abo/success') else: logging.debug('New subscription key for %s' % prev_mail.email) prev_mail.delete() subscription = Subscription(email=to_address_1, validation_key=key, active=False) subscription.put() logging.info('New subscription: %s' % subscription.email) logging.debug('Sending confirmation mail to %s' % to_address_1) mail.send_mail( sender='%s (Photoblog) <%s>' % (conf.mail_from_name, conf.mail_from_address ), to=to_address_1, subject=conf.mail_confirmation_subject, body = mail_content ) self.redirect('/abo/success')