Esempio n. 1
0
 def get_subject_and_message(self, language):
     """
     Returns the subject and message rendered in the specified language.
     """
     return render_message_to_string(
         self.subject_template, self.message_template, self.get_email_params(), language=language
     )
Esempio n. 2
0
 def get_subject_and_message(self, language):
     """
     Returns the subject and message rendered in the specified language.
     """
     return render_message_to_string(self.subject_template,
                                     self.message_template,
                                     self.get_email_params(),
                                     language=language)
Esempio n. 3
0
 def get_subject_and_message_ccx(self):
     """
     Returns the subject and message rendered in the specified language for CCX.
     """
     subject_template = 'emails/enroll_email_enrolledsubject.txt'
     message_template = 'emails/enroll_email_enrolledmessage.txt'
     return render_message_to_string(subject_template, message_template,
                                     self.get_email_params_ccx())
Esempio n. 4
0
 def get_subject_and_message_ccx(self, subject_template, message_template):
     """
     Returns the subject and message rendered in the specified language for CCX.
     """
     return render_message_to_string(
         subject_template,
         message_template,
         self.get_email_params_ccx()
     )
 def get_subject_and_message_ccx(self, subject_template, message_template):
     """
     Returns the subject and message rendered in the specified language for CCX.
     """
     return render_message_to_string(
         subject_template,
         message_template,
         self.get_email_params_ccx()
     )
Esempio n. 6
0
 def get_subject_and_message_ccx(self):
     """
     Returns the subject and message rendered in the specified language for CCX.
     """
     subject_template = 'emails/enroll_email_enrolledsubject.txt'
     message_template = 'emails/enroll_email_enrolledmessage.txt'
     return render_message_to_string(
         subject_template,
         message_template,
         self.get_email_params_ccx()
     )
Esempio n. 7
0
    def send_mail_to_student(self, student, param_dict, language=None):
        """
        Construct the email using templates and then send it.
        `student` is the student's email address (a `str`),
        `param_dict` is a `dict` with keys
        [
            `site_name`: name given to edX instance (a `str`)
            `registration_url`: url for registration (a `str`)
            `display_name` : display name of a course (a `str`)
            `course_id`: id of course (a `str`)
            `auto_enroll`: user input option (a `str`)
            `course_url`: url of course (a `str`)
            `email_address`: email of student (a `str`)
            `full_name`: student full name (a `str`)
            `message`: type of email to send and template to use (a `str`)
            `is_shib_course`: (a `boolean`)
        ]
        `language` is the language used to render the email. If None the language
        of the currently-logged in user (that is, the user sending the email) will
        be used.
        Returns a boolean indicating whether the email was sent successfully.
        """

        # add some helpers and microconfig subsitutions

        if 'display_name' in param_dict:
            param_dict['course_name'] = param_dict['display_name']
        """
        param_dict['site_name'] = configuration_helpers.get_value(
            'SITE_NAME',
            param_dict['site_name']
        )
        """
        subject = None
        message = None

        # see if there is an activation email template definition available as configuration,
        # if so, then render that
        message_type = param_dict['message']

        email_template_dict = {
            'allowed_enroll': ('emails/enroll_email_allowedsubject.txt',
                               'emails/enroll_email_allowedmessage.txt'),
            'enrolled_enroll': ('emails/enroll_email_enrolledsubject.txt',
                                'emails/enroll_email_enrolledmessage.txt'),
            'allowed_unenroll': ('emails/unenroll_email_subject.txt',
                                 'emails/unenroll_email_allowedmessage.txt'),
            'enrolled_unenroll': ('emails/unenroll_email_subject.txt',
                                  'emails/unenroll_email_enrolledmessage.txt'),
            'add_beta_tester': ('emails/add_beta_tester_email_subject.txt',
                                'emails/add_beta_tester_email_message.txt'),
            'remove_beta_tester':
            ('emails/remove_beta_tester_email_subject.txt',
             'emails/remove_beta_tester_email_message.txt'),
            'account_creation_and_enrollment':
            ('emails/enroll_email_enrolledsubject.txt',
             'emails/account_creation_and_enroll_emailMessage.txt'),
        }

        subject_template, message_template = email_template_dict.get(
            message_type, (None, None))
        if subject_template is not None and message_template is not None:
            subject, message = render_message_to_string(subject_template,
                                                        message_template,
                                                        param_dict,
                                                        language=language)

        if subject and message:
            # Remove leading and trailing whitespace from body
            message = message.strip()

            # Email subject *must not* contain newlines
            subject = ''.join(subject.splitlines())
            from_address = configuration_helpers.get_value(
                'email_from_address', settings.DEFAULT_FROM_EMAIL)

            send_mail(subject,
                      message,
                      from_address, [student],
                      fail_silently=False)