def render(self, context): issue = self.issue.resolve(context) if issue == None: return contacts = utils.getIssueContacts(issue) if contacts == None or len(contacts) < 1: return # get the contact names names = [u.username for u in contacts] return ", ".join(names)
def stateChangeNotifications(sender, data=None, **kwargs): """ Sends notification e-mails on state changes for an issue """ if sender.group == None and sender.item == None: return #print data sender = Issue.objects.get(pk=sender.pk) try: sender.assignee except: sender.assignee = None new_assignee = None try: if data['assignee'] != '': new_assignee = User.objects.get(pk=data['assignee']) except: pass contacts = [c.email for c in utils.getIssueContacts(sender)] if new_assignee != None and new_assignee.email not in contacts: contacts.append(new_assignee.email) # send an email to this contact em = Email.NewIssueEmail(sender) try: em.addTo(sender.reporter.email) except: pass # Check for a change in assignee if data.has_key('cc'): cc_id = data.getlist('cc') else: cc_id = [] cc_list = [] for cc in cc_id: try: cc_list.append(User.objects.get(pk=cc)) except: pass em.addCCSection(sender.cc.filter(), cc_list) if new_assignee != sender.assignee: em.addAssigneeSection(str(sender.assignee),str(new_assignee)) # Check for a change in resolved state em.addProblemTypeSection(sender.problem_type.filter(), data.getlist('problem_type')) if data['resolved_state'] != '': resolved_state = ResolveState.objects.get(pk=data['resolved_state']) if resolved_state != sender.resolved_state: em.addResolveStateSection(resolved_state) #Add Comment if exists if data['comment'] != '': em.addCommentSection(User.objects.get(pk=data['user']), data['comment']) title = sender.title try: title = title.replace('@', '[at]') except: pass em.subject = "%s: %s, #%d [" % (sender.item, title, sender.pk) + settings.EMAIL_SUBJECT_PREFIX + "] Updated" for email in contacts: try: em.addTo(email) except: pass em.send()
def sendCreateIssueEmail(sender, instance=None, created=False, **kwargs): """ Send an email for issue creation to the reporter, group contact, and CC """ # retrieve the group from Instance if instance.group == None and instance.item == None or not created: return try: contacts = [c.email for c in utils.getIssueContacts(instance)] except: contacts =[] # send an email to this contact em = Email.NewIssueEmail(instance, instance.title) # if (instance.assignee is None) try: em.addTo(instance.reporter.email) except: pass p_types = [] for p_type in instance.problem_type.all(): p_types.append(p_type.pk) em.addProblemTypeSection("", p_types) if instance.group: group_name = instance.group.name else: group_name = 'None' if (instance.assignee is None): if (instance.steps == '' and instance.attempts ==''): em.addCommentSection(None, "Submitted by " + instance.reporter.username + ".\n" + "Group/Location: " + group_name + ".\n" + "Machine Name: " + instance.item.name + ".\n" + "Description: " + "\n" + instance.description + "\n\n") elif instance.steps == '': em.addCommentSection(None, "Submitted by " + instance.reporter.username + ".\n" + "Group/Location: " + group_name + ".\n" + "Machine Name: " + instance.item.name + ".\n" + "Description: " + "\n" + instance.description + "\n\n" + "Attempts: " + "\n" + instance.attempts + "\n\n") elif instance.attempts == '': em.addCommentSection(None, "Submitted by " + instance.reporter.username + ".\n" + "Group/Location: " + group_name + ".\n" + "Machine Name: " + instance.item.name + ".\n" + "Description: " + "\n" + instance.description + "\n\n" + "Steps: " + "\n" + instance.steps + "\n\n") else: em.addCommentSection(None, "Submitted by " + instance.reporter.username + ".\n" + "Group/Location: " + group_name + ".\n" + "Machine Name: " + instance.item.name + ".\n" + "Description: " + "\n" + instance.description + "\n\n" + "Steps: " + "\n" + instance.steps + "\n\n" + "Attempts: " + "\n" + instance.attempts + "\n\n") else: if (instance.steps == '' and instance.attempts ==''): em.addCommentSection(None, "Submitted by " + instance.reporter.username + ".\n" + "Assigned to: " + instance.assignee.username + ".\n" + "Group/Location: " + group_name + ".\n" + "Machine Name: " + instance.item.name + ".\n" + "Description: " + "\n" + instance.description + "\n\n") elif (instance.steps == ''): em.addCommentSection(None, "Submitted by " + instance.reporter.username + ".\n" + "Assigned to: " + instance.assignee.username + ".\n" + "Group/Location: " + group_name + ".\n" + "Machine Name: " + instance.item.name + ".\n" + "Description: " + "\n" + instance.description + "\n\n" + "Attempts: " + "\n" + instance.attempts + "\n\n") elif (instance.attempts == ''): em.addCommentSection(None, "Submitted by " + instance.reporter.username + ".\n" + "Assigned to: " + instance.assignee.username + ".\n" + "Group/Location: " + group_name + ".\n" + "Machine Name: " + instance.item.name + ".\n" + "Description: " + "\n" + instance.description + "\n\n" + "Steps: " + "\n" + instance.steps + "\n\n") else: em.addCommentSection(None, "Submitted by " + instance.reporter.username + ".\n" + "Assigned to: " + instance.assignee.username + ".\n" + "Group/Location: " + group_name + ".\n" + "Machine Name: " + instance.item.name + ".\n" + "Description: " + "\n" + instance.description + "\n\n" + "Steps: " + "\n" + instance.steps + "\n\n" + "Attempts: " + "\n" + instance.attempts + "\n\n") for email in contacts: try: em.addTo(email) except: pass em.send()