Exemplo n.º 1
0
 def post(self):
     settings = Settings.get_by_key_name('settings')
     for invites, output in helpers.invite_iterator():
         name = invites[0].name
         to_email = '{} <{}>'.format(name, invites[0].email)
         body = const.EMAIL_TEMPLATE.format(student=name, body=output)
         try:
             mail.send_mail(settings.admin_email, to_email,
                            const.EMAIL_SUBJECT, body)
             now = datetime.datetime.now()
             for invite in invites:
                 invite.email_sent = now
                 invite.put()
         except apiproxy_errors.OverQuotaError:
             taskqueue.add(url='/admin/email', countdown=60)
             return self.response.set_status(200)
Exemplo n.º 2
0
 def download_email_json(self, limit=100):
     data = {'template': const.EMAIL_TEMPLATE, 'emails': []}
     now = datetime.datetime.now()
     for invites, output in helpers.invite_iterator(limit=100):
         name = invites[0].name
         email = '{} <{}>'.format(name, invites[0].email)
         cur = {'name': invites[0].name, 'email': email, 'output': output}
         data['emails'].append(cur)
         for invite in invites:
             invite.email_sent = now
             invite.put()
     if data['emails']:
         cd = 'attachement; filename="emails.json"'
         self.response.headers['Content-Type'] = 'text/plain'
         self.response.headers['Content-Disposition'] = cd
         self.response.out.write(json.dumps(data))
     else:
         self.get(warnings=('No more emails to send.',))