Exemplo n.º 1
0
def send_email_to_editors(course_run, template_name, subject, context=None):
    """ Send a specific email template to all editors for a course run.

        Arguments:
            course_run (Object): CourseRun object
            template_name (str): path to template without filename extension
            subject (str): subject line for the email
            context (dict): additional context for the template
    """
    # Model imports here to avoid a circular import
    from course_discovery.apps.course_metadata.models import CourseEditor  # pylint: disable=import-outside-toplevel

    editors = CourseEditor.course_editors(course_run.course)
    send_email(template_name, subject, editors, _('course team'), context=context, course_run=course_run)
Exemplo n.º 2
0
def send_email_for_comment(comment, course, author):
    """ Send the emails for a comment.

        Arguments:
            comment (Dict): Comment dict returned from salesforce.py
            course (Course): Course object for the comment
            author (User): User object who made the post request
    """
    # Model imports here to avoid a circular import
    from course_discovery.apps.course_metadata.models import CourseEditor

    subject = _('Comment added: {title}').format(title=course.title)

    org = course.authoring_organizations.first()
    project_coordinator = get_project_coordinator(org)
    recipients = list(CourseEditor.course_editors(course))
    if project_coordinator:
        recipients.append(project_coordinator)

    # remove email of comment owner if exists
    recipients = filter(lambda x: x.email != author.email, recipients)

    context = {
        'comment_message':
        comment.get('comment'),
        'user_name':
        author.username,
        'course_name':
        course.title,
        'comment_date':
        dateutil.parser.parse(comment.get('created')),
        'page_url':
        '{url}/courses/{path}'.format(
            url=course.partner.publisher_url.strip('/'), path=course.uuid)
    }

    try:
        send_email('course_metadata/email/comment',
                   subject,
                   recipients,
                   '',
                   course=course,
                   context=context,
                   project_coordinator=project_coordinator)
    except Exception:  # pylint: disable=broad-except
        logger.exception(
            'Failed to send email notifications for comment on course %s',
            course.uuid)