def sendBadgeMail(from_email, from_name, contribution, mentor, admin, reply_to, merge, to_name, twitter): sendmail = False contributed_hours = contribution.get("new_total") badge_category = "" badge_name = "" contributors_first_name = mentor.first_name program = Program.all().filter("user = "******" " + mentor.last_name subject = "[MSF] %s just earned a new badge!" % (to_name_mentor) mentor_subject = "[MSF] You've earned a new badge!" tags = "New badge earned" if contributed_hours >= 250 and program.grand_master == None: sendmail = True badge_category = "GRAND MASTER" badge_name = "Badge250" program.scout_master = True program.sensei = True program.captain = True program.general = True program.grand_master = True program.put() elif contributed_hours >= 100 and program.general == None: sendmail = True badge_category = "GENERAL" badge_name = "Badge100" program.scout_master = True program.sensei = True program.captain = True program.general = True program.put() elif contributed_hours >= 50 and program.captain == None: sendmail = True badge_category = "CAPTAIN" badge_name = "Badge50" program.scout_master = True program.sensei = True program.captain = True program.put() elif contributed_hours >= 25 and program.sensei == None: sendmail = True badge_name = "Badge25" badge_category = "SENSEI" program.scout_master = True program.sensei = True program.put() elif contributed_hours >= 10 and program.scout_master == None: sendmail = True badge_name = "Badge10" badge_category = "SCOUT MASTER" program.scout_master = True program.put() to_email_mentor = mentor.email html_mentor = mailContent.newbadge variables_mentor = [ {"name": "contributors_first_name", "content": contributors_first_name}, {"name": "contributed_hours", "content": contributed_hours}, {"name": "server_url", "content": access.server_url}, {"name": "badge_name", "content": badge_name}, {"name": "badge_category", "content": badge_category}, ] to_email_admin = admin.email to_name_admin = to_name html_admin = mailContent.newbadgeadmin variables_admin = [ {"name": "contributors_full_name", "content": to_name_mentor}, {"name": "badge_category", "content": badge_category}, {"name": "contributed_hours", "content": contributed_hours}, {"name": "server_url", "content": access.server_url}, {"name": "twitter", "content": twitter}, {"name": "contributors_first_name", "content": contributors_first_name}, ] if sendmail: try: mentor_mail = sendOutboundMail( from_email, from_name, to_email_mentor, to_name_mentor, mentor_subject, html_mentor, tags, reply_to, variables_mentor, merge, ) admin_mail = sendOutboundMail( from_email, from_name, to_email_admin, to_name_admin, subject, html_admin, tags, reply_to, variables_admin, merge, ) return True except: return False return True
def sendBadgeMail(from_email, from_name, contribution, mentor, admin, reply_to, merge, to_name): sendmail = False contributed_hours = contribution.get("new_total") badge_category = "" badge_name = "" contributors_first_name = mentor.first_name program = Program.all().filter("user = "******" " + mentor.last_name subject = "%s just earned a new badge!" %(to_name_mentor) tags = "New badge earned" if contributed_hours >= 50 and program.guru == None: sendmail = True badge_category = "GURU" badge_name = "Badge50" program.guru = True program.ninja = True program.rock_star = True program.put() elif contributed_hours >= 25 and program.ninja == None: sendmail = True badge_name = "Badge25" badge_category = "NINJA" program.ninja = True program.rock_star = True program.put() elif contributed_hours >= 10 and program.rock_star == None: sendmail = True badge_name = "Badge10" badge_category = "ROCK STAR" program.rock_star = True program.put() to_email_mentor = mentor.email html_mentor = mailContent.newbadge variables_mentor = [ {'name':'contributors_first_name', 'content': contributors_first_name}, {'name':'contributed_hours', 'content': contributed_hours}, {'name':'badge_name', 'content': badge_name}, {'name':'badge_category', 'content': badge_category} ] to_email_admin = admin.email to_name_admin = to_name html_admin = mailContent.newbadgeadmin variables_admin = [ {'name':'contributors_full_name', 'content': to_name_mentor}, {'name':'badge_category', 'content': badge_category}, {'name':'contributed_hours', 'content': contributed_hours}, {'name':'contributors_first_name', 'content': contributors_first_name} ] if sendmail: try: mentor_mail = sendOutboundMail(from_email, from_name, to_email_mentor, to_name_mentor, subject, html_mentor, tags, reply_to, variables_mentor, merge) admin_mail = sendOutboundMail(from_email, from_name, to_email_admin, to_name_admin, subject, html_admin, tags, reply_to, variables_admin, merge) return True except: return False return True