Ejemplo n.º 1
0
  def post(self, action_path):

    # CREATE LEAD
    # ==============
    lead_email = self.request.get("email", None)
    if lead_email:
      logging.info("New Lead Submission: %s" % lead_email)
    else:
      logging.error("No email for lead submission.")
      return 

    action_path = urllib.unquote(action_path)
    account = models.Account.all().filter("action_path =", action_path).get()
    if not account:
      logging.error("Invalid Account Action Path '%s'" % action_path)
      return

    lead_ctx = {}
    for key in self.request.arguments():
      if key not in models.Lead.PROTECTED:
        value = u', '.join([cgi.escape(v) for v in self.request.get_all(key)])
        lead_ctx[str(key)] = value or None
    
    # note: 'email' is required property
    lead = models.Lead(account=account, **lead_ctx)
    if not models.Lead.all().filter("email =", lead_ctx['email']).get():
      lead.put()
    else:
      logging.warning("Email %s already submitted." % lead_ctx['email'])
      return

    # GENERATE ADMIN EMAIL
    # ==============
    account_email_body = template.render(
      TMPL_DIR + "/new_lead_email.txt",
      {'lead_ctx': lead_ctx},
      )
    mail.send_mail(
      sender=mailer.BOT_EMAIL,
      to=account.user.email(),
      subject='Mail Hard Copy to New Lead',
      body=account_email_body,
      )

    # GENERATE USER EMAIL
    # ===================
    mailer.mail_lead(
      account = account,
      to_email = lead.email,
      mail_name='first',
      )
    lead.date_last_auto_ping = datetime.datetime.now()
    lead.num_auto_ping += 1
    lead.put()
    
    self.response.out.write("Thank you for your inquiry.")
Ejemplo n.º 2
0
  def get(self):

    # get cursor if taskqueue
    logging.info("Default Cron Job Activated.")

    q = models.Lead.all()
    q.filter("num_auto_ping <=", MAX_MAIL)
    q.filter("date_closed =", None)

    # WARNING: this should really be in some queue with a transaction
    leads = q.fetch(RESULT_SIZE)
    logging.info("Sending %s emails in cron." % len(leads))
    for lead in leads:
      lead.num_auto_ping += 1
      lead.date_last_auto_ping = datetime.datetime.now()
      logging.info("Email #%s to %s." % (lead.num_auto_ping, lead.email))
      mailer.mail_lead(
        account = lead.account,
        to_email = lead.email,
        mail_name = 'auto',
        )
    db.put(leads)