def test_get_journal_preferred_language(self):
     """webjournal - returns the most adequate language to display the
     journal, given a language """
     value = wju.get_journal_preferred_language('AtlantisTimes', 'fr')
     self.assertEqual(value, 'fr')
     value = wju.get_journal_preferred_language('AtlantisTimes', 'it')
     self.assertEqual(value, 'en')
     value = wju.get_journal_preferred_language('AtlantisTimes', 'hello')
     self.assertEqual(value, 'en')
 def test_get_journal_preferred_language(self):
     """webjournal - returns the most adequate language to display the
     journal, given a language """
     value = wju.get_journal_preferred_language('AtlantisTimes', 'fr')
     self.assertEqual(value, 'fr')
     value = wju.get_journal_preferred_language('AtlantisTimes', 'it')
     self.assertEqual(value, 'en')
     value = wju.get_journal_preferred_language('AtlantisTimes', 'hello')
     self.assertEqual(value, 'en')
 def test_get_journal_preferred_language(self):
     """webjournal - returns the most adequate language to display the
     journal, given a language """
     value = wju.get_journal_preferred_language("AtlantisTimes", "fr")
     self.assertEqual(value, "fr")
     value = wju.get_journal_preferred_language("AtlantisTimes", "it")
     self.assertEqual(value, "en")
     value = wju.get_journal_preferred_language("AtlantisTimes", "hello")
     self.assertEqual(value, "en")
def format_element(bfo):
    """
    Formats a header used in Bulletin Articles containing: issue nr., date,
    english/french link, report number
    """
    # get variables
    this_recid = bfo.control_field('001')
    available_languages = bfo.fields('041__a')
    current_language = bfo.lang
    report_number = bfo.fields('037__a')
    issue_numbers = bfo.fields('773__n')
    journal_name = bfo.field('773__t')
    if journal_name.lower() == 'cern bulletin':
        journal_name = 'CERNBulletin'
    elif journal_name.lower() == 'cms bulletin':
        journal_name = 'CMSBulletin'

    preferred_ln = get_journal_preferred_language(journal_name, bfo.lang)

    date = ''
    if len(issue_numbers) > 0:
#        date = get_release_datetime(issue_numbers[0], journal_name)
#        if not date:
        date = issue_to_datetime(issue_numbers[0], journal_name)
        weekday = get_i18n_day_name(date.isoweekday() % 7)
        monthname = get_i18n_month_name(date.month)
        date  = weekday + ' ' + date.strftime('%d') + ' ' + monthname + ' ' + date.strftime('%Y')

    # assemble the HTML output
    out = '<div id="top"><div id="topbanner">&nbsp;</div>'
    if len(issue_numbers) > 0:
        out += '<span class="printLogo">%s, %s</span>' % (" & ".join(["%s" % issue.split("/")[0] for issue in issue_numbers]), date)
    out += '<div id="mainmenu"><table width="100%">'
    out += '<tr>'
    if len(issue_numbers) > 0:
        issue_number, issue_year = issue_numbers[-1].split('/')
        out += '<td class="left"><a href="%s/journal/CERNBulletin/%s/%s" target="_blank">%s: %s, %s</a></td>' % \
               (CFG_SITE_URL, issue_year, issue_number,
                cfg_messages["published_in"][preferred_ln],
                " & ".join(["%s" % issue for issue in issue_numbers]),
                date)
    if len(report_number) > 0:
        out += '<td class="right">%s</td>' % report_number[0]
    out += '</tr>'

    out += '<tr>'
    if len(available_languages) > 1:
        if current_language == "en" and "fr" in available_languages:
            #TODO: server name generic
            out += '<td class="left"><a href="%s/record/%s?ln=fr">&gt;&gt; french version</a></td>' % (CFG_SITE_URL, this_recid)
        elif current_language == "fr" and "en" in available_languages:
            out += '<td class="left"><a href="%s/record/%s?ln=en">&gt;&gt; version anglaise</a></td>' % (CFG_SITE_URL, this_recid)

    out += '<td class="right"></td>'
    out += '</tr>'
    out += '</table></div><div id="mainphoto"></div></div>'

    return out