def send_org_bookmark_email(self, org_bookmark, now_month, options):
        if org_bookmark.practice or options["practice"]:
            org = org_bookmark.practice or Practice.objects.get(
                pk=options["practice"])
        elif org_bookmark.pct or options["ccg"]:
            org = org_bookmark.pct or PCT.objects.get(pk=options["ccg"])
        elif org_bookmark.pcn or options["pcn"]:
            org = org_bookmark.pcn or PCN.objects.get(pk=options["pcn"])
        else:
            assert False
        if getattr(org, "close_date", None):
            logger.info("Skipping sending alert for closed org %s", org.pk)
            return
        stats = bookmark_utils.InterestingMeasureFinder(
            org).context_for_org_email()

        try:
            msg = bookmark_utils.make_org_email(org_bookmark,
                                                stats,
                                                tag=now_month)
            msg = EmailMessage.objects.create_from_message(msg)
            msg.send()
            logger.info("Sent org bookmark alert to %s about %s" %
                        (msg.to, org_bookmark.id))
        except bookmark_utils.BadAlertImageError as e:
            logger.exception(e)
                def callback():
                    stats = bookmark_utils.InterestingMeasureFinder(
                        practice=org_bookmark.practice or options['practice'],
                        pct=org_bookmark.pct
                        or options['ccg']).context_for_org_email()

                    msg = bookmark_utils.make_org_email(org_bookmark, stats)
                    msg = EmailMessage.objects.create_from_message(msg)
                    msg.send()
                    logger.info("Sent org bookmark alert to %s about %s" %
                                (msg.to, org_bookmark.id))
예제 #3
0
def preview_bookmark(request, practice=None, pct=None, url=None, name=None):
    user = User(email='*****@*****.**')
    user.profile = Profile()
    if pct or practice:
        context = bookmark_utils.InterestingMeasureFinder(
            practice=practice, pct=pct).context_for_org_email()
        bookmark = OrgBookmark(practice=practice, pct=pct, user=user)
        msg = bookmark_utils.make_org_email(bookmark, context)
    else:
        bookmark = SearchBookmark(url=url, user=user, name=name)
        msg = bookmark_utils.make_search_email(bookmark)
    html = msg.alternatives[0][0]
    images = msg.attachments
    return HttpResponse(_convert_images_to_data_uris(html, images))
예제 #4
0
 def send_org_bookmark_email(self, org_bookmark, now_month, options):
     stats = bookmark_utils.InterestingMeasureFinder(
         practice=org_bookmark.practice or options['practice'],
         pct=org_bookmark.pct or options['ccg']
     ).context_for_org_email()
     try:
         msg = bookmark_utils.make_org_email(org_bookmark, stats, tag=now_month)
         msg = EmailMessage.objects.create_from_message(msg)
         msg.send()
         logger.info(
             "Sent org bookmark alert to %s about %s" % (
                 msg.to, org_bookmark.id))
     except bookmark_utils.BadAlertImageError as e:
         logger.exception(e)
예제 #5
0
def preview_bookmark(request, practice=None, pct=None, url=None, name=None):
    user = User(email='*****@*****.**')
    user.profile = Profile()
    if pct or practice:
        context = bookmark_utils.InterestingMeasureFinder(
            practice=practice,
            pct=pct
        ).context_for_org_email()
        bookmark = OrgBookmark(practice=practice, pct=pct, user=user)
        msg = bookmark_utils.make_org_email(
            bookmark, context)
    else:
        bookmark = SearchBookmark(url=url, user=user, name=name)
        msg = bookmark_utils.make_search_email(bookmark)
    html = msg.alternatives[0][0]
    images = msg.attachments
    return HttpResponse(_convert_images_to_data_uris(html, images))
예제 #6
0
    def handle(self, *args, **options):
        self.validate_options(**options)
        for org_bookmark in self.get_org_bookmarks(**options):
            stats = bookmark_utils.InterestingMeasureFinder(
                practice=org_bookmark.practice or options['practice'],
                pct=org_bookmark.pct or options['ccg']).context_for_org_email()

            msg = bookmark_utils.make_org_email(
                org_bookmark, stats)
            msg.send()
            logger.info("Sent message to user %s about bookmark %s" % (
                msg.recipients(), org_bookmark.id))
        for search_bookmark in self.get_search_bookmarks(**options):
            recipient_id = search_bookmark.user.id
            msg = bookmark_utils.make_search_email(
                search_bookmark)
            msg.send()
            logger.info("Sent message to user %s about bookmark %s" % (
                recipient_id, search_bookmark.id))