Ejemplo n.º 1
0
    def notify(self, who, what, date, url, changes = None):
        recipients = []
        
        try:
            for i in who:
                e = self.__get_recipient(i)

                if e:
                    recipients += [e]
        except TypeError: # 'who' is not a list, but a single user
            e = self.__get_recipient(who)

            if e:
                recipients += [e]
                                 
        email = self.cloneTemplate(what)
        email.SetRecipients(recipients)
        body = email.GetBody();

        if changes:
            body += "\n\nList of changes:\n\n"
            for i in changes:
                body += i + (":\t" if len(i) < 8 else ":") + changes[i] + "\n"

        email.SetBody(body % (date, url))
        self.post(email)
        Notifier.notify(self)
Ejemplo n.º 2
0
    def __init__(self, skipEmails = [], test = False, log = False):
        Notifier.__init__(self, skipEmails, test, log)

        activities = {"new"      : ("A new activity was added for the maintenance period"
                                    " on %s\nClick to view: %s") ,
                      "modified" : ("A previously approved activity has been modified for"
                                    " the maintenance period on %s\nClick to view: %s"),
                      "deleted"  : ("An activity has been deleted from the maintenance"
                                    "period on %s\nClick to view: %s"),
                      "approved" : ("Your activity for the maintenance period for %s"
                                    " has been approved.\nClick to view: %s")}

        sender = "*****@*****.**"
        subject = "GBT Resource Calendar Activity"

        for i in activities:
            em_templ = EmailMessage(sender, "", subject, activities[i])
            self.registerTemplate(i, em_templ)
Ejemplo n.º 3
0
def projects_email(request, *args, **kwds):
    if request.method == "GET":
        pcodes = request.GET.get("pcodes", None)
        pcode_list = pcodes.split(" ") if pcodes is not None else getPcodesFromFilter(request)
        pi_list, pc_list, ci_list, ob_list, fs_list = getInvestigatorEmails(pcode_list)

        templates = EmailTemplate.get_templates(pcode_list)

        return HttpResponse(
            json.dumps(
                {
                    "PI-Addresses": pi_list,
                    "PC-Addresses": pc_list,
                    "CO-I-Addresses": ci_list,
                    "OBS-Addresses": ob_list,
                    "Friend-Addresses": fs_list,
                    "PCODES": pcode_list,
                    "Templates": templates,
                }
            ),
            mimetype="text/plain",
        )

    elif request.method == "POST":
        email_key = "projects_email"
        pe_notifier = Notifier()
        em_templ = EmailMessage("*****@*****.**", "", "", "")
        pe_notifier.registerTemplate(email_key, em_templ)
        addr = str(request.POST.get("address", "")).replace(" ", "").split(",")
        subject = request.POST.get("subject", "")
        body = request.POST.get("body", "")

        email = pe_notifier.cloneTemplate(email_key)
        email.SetRecipients(addr)
        email.SetSubject(subject)
        email.SetBody(body)
        pe_notifier.post(email)
        pe_notifier.notify()

        return HttpResponse(json.dumps({"success": "ok"}), mimetype="text/plain")

    else:
        return HttpResponse(json.dumps({"error": "request.method is neither GET or POST!"}), mimetype="text/plain")