Пример #1
0
def perform_request_alert(
    journal_name, issue, sent, plain_text, subject, recipients, html_mail, force, ln=CFG_SITE_LANG
):
    """
    All the logic for alert emails.

    Display a form to edit email/recipients and options to send the
    email.  Sent in HTML/PlainText or only PlainText if wished so.
    Also prevent mistake of sending the alert more than one for a
    particular issue.

    Parameters:
        journal_name  -  the journal for which the alert is sent
               issue  -  the issue for which the alert is sent
                sent  -  Display interface to edit email if "False"
                         (string). Else send the email.
          plain_text  -  the text of the mail
             subject  -  the subject of the mail
          recipients  -  the recipients of the mail (string with
                         comma-separated emails)
           html_mail  -  if 'html', also send email as HTML (copying
                         from the current issue on the web)
               force  -  if different than "False", the email is sent
                         even if it has already been sent.
                  ln  -  language
    """
    # FIXME: more flexible options to choose the language of the alert
    languages = get_journal_languages(journal_name)
    if languages:
        alert_ln = languages[0]
    else:
        alert_ln = CFG_SITE_LANG

    if not get_release_datetime(issue, journal_name, ln):
        # Trying to send an alert for an unreleased issue
        return wjt.tmpl_admin_alert_unreleased_issue(ln, journal_name)
    if sent == "False":
        # Retrieve default message, subject and recipients, and
        # display email editor
        subject = wjt.tmpl_admin_alert_subject(journal_name, alert_ln, issue)
        plain_text = wjt.tmpl_admin_alert_plain_text(journal_name, alert_ln, issue)
        plain_text = plain_text.encode("utf-8")
        recipients = get_journal_alert_recipient_email(journal_name)
        return wjt.tmpl_admin_alert_interface(ln, journal_name, subject, plain_text, recipients, alert_ln)
    else:
        # User asked to send the mail
        if was_alert_sent_for_issue(issue, journal_name, ln) != False and force == "False":
            # Mmh, email already sent before for this issue. Ask
            # confirmation
            return wjt.tmpl_admin_alert_was_already_sent(
                ln, journal_name, subject, plain_text, recipients, html_mail, issue
            )
        html_string = None
        if html_mail == "html":
            # Also send as HTML: retrieve from current issue
            html_file = urlopen("%s/journal/%s?ln=%s" % (CFG_SITE_URL, journal_name, alert_ln))
            html_string = html_file.read()
            html_file.close()
            html_string = put_css_in_file(html_string, journal_name)
            html_string = insert_journal_link(html_string, journal_name, issue, ln)

        sender_email = get_journal_alert_sender_email(journal_name)
        send_email(
            sender_email,
            recipients,
            subject,
            plain_text,
            html_string,
            header="",
            footer="",
            html_header="",
            html_footer="",
            charset="utf-8",
        )

        update_DB_for_alert(issue, journal_name, ln)
        return wjt.tmpl_admin_alert_success_msg(ln, journal_name)
 def test_get_journal_languages(self):
     """webjournal - returns the list of languages defined for this journal"""
     lang = wju.get_journal_languages('AtlantisTimes')
     self.assertEqual(lang[0], 'en')
     self.assertEqual(lang[1], 'fr')
Пример #3
0
def perform_request_alert(journal_name,
                          issue,
                          sent,
                          plain_text,
                          subject,
                          recipients,
                          html_mail,
                          force,
                          ln=CFG_SITE_LANG):
    """
    All the logic for alert emails.

    Display a form to edit email/recipients and options to send the
    email.  Sent in HTML/PlainText or only PlainText if wished so.
    Also prevent mistake of sending the alert more than one for a
    particular issue.

    Parameters:
        journal_name  -  the journal for which the alert is sent
               issue  -  the issue for which the alert is sent
                sent  -  Display interface to edit email if "False"
                         (string). Else send the email.
          plain_text  -  the text of the mail
             subject  -  the subject of the mail
          recipients  -  the recipients of the mail (string with
                         comma-separated emails)
           html_mail  -  if 'html', also send email as HTML (copying
                         from the current issue on the web)
               force  -  if different than "False", the email is sent
                         even if it has already been sent.
                  ln  -  language
    """
    # FIXME: more flexible options to choose the language of the alert
    languages = get_journal_languages(journal_name)
    if languages:
        alert_ln = languages[0]
    else:
        alert_ln = CFG_SITE_LANG

    if not get_release_datetime(issue, journal_name, ln):
        # Trying to send an alert for an unreleased issue
        return wjt.tmpl_admin_alert_unreleased_issue(ln, journal_name)
    if sent == "False":
        # Retrieve default message, subject and recipients, and
        # display email editor
        subject = wjt.tmpl_admin_alert_subject(journal_name, alert_ln, issue)
        plain_text = wjt.tmpl_admin_alert_plain_text(journal_name, alert_ln,
                                                     issue)
        plain_text = plain_text.encode('utf-8')
        recipients = get_journal_alert_recipient_email(journal_name)
        return wjt.tmpl_admin_alert_interface(ln, journal_name, subject,
                                              plain_text, recipients, alert_ln)
    else:
        # User asked to send the mail
        if was_alert_sent_for_issue(issue, journal_name,
                                    ln) != False and force == "False":
            # Mmh, email already sent before for this issue. Ask
            # confirmation
            return wjt.tmpl_admin_alert_was_already_sent(
                ln, journal_name, subject, plain_text, recipients, html_mail,
                issue)
        html_string = None
        if html_mail == "html":
            # Also send as HTML: retrieve from current issue
            html_file = WEBJOURNAL_OPENER.open(
                '%s/journal/%s?ln=%s' % (CFG_SITE_URL, journal_name, alert_ln))
            html_string = html_file.read()
            html_file.close()
            html_string = put_css_in_file(html_string, journal_name)
            html_string = insert_journal_link(html_string, journal_name, issue,
                                              ln)
            html_string = wash_alert(html_string)

        sender_email = get_journal_alert_sender_email(journal_name)
        send_email(sender_email,
                   recipients,
                   subject,
                   plain_text,
                   html_string,
                   header='',
                   footer='',
                   html_header='',
                   html_footer='',
                   charset='utf-8')

        update_DB_for_alert(issue, journal_name, ln)
        return wjt.tmpl_admin_alert_success_msg(ln, journal_name)
 def test_get_journal_languages(self):
     """webjournal - returns the list of languages defined for this journal"""
     lang = wju.get_journal_languages('AtlantisTimes')
     self.assertEqual(lang[0], 'en')
     self.assertEqual(lang[1], 'fr')
Пример #5
0
 def test_get_journal_languages(self):
     """webjournal - returns the list of languages defined for this journal"""
     lang = wju.get_journal_languages("AtlantisTimes")
     self.assertEqual(lang[0], "en")
     self.assertEqual(lang[1], "fr")