Example #1
0
def put_css_in_file(html_message, journal_name):
    """
    Retrieve the CSS of the journal and insert/inline it in the <head>
    section of the given html_message. (Used for HTML alert emails)

    Parameters:
          journal_name  -  the journal name
          html_message  -  the html message (string) in which the CSS
                           should be inserted
    Returns:
          the HTML message with its CSS inlined
    """
    css_path = get_journal_css_url(journal_name)
    if not css_path:
        return
    css_file = WEBJOURNAL_OPENER.open(css_path)
    css = css_file.read()
    css = make_full_paths_in_css(css, journal_name)
    html_parted = html_message.split("</head>")
    if len(html_parted) > 1:
        html = '%s<style type="text/css">%s</style></head>%s' % (html_parted[0],
                                                        css,
                                                        html_parted[1])
    else:
        html_parted = html_message.split("<html>")
        if len(html_parted) > 1:
            html = '%s<html><head><style type="text/css">%s</style></head>%s' % (html_parted[0],
                                                                                 css,
                                                                                 html_parted[1])
        else:
            return
    return html
Example #2
0
def put_css_in_file(html_message, journal_name):
    """
    Retrieve the CSS of the journal and insert/inline it in the <head>
    section of the given html_message. (Used for HTML alert emails)

    Parameters:
          journal_name  -  the journal name
          html_message  -  the html message (string) in which the CSS
                           should be inserted
    Returns:
          the HTML message with its CSS inlined
    """
    css_path = get_journal_css_url(journal_name)
    if not css_path:
        return
    css_file = WEBJOURNAL_OPENER.open(css_path)
    css = css_file.read()
    css = make_full_paths_in_css(css, journal_name)
    html_parted = html_message.split("</head>")
    if len(html_parted) > 1:
        html = '%s<style type="text/css">%s</style></head>%s' % (html_parted[0],
                                                        css,
                                                        html_parted[1])
    else:
        html_parted = html_message.split("<html>")
        if len(html_parted) > 1:
            html = '%s<html><head><style type="text/css">%s</style></head>%s' % (html_parted[0],
                                                                                 css,
                                                                                 html_parted[1])
        else:
            return
    return html
Example #3
0
def format_element(bfo, var=''):
    """
    Print several journal specific variables.
    @param var: the name of the desired variable. Can be one of: WEBJOURNAL_CSS_URL, WEBJOURNAL_NAME, WEBJOURNAL_NAME_INTL, WEBJOURNAL_CURRENT_ISSUE_NUMBER, WEBJOURNAL_ISSUE_NUMBER, WEBJOURNAL_URL
    """
    args = parse_url_string(bfo.user_info['uri'])
    journal_name = args["journal_name"]
    this_issue_number = args["issue"]

    if var == '':
        out = ''
    elif var == 'WEBJOURNAL_NAME':
        out = journal_name
    elif var == 'WEBJOURNAL_NAME_INTL':
        out = get_journal_name_intl(journal_name, bfo.lang)
    elif var == 'WEBJOURNAL_ISSUE_NUMBER':
        out = this_issue_number
    elif var == 'WEBJOURNAL_CURRENT_ISSUE_NUMBER':
        out = get_current_issue(bfo.lang, journal_name)
    elif var == 'WEBJOURNAL_URL':
        out = make_journal_url(bfo.user_info['uri'], {'ln': bfo.lang})
    elif var == 'WEBJOURNAL_CSS_URL':
        out = get_journal_css_url(journal_name)
    elif var == 'WEBJOURNAL_USER_LANG':
        out = bfo.lang

    return out
Example #4
0
def format_element(bfo, var=''):
    """
    Print several journal specific variables.
    @param var: the name of the desired variable. Can be one of: WEBJOURNAL_CSS_URL, WEBJOURNAL_NAME, WEBJOURNAL_NAME_INTL, WEBJOURNAL_CURRENT_ISSUE_NUMBER, WEBJOURNAL_ISSUE_NUMBER, WEBJOURNAL_URL
    """
    args = parse_url_string(bfo.user_info['uri'])
    journal_name = args["journal_name"]
    this_issue_number = args["issue"]

    if var == '':
        out =  ''
    elif var == 'WEBJOURNAL_NAME':
        out = journal_name
    elif var == 'WEBJOURNAL_NAME_INTL':
        out = get_journal_name_intl(journal_name, bfo.lang)
    elif var == 'WEBJOURNAL_ISSUE_NUMBER':
        out = this_issue_number
    elif var == 'WEBJOURNAL_CURRENT_ISSUE_NUMBER':
        out = get_current_issue(bfo.lang, journal_name)
    elif var == 'WEBJOURNAL_URL':
        out = make_journal_url(bfo.user_info['uri'], {'ln': bfo.lang})
    elif var == 'WEBJOURNAL_CSS_URL':
        out = get_journal_css_url(journal_name)
    elif var == 'WEBJOURNAL_USER_LANG':
        out = bfo.lang

    return out