def newPost(self, user, message, clean_team, notification=True): self.user = user self.clean_team = clean_team self.message = message self.save() if notification: try: # Send notifications notification = Notification.objects.get(notification_type="message_posted") # The names that will go in the notification message template name_strings = [self.clean_team.name] link_strings = [str(self.clean_team.id)] users_to_notify_str = notification.users_to_notify users_to_notify = users_to_notify_str.split(', ') # Notify all of the Users that have the roles within users_to_notify for role in users_to_notify: clean_team_members = CleanTeamMember.objects.filter(role=role, clean_team=self.clean_team, status="approved") members_list = list(clean_team_members) if role == "agent": clean_champions = CleanChampion.objects.filter(clean_team=self.clean_team, status="approved") members_list = list(chain(clean_team_members, clean_champions)) for member in members_list: user_notification = UserNotification() user_notification.create_notification("message_posted", member.user, name_strings, link_strings) except Exception, e: print e
def newPost(self, user, message, community, notification=True): self.user = user self.community = community self.message = message self.save() if notification: try: # Send notifications notification = Notification.objects.get(notification_type="message_posted") # The names that will go in the notification message template name_strings = [self.community.name] link_strings = [str(self.community.id)] users_to_notify_str = notification.users_to_notify users_to_notify = users_to_notify_str.split(', ') # Notify all of the Users that have the roles within users_to_notify for role in users_to_notify: community_members = UserCommunityMembership.objects.filter(community=self.community) members_list = list(community_members) for member in members_list: user_notification = UserNotification() user_notification.create_notification("message_posted", member.user, name_strings, link_strings) except Exception, e: print e
def becomeCleanChampionNew(self, user, userid, selected_team): self.user_id = userid self.clean_team_id = selected_team self.status = "approved" self.save() # Send notifications notification = Notification.objects.get(notification_type="cc_joined") # The names that will go in the notification message template full_name = u'%s %s' %(self.user.first_name, self.user.last_name) name_strings = [full_name, self.clean_team.name] users_to_notify_str = notification.users_to_notify users_to_notify = users_to_notify_str.split(', ') # Notify all of the Users that have the roles within users_to_notify for role in users_to_notify: # print self.clean_team_id clean_team_members = CleanTeamMember.objects.filter(role=role, clean_team=self.clean_team, status="approved") for member in clean_team_members: user_notification = UserNotification() user_notification.create_notification("cc_joined", member.user, name_strings) self.clean_team.add_team_clean_creds(5) self.user.profile.add_clean_creds(20)
def requestBecomeCleanAmbassador(self, user, selected_team, notification=True): self.user = user self.clean_team = selected_team self.status = "pending" self.role = "leader" self.save() self.user.profile.clean_team_member = CleanTeamMember.objects.latest('id') self.user.profile.save() try: if notification: # Send notifications # notification = Notification.objects.get(notification_type="ca_request") # The names that will go in the notification message template full_name = u'%s %s' %(self.user.first_name, self.user.last_name) name_strings = [full_name, self.clean_team.name] # users_to_notify_str = notification.users_to_notify users_to_notify_str = "leader" users_to_notify = users_to_notify_str.split(', ') # Notify all of the Users that have the roles within users_to_notify for role in users_to_notify: clean_team_members = CleanTeamMember.objects.filter(role=role, clean_team=self.clean_team, status="approved") for member in clean_team_members: user_notification = UserNotification() user_notification.create_notification("ca_request", member.user, name_strings) except Exception, e: print e
def becomeCleanChampion(self, user, selected_team, notification=True): self.user = user self.clean_team = selected_team self.status = "approved" self.save() if notification: try: # Send notifications notification = Notification.objects.get(notification_type="cc_joined") # The names that will go in the notification message template full_name = u'%s %s' %(self.user.first_name, self.user.last_name) name_strings = [full_name, self.clean_team.name] users_to_notify_str = notification.users_to_notify users_to_notify = users_to_notify_str.split(', ') # Notify all of the Users that have the roles within users_to_notify for role in users_to_notify: clean_team_members = CleanTeamMember.objects.filter(role=role, clean_team=self.clean_team, status="approved") for member in clean_team_members: user_notification = UserNotification() user_notification.create_notification("cc_joined", member.user, name_strings) except Exception, e: print e
def add_team_clean_creds(self, amount, notification=True): self.clean_creds += amount self.save() if notification: try: # Send notifications notification = Notification.objects.get(notification_type="clean_team_add_clean_creds") # The names that will go in the notification message template name_strings = [self.name, amount] link_strings = [str(self.id)] users_to_notify_str = notification.users_to_notify users_to_notify = users_to_notify_str.split(', ') # Notify all of the Users that have the roles within users_to_notify for role in users_to_notify: clean_team_members = CleanTeamMember.objects.filter(role=role, clean_team=self, status="approved") for member in clean_team_members: user_notification = UserNotification() user_notification.create_notification("clean_team_add_clean_creds", member.user, name_strings, link_strings) except Exception, e: print e
def add_clean_creds(self, amount, notification=True): self.clean_creds += amount self.save() if notification: try: # Send notifications notification = Notification.objects.get(notification_type="user_add_clean_creds") # The names that will go in the notification message template name_strings = [amount] link_strings = [str(self.user.id)] user_notification = UserNotification() user_notification.create_notification("user_add_clean_creds", self.user, name_strings, link_strings) except Exception, e: print e
def level_up(self, notification=True): # If they don't have a badge, ie. new team, make them a Seedling if self.level is None: level = CleanTeamLevel.objects.get(name="Seedling") else: level = CleanTeamLevel.objects.get(name="Seedling") self.level = level # Add rewards for certain badges self.save() level_tasks = CleanTeamLevelTask.objects.filter(clean_team_level=self.level) # Create the new tasks the Change Team must complete for task in level_tasks: level_progress = CleanTeamLevelProgress(clean_team=self, level_task=task) level_progress.save() if notification: try: # Send notifications notification = Notification.objects.get(notification_type="level_up") # The names that will go in the notification message template name_strings = [self.name, self.level.name] link_strings = [str(self.id)] users_to_notify_str = notification.users_to_notify users_to_notify = users_to_notify_str.split(', ') # Notify all of the Users that have the roles within users_to_notify for role in users_to_notify: clean_team_members = CleanTeamMember.objects.filter(role=role, clean_team=self, status="approved") for member in clean_team_members: user_notification = UserNotification() user_notification.create_notification("level_up", member.user, name_strings, link_strings) except Exception, e: print e
def acceptInvite(self, user, notification=True): if self.role == "agent": clean_champion = CleanChampion() clean_champion.becomeCleanChampion(user, self.clean_team) elif self.role == "leader": ctm = CleanTeamMember() ctm.becomeCleanAmbassador(user, self.clean_team) emails = User.objects.filter(email=self.email).count() if emails > 0: self.status = "accepted" self.save() self.user.profile.add_clean_creds(10) if notification: if self.role: try: # Send notifications notification = Notification.objects.get(notification_type="ca_joined") # The names that will go in the notification message template full_name = u'%s %s' %(self.user.first_name, self.user.last_name) name_strings = [full_name, self.clean_team.name] users_to_notify_str = notification.users_to_notify users_to_notify = users_to_notify_str.split(', ') # Notify all of the Users that have the roles within users_to_notify for role in users_to_notify: clean_team_members = CleanTeamMember.objects.filter(role=role, clean_team=self.clean_team, status="approved") for member in clean_team_members: user_notification = UserNotification() user_notification.create_notification("ca_joined", member.user, name_strings) # self.clean_team.add_team_clean_creds(5) except Exception, e: print e return True
def becomeCleanAmbassador(self, user, selected_team, notification=True): CleanChampion.objects.filter(user=user, clean_team=selected_team).delete() self.user = user self.clean_team = selected_team self.role = "leader" self.status = "approved" self.save() self.user.profile.clean_team_member = CleanTeamMember.objects.latest('id') self.user.profile.save() if notification: try: # Send notifications # notification = Notification.objects.get(notification_type="ca_approved") # The names that will go in the notification message template name_strings = [self.clean_team.name] link_strings = [str(self.clean_team.id)] user_notification = UserNotification() user_notification.create_notification("ca_approved", self.user, name_strings, link_strings) except Exception, e: print e
self.save() try: CleanChampion.objects.filter(user=self.user, clean_team=self.clean_team).delete() except Exception, e: print e if notification: try: # Send notifications # notification = Notification.objects.get(notification_type="ca_approved") # The names that will go in the notification message template name_strings = [self.clean_team.name] link_strings = [str(self.clean_team.id)] user_notification = UserNotification() user_notification.create_notification("ca_approved", self.user, name_strings, link_strings) except Exception, e: print e self.user.profile.add_clean_creds(50) def removedCleanAmbassador(self): self.user.profile.clean_team_member = None self.user.profile.save() self.delete() def requestBecomeCleanAmbassador(self, user, selected_team, notification=True): self.user = user self.clean_team = selected_team self.status = "pending" self.role = "leader"