def test_field_handles_html(content, values, expected_stripped, expected_escaped, expected_passthrough): assert str(Field(content, values)) == expected_stripped assert str(Field(content, values, html='strip')) == expected_stripped assert str(Field(content, values, html='escape')) == expected_escaped assert str(Field(content, values, html='passthrough')) == expected_passthrough
def __str__(self): return Markup( self.jinja_template.render({ 'sender': self.sender, 'show_sender': self.show_sender, 'recipient': Field('((phone number))', self.values, with_brackets=False, html='escape'), 'show_recipient': self.show_recipient, 'body': Take( Field( self.content, self.values, html='escape', redact_missing_personalisation=self. redact_missing_personalisation, )).then(add_prefix, (escape_html(self.prefix) or None) if self.show_prefix else None). then(sms_encode if self.downgrade_non_sms_characters else str ).then(remove_whitespace_before_punctuation).then( nl2br).then(autolink_sms) }))
def service_settings(service_id): letter_branding_organisations = email_branding_client.get_letter_email_branding( ) organisation = organisations_client.get_service_organisation( service_id).get('name', None) if current_service['email_branding']: email_branding = email_branding_client.get_email_branding( current_service['email_branding'])['email_branding'] else: email_branding = None inbound_number = inbound_number_client.get_inbound_sms_number_for_service( service_id) disp_inbound_number = inbound_number['data'].get('number', '') reply_to_email_addresses = service_api_client.get_reply_to_email_addresses( service_id) reply_to_email_address_count = len(reply_to_email_addresses) default_reply_to_email_address = next( (x['email_address'] for x in reply_to_email_addresses if x['is_default']), "Not set") letter_contact_details = service_api_client.get_letter_contacts(service_id) letter_contact_details_count = len(letter_contact_details) default_letter_contact_block = next( (Field(x['contact_block'], html='escape') for x in letter_contact_details if x['is_default']), "Not set") sms_senders = service_api_client.get_sms_senders(service_id) sms_sender_count = len(sms_senders) default_sms_sender = next((Field(x['sms_sender'], html='escape') for x in sms_senders if x['is_default']), "None") free_sms_fragment_limit = billing_api_client.get_free_sms_fragment_limit_for_year( service_id) data_retention = service_api_client.get_service_data_retention(service_id) return render_template( 'views/service-settings.html', email_branding=email_branding, letter_branding=letter_branding_organisations.get( current_service.get('dvla_organisation', '001')), can_receive_inbound=('inbound_sms' in current_service['permissions']), inbound_number=disp_inbound_number, default_reply_to_email_address=default_reply_to_email_address, reply_to_email_address_count=reply_to_email_address_count, default_letter_contact_block=default_letter_contact_block, letter_contact_details_count=letter_contact_details_count, default_sms_sender=default_sms_sender, sms_sender_count=sms_sender_count, free_sms_fragment_limit=free_sms_fragment_limit, prefix_sms=current_service['prefix_sms'], organisation=organisation, data_retention=data_retention, )
def __str__(self): return Markup( self.jinja_template.render({ 'admin_base_url': self.admin_base_url, 'logo_file_name': self.logo_file_name, 'subject': self.subject, 'message': Take( Field( strip_dvla_markup(self.content), self.values, html='escape', markdown_lists=True, redact_missing_personalisation=self. redact_missing_personalisation, )).then(strip_pipes).then( make_markdown_take_notice_of_multiple_newlines).then( notify_letter_preview_markdown). then(strip_characters_inserted_to_force_newlines).then( do_nice_typography).then(remove_trailing_linebreak).then( replace_hyphens_with_non_breaking_hyphens).then( tweak_dvla_list_markup), 'address': Take( Field(self.address_block, (self.values_with_default_optional_address_lines if all( Columns(self.values).get(key) for key in { 'address line 1', 'address line 2', 'postcode', }) else self.values), html='escape', with_brackets=False) ).then(strip_pipes).then(remove_empty_lines).then( remove_whitespace_before_punctuation).then(nl2li), 'contact_block': Take( Field( '\n'.join(line.strip() for line in self.contact_block.split('\n')), self.values, redact_missing_personalisation=self. redact_missing_personalisation, html='escape', )).then(remove_whitespace_before_punctuation).then( nl2br).then(strip_pipes), 'date': datetime.utcnow().strftime('%-d %B %Y') }))
def __str__(self): return Markup( self.jinja_template.render({ 'body': get_html_email_body(self.content, self.values, redact_missing_personalisation=self. redact_missing_personalisation), 'subject': self.subject, 'from_name': escape_html(self.from_name), 'from_address': self.from_address, 'reply_to': self.reply_to, 'recipient': Field("((email address))", self.values, translated=True), 'show_recipient': self.show_recipient, 'fip_banner_english': self.fip_banner_english, 'fip_banner_french': self.fip_banner_french, 'brand_colour': self.brand_colour, 'brand_logo': self.brand_logo, 'brand_text': self.brand_text, 'brand_name': self.brand_name, 'asset_domain': self.asset_domain, }))
def nl2br(value): if value: return Markup(Take(Field( value, html='escape', )).then(utils_nl2br)) return ''
def get_default_sms_sender(sms_senders): return str( next( (Field(x["sms_sender"], html="escape") for x in sms_senders if x["is_default"]), "None", ))
def subject(self): return Take( Field(self._subject, self.values, html='escape', redact_missing_personalisation=self. redact_missing_personalisation)).then(do_nice_typography)
def __str__(self): return Markup( Field(self.content, self.values, html='escape', redact_missing_personalisation=self. redact_missing_personalisation))
def nl2br(value): if value: return Markup( Take(Field( value, html='escape', )).then(formatters.nl2br)) return ''
def content_with_placeholders_filled_in(self): return str(Field( self.content, self.values, html='passthrough', redact_missing_personalisation=self.redact_missing_personalisation, markdown_lists=True, )).strip()
def __str__(self): return str(Field( self.content, self.values, html='passthrough', redact_missing_personalisation=self.redact_missing_personalisation, markdown_lists=True, ))
def __str__(self): return Take(Field( self.content.strip(), self.values, html='escape', )).then(sms_encode).then(remove_whitespace_before_punctuation).then( normalise_whitespace_and_newlines).then( normalise_multiple_newlines)
def subject(self): return Markup( Take( Field(self._subject, self.values, html='passthrough', redact_missing_personalisation=self. redact_missing_personalisation)).then( do_nice_typography).then(normalise_whitespace))
def __str__(self): return Take( Field(self.content, self.values, html='passthrough', markdown_lists=True)).then(unlink_govuk_escaped).then( notify_plain_text_email_markdown ).then(do_nice_typography).then(unescape).then( strip_leading_whitespace).then(add_trailing_newline)
def default_letter_contact_block_html(self): if self.default_letter_contact_block: return Markup( Take( Field( self.default_letter_contact_block['contact_block'], html='escape', )).then(nl2br)) return ''
def _contact_block(self): return Take( Field( '\n'.join(line.strip() for line in self.contact_block.split('\n')), self.values, redact_missing_personalisation=self. redact_missing_personalisation, html='escape', )).then(remove_whitespace_before_punctuation).then(nl2br)
def __str__(self): return Markup(self.jinja_template.render({ 'body': self.html_body, 'subject': self.subject, 'from_name': escape_html(self.from_name), 'from_address': self.from_address, 'reply_to': self.reply_to, 'recipient': Field("((email address))", self.values, with_brackets=False), 'show_recipient': self.show_recipient }))
def subject(self): return Take( Field( self._subject, self.values, redact_missing_personalisation=self. redact_missing_personalisation, html='escape', )).then(do_nice_typography).then(strip_pipes).then( strip_dvla_markup).then(normalise_whitespace)
def default_letter_contact_block_html(self): if self.default_letter_contact_block: return Markup( Take( Field( self.default_letter_contact_block["contact_block"], html="escape", ) ).then(nl2br) ) return ""
def _message(self): return Take( Field( self.content, self.values, html='escape', markdown_lists=True, redact_missing_personalisation=self. redact_missing_personalisation, )).then(add_trailing_newline).then( notify_letter_preview_markdown).then(do_nice_typography).then( replace_hyphens_with_non_breaking_hyphens)
def preheader(self): return " ".join( Take( Field( self.content, self.values, html='escape', markdown_lists=True, )).then(unlink_govuk_escaped). then(strip_unsupported_characters).then(add_trailing_newline).then( notify_email_preheader_markdown).then(do_nice_typography). split())[:self.PREHEADER_LENGTH_IN_CHARACTERS].strip()
def html_body(self): return Take( Field( self.content, self.values, html='escape', markdown_lists=True, redact_missing_personalisation=self. redact_missing_personalisation, )).then(unlink_govuk_escaped).then( strip_unsupported_characters).then(add_trailing_newline).then( notify_email_markdown).then(do_nice_typography)
def __str__(self): return Markup( Take( Field( self.content, self.values, html='escape', redact_missing_personalisation=True, )).then(sms_encode).then(remove_whitespace_before_punctuation). then(normalise_whitespace_and_newlines).then( normalise_multiple_newlines).then(str.strip))
def __str__(self): return Markup(self.jinja_template.render({ 'body': get_html_email_body( self.content, self.values, redact_missing_personalisation=self.redact_missing_personalisation ), 'subject': self.subject, 'from_name': escape_html(self.from_name), 'from_address': self.from_address, 'reply_to': self.reply_to, 'recipient': Field("((email address))", self.values, with_brackets=False), 'expanded': self.expanded, 'show_recipient': self.show_recipient }))
def get_html_email_body(template_content, template_values, redact_missing_personalisation=False): return Take( Field( template_content, template_values, html='escape', markdown_lists=True, redact_missing_personalisation=redact_missing_personalisation, )).then(unlink_govuk_escaped).then(notify_email_markdown).then( do_nice_typography)
def _address_block(self): return Take( Field(self.address_block, (self.values_with_default_optional_address_lines if all( Columns(self.values).get(key) for key in { 'address line 1', 'address line 2', 'postcode', }) else self.values), html='escape', with_brackets=False)).then(strip_pipes).then( remove_empty_lines).then( remove_whitespace_before_punctuation).then(nl2li)
def _address_block(self): from notifications_utils.postal_address import PostalAddress postal_address = PostalAddress.from_personalisation(Columns(self.values)) if postal_address.has_enough_lines and not postal_address.has_too_many_lines: return postal_address.normalised_lines return Field( self.address_block, self.values, html='escape', with_brackets=False, ).splitlines()
def __str__(self): return Take(Field( self.content, self.values, html='passthrough' )).then( add_prefix, self.prefix ).then( gsm_encode ).then( remove_whitespace_before_punctuation ).then( normalise_newlines ).then( str.strip )
def _address_block(self): if self.postal_address.has_enough_lines and not self.postal_address.has_too_many_lines: return self.postal_address.normalised_lines if 'address line 7' not in self.values and 'postcode' in self.values: self.values['address line 7'] = self.values['postcode'] return Field( self.address_block, self.values, html='escape', with_brackets=False, ).splitlines()