def __str__(self): return Take( Field(self.content, self.values, html='passthrough', markdown_lists=True)).then(unlink_govau_escaped).then( notify_plain_text_email_markdown ).then(do_nice_typography).then(unescape).then( strip_leading_whitespace).then(add_trailing_newline)
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 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 __str__(self): return Markup( Field( self.content, self.values, html='escape', redact_missing_personalisation=self. redact_missing_personalisation, ))
def service_settings(service_id): letter_branding_organisations = organisations_client.get_letter_organisations() if current_service['organisation']: organisation = organisations_client.get_organisation(current_service['organisation'])['organisation'] else: organisation = 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) return render_template( 'views/service-settings.html', organisation=organisation, 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'], )
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 _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 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 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 subject(self): return Markup( Take( Field( self._subject, self.values, html='escape', redact_missing_personalisation=self. redact_missing_personalisation, )).then(do_nice_typography))
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 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 _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 __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({ '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( gsm_encode if self.downgrade_non_gsm_characters else str ).then( remove_whitespace_before_punctuation ).then( nl2br ) }))
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): 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()
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 __str__(self): return Markup( self.jinja_template.render({ 'recipient': Field('((phone number))', self.values, with_brackets=False, html='escape'), 'show_recipient': self.show_recipient, 'body': Take.as_field(self.content, self.values, html='escape').then( add_prefix, (escape_html(self.prefix) or None) if not self.sender else None).then(gsm_encode).then(nl2br).as_string }))
def test_field_renders_lists_as_strings(values, expected, expected_as_markdown): assert str(Field("list: ((placeholder))", values, markdown_lists=True)) == expected_as_markdown assert str(Field("list: ((placeholder))", values)) == expected
def placeholders(self): return super().placeholders | Field( self.contact_block).placeholder_names
def placeholders(self): return Field(self._subject).placeholder_names | Field( self.content).placeholder_names
def test_handling_of_missing_values(content, values, expected): assert str(Field(content, values)) == expected
def missing_data(self): return list( placeholder_name for placeholder_name in Field(self.content).placeholder_names if self.values.get(placeholder_name) is None)
def placeholders(self): # TODO: rename to placeholder_names return Field(self.content).placeholder_names