def sendCommentNotificationEmail(self, userToEmail, authorUser, vision, comment): '''Takes dictionary inputs''' visionUser = User.getById(vision[Vision.Key.USER_ID]) if visionUser: visionUser = visionUser.toDictionary() emailAddress = userToEmail[User.Key.EMAIL] if authorUser[User.Key.ID] == visionUser[User.Key.ID]: emailSubject = authorUser[User.Key.FULL_NAME] + \ " responded on their vision" else: emailSubject = authorUser[User.Key.FULL_NAME] + \ " responded on " + \ visionUser[User.Key.FULL_NAME] + "\'s vision" emailText = emailSubject emailHtml = render_template("email/commentNotification.html", userToEmail=userToEmail, authorUser=authorUser, visionUser=visionUser, vision=vision, comment=comment) email = { Constant.EMAIL_TO_KEY : emailAddress, Constant.EMAIL_SUBJECT_KEY : emailSubject, Constant.EMAIL_BODY_TEXT_KEY : emailText, Constant.EMAIL_BODY_HTML_KEY : emailHtml, } emailer = Emailer() emailer.sendBatch([email])
def addVisions(self, userId, numVisionsToAdd): for i in range(0, numVisionsToAdd): text = random.choice(TestApi.texts) url = random.choice(TestApi.pictures) #Add user = User.getById(userId) if user: user.addVision(url, text, True, random.choice([True, False]))
def __getMotivationContent(self): users = User.getAllUsers() data = [] for user in users: obj = user.toDictionaryFull() vision = user.randomVision() if vision: visionObj = vision.toDictionary( options=[Vision.Options.PICTURE]) obj[Notifications.UserKey.RANDOM_VISION] = visionObj data.append(obj) else: # For now, ignore users without any visions # !!!!! FIX THIS LATER SINCE WE SHOULD SEND THEM SOMETHING !!!! #obj[Notifications.UserKey.RANDOM_VISION] = None pass return data '''
def sendCommentEmail(self, authorUser, vision, comment): '''Takes dictionary inputs''' visionUser = User.getById(vision[Vision.Key.USER_ID]) if visionUser: visionUser = visionUser.toDictionaryFull() emailAddress = visionUser[User.Key.EMAIL] emailSubject = authorUser[User.Key.FULL_NAME] + " wrote on your vision" emailText = emailSubject emailHtml = render_template("email/comment.html", author = authorUser, user = visionUser, vision = vision, comment = comment) email = { Constant.EMAIL_TO_KEY : emailAddress, Constant.EMAIL_SUBJECT_KEY : emailSubject, Constant.EMAIL_BODY_TEXT_KEY : emailText, Constant.EMAIL_BODY_HTML_KEY : emailHtml, } emailer = Emailer() emailer.sendBatch([email])
def addUsers(self, numUsersToAdd): for i in range(0,numUsersToAdd): firstName = random.choice(TestApi.firstNames) lastName = random.choice(TestApi.lastNames) email = "TEST" + str(i) + "-" + TestApi.email password = TestApi.password #Add (user, msg)= User.registerNewUser(firstName, lastName, email, password) if None == user: print "Error adding user: "******" " \ + lastName + " " + email print " --> Skipping adding visions for: " + firstName continue print "Added user: "******" " + lastName + " " + email self.addVisions(user.id(), TestApi.NUM_VISIONS) print "Added " + str(TestApi.NUM_VISIONS) + " visions for " \ + firstName + "\n"
def sendRepostEmail(self, user, origVision, newVision): '''Takes dictionaries as input''' origUser = User.getById(origVision['userId']) if origUser: origUser = origUser.toDictionaryFull() emailAddress = origUser[User.Key.EMAIL] emailSubject = user[User.Key.FULL_NAME] + " reposted your vision" emailText = emailSubject emailHtml = render_template("email/repost.html", origUser = origUser, origVision = origVision, user = user, vision = newVision) email = { Constant.EMAIL_TO_KEY : emailAddress, Constant.EMAIL_SUBJECT_KEY : emailSubject, Constant.EMAIL_BODY_TEXT_KEY : emailText, Constant.EMAIL_BODY_HTML_KEY : emailHtml, } emailer = Emailer() emailer.sendBatch([email])