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 nl2br(value):
    if value:
        return Markup(Take(Field(
            value,
            html='escape',
        )).then(utils_nl2br))
    return ''
    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)
            }))
Exemple #4
0
 def subject(self):
     return Take(
         Field(self._subject,
               self.values,
               html='escape',
               redact_missing_personalisation=self.
               redact_missing_personalisation)).then(do_nice_typography)
Exemple #5
0
def nl2br(value):
    if value:
        return Markup(
            Take(Field(
                value,
                html='escape',
            )).then(formatters.nl2br))
    return ''
 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)
Exemple #7
0
def get_html_email_body(template_content, template_values):

    return Take.as_field(template_content,
                         template_values,
                         html='escape',
                         markdown_lists=True).then(unlink_govuk_escaped).then(
                             prepare_newlines_for_markdown).then(
                                 notify_email_markdown).as_string
 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)
Exemple #9
0
 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 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))
Exemple #11
0
def do_nice_typography(value):
    return Take(
        value
    ).then(
        remove_whitespace_before_punctuation
    ).then(
        make_quotes_smart
    ).then(
        replace_hyphens_with_en_dashes
    )
 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 _get_unsanitised_content(self):
     # This is faster to call than __str__ if all you need to know is
     # how many characters are in the message
     return Take(
         PlainTextField(
             self.content, self.values,
             html='passthrough')).then(add_prefix, self.prefix).then(
                 remove_whitespace_before_punctuation).then(
                     normalise_whitespace_and_newlines).then(
                         normalise_multiple_newlines).then(str.strip)
 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 test_take():
    assert 'Service name: HELLO WORLD!' == Take(
        'hello world'
    ).then(
        _uppercase
    ).then(
        _append, '!'
    ).then(
        _prepend_with_service_name, service_name='Service name'
    ).as_string
Exemple #16
0
 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 ""
Exemple #17
0
def guess_name_from_email_address(email_address):

    possible_name = re.split(r"[\@\+]", email_address)[0]

    if "." not in possible_name or starts_with_initial(possible_name):
        return ""

    return (Take(possible_name).then(
        str.replace, ".",
        " ").then(remove_digits).then(remove_middle_initial).then(
            str.title).then(make_quotes_smart).then(normalize_spaces))
Exemple #18
0
def guess_name_from_email_address(email_address):

    possible_name = re.split(r'[\@\+]', email_address)[0]

    if '.' not in possible_name or starts_with_initial(possible_name):
        return ''

    return Take(possible_name).then(
        str.replace, '.',
        ' ').then(remove_digits).then(remove_middle_initial).then(
            str.title).then(make_quotes_smart).then(normalize_spaces)
    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 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 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 _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 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)
Exemple #24
0
 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.as_field(
                 strip_dvla_markup(self.content),
                 self.values,
                 html='escape',
                 markdown_lists=True).then(strip_pipes).then(
                     prepare_newlines_for_markdown).then(
                         notify_letter_preview_markdown).as_string,
             'address':
             Take.as_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(nl2br).as_string,
             'contact_block':
             Take.as_field(
                 '\n'.join(line.strip()
                           for line in self.contact_block.split('\n')),
                 self.values,
                 html='escape',
             ).then(nl2br).then(strip_pipes).as_string,
             'date':
             datetime.utcnow().strftime('%-d %B %Y')
         }))
 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)
Exemple #26
0
 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 _get_unsanitised_content(self):
     # This is faster to call than SMSMessageTemplate.__str__ if all
     # you need to know is how many characters are in the message
     if self.values:
         values = self.values
     else:
         values = {key: MAGIC_SEQUENCE for key in self.placeholders}
     return Take(PlainTextField(
         self.content, values, html='passthrough')).then(
             add_prefix,
             self.prefix).then(remove_whitespace_before_punctuation).then(
                 normalise_whitespace_and_newlines).then(
                     normalise_multiple_newlines).then(str.strip).then(
                         str.replace, MAGIC_SEQUENCE, '')
Exemple #28
0
    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
            }))
Exemple #29
0
 def subject(self):
     return Take.as_field(
         self._subject, self.values,
         html='escape').then(strip_pipes).then(strip_dvla_markup).as_string
Exemple #30
0
    def __str__(self):

        OTT = '140'
        ORG_ID = self.org_id
        ORG_NOTIFICATION_TYPE = '001'
        ORG_NAME = ''
        NOTIFICATION_ID = self.notification_reference
        NOTIFICATION_DATE = ''
        CUSTOMER_REFERENCE = ''
        ADDITIONAL_LINE_1, \
            ADDITIONAL_LINE_2, \
            ADDITIONAL_LINE_3, \
            ADDITIONAL_LINE_4, \
            ADDITIONAL_LINE_5, \
            ADDITIONAL_LINE_6, \
            ADDITIONAL_LINE_7, \
            ADDITIONAL_LINE_8, \
            ADDITIONAL_LINE_9, \
            ADDITIONAL_LINE_10 = [
                line.strip()
                for line in
                ((
                    Take.as_field(self.contact_block, self.values, html='strip_dvla_markup')
                ).as_string.split('\n') + ([''] * 10))
            ][:10]
        TO_NAME_1,\
            _,\
            TO_ADDRESS_LINE_1,\
            TO_ADDRESS_LINE_2,\
            TO_ADDRESS_LINE_3,\
            TO_ADDRESS_LINE_4,\
            TO_ADDRESS_LINE_5,\
            TO_POST_CODE, = str(Field(
                self.address_block,
                self.values_with_default_optional_address_lines,
            )).split('\n')
        TO_NAME_2 = ''
        RETURN_NAME = ''
        RETURN_ADDRESS_LINE_1 = ''
        RETURN_ADDRESS_LINE_2 = ''
        RETURN_ADDRESS_LINE_3 = ''
        RETURN_ADDRESS_LINE_4 = ''
        RETURN_ADDRESS_LINE_5 = ''
        RETURN_POST_CODE = ''
        SUBJECT_LINE = ''
        NOTIFICATION_BODY = (
            '{}<cr><cr>'
            '<h1>{}<normal><cr><cr>'
            '{}'
        ).format(
            datetime.utcnow().strftime('%-d %B %Y'), self.subject,
            Take.as_field(
                self.content,
                self.values,
                markdown_lists=True,
                html='strip_dvla_markup').then(prepare_newlines_for_markdown).
            then(notify_letter_dvla_markdown).then(
                fix_extra_newlines_in_dvla_lists).as_string)

        return '|'.join(
            strip_pipes(line) for line in [
                OTT,
                ORG_ID,
                ORG_NOTIFICATION_TYPE,
                ORG_NAME,
                NOTIFICATION_ID,
                NOTIFICATION_DATE,
                CUSTOMER_REFERENCE,
                ADDITIONAL_LINE_1,
                ADDITIONAL_LINE_2,
                ADDITIONAL_LINE_3,
                ADDITIONAL_LINE_4,
                ADDITIONAL_LINE_5,
                ADDITIONAL_LINE_6,
                ADDITIONAL_LINE_7,
                ADDITIONAL_LINE_8,
                ADDITIONAL_LINE_9,
                ADDITIONAL_LINE_10,
                TO_NAME_1,
                TO_NAME_2,
                TO_ADDRESS_LINE_1,
                TO_ADDRESS_LINE_2,
                TO_ADDRESS_LINE_3,
                TO_ADDRESS_LINE_4,
                TO_ADDRESS_LINE_5,
                TO_POST_CODE,
                RETURN_NAME,
                RETURN_ADDRESS_LINE_1,
                RETURN_ADDRESS_LINE_2,
                RETURN_ADDRESS_LINE_3,
                RETURN_ADDRESS_LINE_4,
                RETURN_ADDRESS_LINE_5,
                RETURN_POST_CODE,
                SUBJECT_LINE,
                NOTIFICATION_BODY,
            ])