def _get_substitutions(to, comment=None, idea=None, fi=None, previous_di=None, comment_author=None, **kw):

    # initialize useful values for substitutions
    base_url = get_url_service().base_url
    shop_url = get_url_service().expand_url(['shop'], relative=False)
    idea_url = get_url_service().expand_url(['idea', idea.id], relative=False) if idea else u''

    fi = fi or (idea.wf_context.assignated_fi if idea else None)
    di = idea.wf_context.assignated_di if idea else None

    mailer = mail.get_mailer()

    # creates the substitutions
    substitutions = {
        u'RECIPIENT_LOGIN': to.uid if to else u'',
        u'RECIPIENT_FIRSTNAME': to.firstname if to else u'',
        u'RECIPIENT_LASTNAME': to.lastname if to else u'',
        u'RECIPIENT_EMAIL': to.email or u'' if to else u'',

        u'FI_FIRSTNAME': fi.firstname if fi else u'',
        u'FI_LASTNAME': fi.lastname if fi else u'',
        u'FI_EMAIL': fi.email if fi and fi.email else u'',

        u'DI_FIRSTNAME': di.firstname if di else u'',
        u'DI_LASTNAME': di.lastname if di else u'',
        u'DI_EMAIL': di.email if di and di.email else u'',

        u'IDEA_ID': str(idea.id) if idea else u'',
        u'IDEA_TITLE': text_to_html(idea.title) if idea else u'',
        u'IDEA_LINK_HERE': render_link(_(u'here'), idea_url),

        u'SUBMISSION_DATE': format_date(datetime.today(), format='medium'),
        u'COMMENT': text_to_html(comment or u''),

        u'COMMENT_AUTHOR_FIRSTNAME': comment_author.firstname if comment_author else '',
        u'COMMENT_AUTHOR_LASTNAME': comment_author.lastname if comment_author else '',

        u'EUREKA_LINK': render_link(_(u'Eurêka'), base_url),
        u'EUREKA_URL_LINK': render_link(base_url, base_url),
        u'SHOP_LINK': render_link(_(u'shop'), shop_url),

        u'PREVIOUS_DI_EMAIL': (previous_di.email if (previous_di and previous_di.email) else u''),
        u'PREVIOUS_DI_FIRSTNAME': (previous_di.firstname if (previous_di and previous_di.firstname) else u''),
        u'PREVIOUS_DI_LASTNAME': (previous_di.lastname if (previous_di and previous_di.lastname) else u''),
    }

    substitutions.update(mailer.get_substitutions())

    substitutions.update({k.upper(): v for k, v in kw.iteritems()})

    return substitutions
Exemple #2
0
 def test_text_to_html(self):
     # iso-transform when there's nothing special
     self.assertEquals('Text',
                       text_to_html('Text'))
     # we escape special html chars and do not let html tags pass
     self.assertEquals('David & Goliath',
                       text_to_html('David & Goliath'))
     self.assertEquals('<script>I am a hacker</script>',
                       text_to_html('<script>I am a hacker</script>'))
     # we deal with end of line characters
     self.assertEquals('First line<br/>Second line',
                       text_to_html('First line\nSecond line'))
     # we detect urls and transform them to <a> tags
     self.assertEquals('A http link <a href="http://www.google.fr">http://www.google.fr</a> with trailing text',
                       text_to_html('A http link http://www.google.fr with trailing text'))
     self.assertEquals('A https link <a href="https://www.google.fr">https://www.google.fr</a> with trailing text',
                       text_to_html('A https link https://www.google.fr with trailing text'))
     self.assertEquals(u'Le site &quot;<a href="http://www.google.fr">http://www.google.fr</a>&quot; est très bien',
                       text_to_html(u'Le site "http://www.google.fr" est très bien'))
     self.assertEquals('<a href="http://www.google.fr/site-production?param=valeur&amp;truc=muche">http://www.google.fr/site-production?param=valeur&amp;truc=muche</a>',
                       text_to_html('http://www.google.fr/site-production?param=valeur&truc=muche'))
     self.assertEquals('Url with port <a href="http://localhost:8080">http://localhost:8080</a> and with trailing text',
                       text_to_html('Url with port http://localhost:8080 and with trailing text'))
     self.assertEquals('Url with port <a href="http://localhost:8080/blabla,toto">http://localhost:8080/blabla,toto</a> and with trailing text',
                       text_to_html('Url with port http://localhost:8080/blabla,toto and with trailing text'))
     self.assertEquals('Url with port <a href="http://localhost:8080/blabla">http://localhost:8080/blabla</a>, and with trailing text',
                       text_to_html('Url with port http://localhost:8080/blabla, and with trailing text'))