def get_password_reset_email( user, reset_url, subject_template_name='registration/password_reset_subject.txt', # noqa email_template_name='api_password_reset_email.html', # noqa token_generator=default_token_generator, email_subject=None): """Creates the subject and email body for password reset email.""" result = urlparse(reset_url) site_name = domain = result.hostname encoded_username = urlsafe_base64_encode(b(user.username.encode('utf-8'))) c = { 'email': user.email, 'domain': domain, 'path': result.path, 'site_name': site_name, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'username': user.username, 'encoded_username': encoded_username, 'token': token_generator.make_token(user), 'protocol': result.scheme if result.scheme != '' else 'http', } # if subject email provided don't load the subject template subject = email_subject or loader.render_to_string(subject_template_name, c) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) email = loader.render_to_string(email_template_name, c) return subject, email
def get_password_reset_email(user, reset_url, subject_template_name='registration/password_reset_subject.txt', # noqa email_template_name='api_password_reset_email.html', # noqa token_generator=default_token_generator, email_subject=None): """Creates the subject and email body for password reset email.""" result = urlparse(reset_url) site_name = domain = result.hostname encoded_username = urlsafe_base64_encode( b(user.username.encode('utf-8'))) c = { 'email': user.email, 'domain': domain, 'path': result.path, 'site_name': site_name, 'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'username': user.username, 'encoded_username': encoded_username, 'token': token_generator.make_token(user), 'protocol': result.scheme if result.scheme != '' else 'http', } # if subject email provided don't load the subject template subject = email_subject or loader.render_to_string(subject_template_name, c) # Email subject *must not* contain newlines subject = ''.join(subject.splitlines()) email = loader.render_to_string(email_template_name, c) return subject, email
def get_survey(self): if not hasattr(self, "_survey"): try: builder = SurveyElementBuilder() self._survey = \ builder.create_survey_element_from_json(self.json) except ValueError: xml = b(bytearray(self.xml, encoding='utf-8')) self._survey = create_survey_element_from_xml(xml) return self._survey
def get_survey(self): if not hasattr(self, "_survey"): try: builder = SurveyElementBuilder() self._survey = \ builder.create_survey_element_from_json(self.json) except ValueError: xml = b(bytearray(self.xml, encoding='utf-8')) self._survey = create_survey_element_from_xml(xml) return self._survey