def test_get_announcement_datetime(self):
     """webjournal - get the date at which an issue was announced through
     the alert system"""
     value = wju.get_announcement_datetime('03/2009',
                                           'AtlantisTimes',
                                           ln=CFG_SITE_LANG)
     self.assertEqual(value, None)
    def tmpl_admin_administrate(self,
                                journal_name,
                                current_issue,
                                current_publication,
                                issue_list,
                                next_issue_number,
                                ln=CFG_SITE_LANG,
                                as_editor=True):
        """
        Returns an administration interface that shows the current publication and
        supports links to all important actions.

        @param as_editor: True if can make changes to the configuration. Else read-only mode.
        """
        _ = gettext_set_language(ln)
        out = ''

        if as_editor:
            admin_menu = '''<table class="admin_wvar">
            <tr><th colspan="5" class="adminheaderleft" cellspacing="0">%(menu)s</th></tr>
            <tr>
            <td>0.&nbsp;<small>Administrate</small>&nbsp;</td>
            <td>1.&nbsp;<small><a href="feature_record?journal_name=%(journal_name)s">Feature a Record</a></small>&nbsp;</td>
            <td>2.&nbsp;<small><a href="configure?action=edit&amp;journal_name=%(journal_name)s">Edit Configuration</a></small>&nbsp;</td>
            <td>3.&nbsp;<small><a href="%(CFG_SITE_URL)s/journal/%(journal_name)s">Go to the Journal</a></small>&nbsp;</td>
            </tr>
            </table><br/>'''
        else:
            admin_menu = '''<table class="admin_wvar">
            <tr><th colspan="5" class="adminheaderleft" cellspacing="0">%(menu)s</th></tr>
            <tr>
            <td>0.&nbsp;<small>Administrate</small>&nbsp;</td>
            <td>1.&nbsp;<small><a href="%(CFG_SITE_URL)s/journal/%(journal_name)s">Go to the Journal</a></small>&nbsp;</td>
            </tr>
            </table><br/>'''

        out += admin_menu % {
            'journal_name': journal_name,
            'menu': _("Menu"),
            'CFG_SITE_URL': CFG_SITE_URL
        }

        # format the issues
        issue_boxes = []
        issue_list.append(next_issue_number)
        for issue in issue_list:
            articles = get_number_of_articles_for_issue(
                issue, journal_name, ln)
            released_on = get_release_datetime(issue, journal_name, ln)
            announced_on = get_announcement_datetime(issue, journal_name, ln)
            issue_box = '''
                <tr style="%s">
                    <td class="admintdright" style="vertical-align: middle;"></td>
                    <td class="admintdleft" style="white-space: nowrap; vertical-align: middle;">
                        <p>Issue: %s</p>
                        <p>Publication: %s</p>
                    </td>
                    <td class="admintdright" style="vertical-align: middle;">
                        %s
                    </td>
                    <td class="admintdright" style="vertical-align: middle;">
                        <p>%s</p>
                        <p>%s</p>
                    </td>
                    <td class="admintdright" style="vertical-align: middle;">
                        <p><a href="%s/admin/webjournal/webjournaladmin.py/regenerate?journal_name=%s&amp;issue=%s&amp;ln=%s">&gt;regenerate</a></p>
                    </td>
                <tr>
            ''' % ((issue==current_issue) and "background:#00FF00;" or "background:#F1F1F1;",

                    issue, (issue==next_issue_number) and "?" or current_publication,

                    "\n".join(['<p>%s : %s <a href="%s/journal/%s/%s/%s/%s">&gt;view</a></p>' %
                               (item[0], item[1],
                                CFG_SITE_URL, journal_name,
                                issue.split('/')[1], issue.split('/')[0], item[0]) \
                               for item in articles.iteritems()]),

                    (not released_on) and
                    ('<em>not released</em>' + (as_editor and '<br/><a href="%s/admin/webjournal/webjournaladmin.py/issue_control?journal_name=%s">&gt;release now</a>' % (CFG_SITE_URL, journal_name) or '')) or
                    'released on: %s' % released_on.strftime("%d.%m.%Y"),

                    (not announced_on)
                    and ('<em>not announced</em>' + (as_editor and '<br/><a href="%s/admin/webjournal/webjournaladmin.py/alert?journal_name=%s&issue=%s">&gt;announce now</a>' % (CFG_SITE_URL, journal_name, issue) or '')) or
                    'announced on: %s <br/><a href="%s/admin/webjournal/webjournaladmin.py/alert?journal_name=%s&issue=%s">&gt;re-announce</a>' % (announced_on.strftime("%d.%m.%Y"), CFG_SITE_URL, journal_name, issue),

                    CFG_SITE_URL, journal_name, issue, ln
                )
            issue_boxes.append(issue_box)
        out += '''
                 <table class="admin_wvar" width="80%%" cellspacing="0">
                    <tbody>
                        <tr>
                            <th class="adminheaderleft"></th>
                            <th class="adminheaderleft">Issue / Publication</th>
                            <th class="adminheader">Articles</th>
                            <th class="adminheaderleft">Release / Announcement</th>
                            <th class="adminheaderleft">Cache Status</th>
                        <tr>
                        %s
                    </tbody>
                 </table>
                 ''' % ("\n".join([issue_box for issue_box in issue_boxes]))

        return out
    def tmpl_admin_administrate(
        self,
        journal_name,
        current_issue,
        current_publication,
        issue_list,
        next_issue_number,
        ln=CFG_SITE_LANG,
        as_editor=True,
    ):
        """
        Returns an administration interface that shows the current publication and
        supports links to all important actions.

        @param as_editor: True if can make changes to the configuration. Else read-only mode.
        """
        _ = gettext_set_language(ln)
        out = ""

        if as_editor:
            admin_menu = """<table class="admin_wvar">
            <tr><th colspan="5" class="adminheaderleft" cellspacing="0">%(menu)s</th></tr>
            <tr>
            <td>0.&nbsp;<small>Administrate</small>&nbsp;</td>
            <td>1.&nbsp;<small><a href="feature_record?journal_name=%(journal_name)s">Feature a Record</a></small>&nbsp;</td>
            <td>2.&nbsp;<small><a href="configure?action=edit&amp;journal_name=%(journal_name)s">Edit Configuration</a></small>&nbsp;</td>
            <td>3.&nbsp;<small><a href="%(CFG_SITE_URL)s/journal/%(journal_name)s">Go to the Journal</a></small>&nbsp;</td>
            </tr>
            </table><br/>"""
        else:
            admin_menu = """<table class="admin_wvar">
            <tr><th colspan="5" class="adminheaderleft" cellspacing="0">%(menu)s</th></tr>
            <tr>
            <td>0.&nbsp;<small>Administrate</small>&nbsp;</td>
            <td>1.&nbsp;<small><a href="%(CFG_SITE_URL)s/journal/%(journal_name)s">Go to the Journal</a></small>&nbsp;</td>
            </tr>
            </table><br/>"""

        out += admin_menu % {"journal_name": journal_name, "menu": _("Menu"), "CFG_SITE_URL": CFG_SITE_URL}

        # format the issues
        issue_boxes = []
        issue_list.append(next_issue_number)
        for issue in issue_list:
            articles = get_number_of_articles_for_issue(issue, journal_name, ln)
            released_on = get_release_datetime(issue, journal_name, ln)
            announced_on = get_announcement_datetime(issue, journal_name, ln)
            issue_box = """
                <tr style="%s">
                    <td class="admintdright" style="vertical-align: middle;"></td>
                    <td class="admintdleft" style="white-space: nowrap; vertical-align: middle;">
                        <p>Issue: %s</p>
                        <p>Publication: %s</p>
                    </td>
                    <td class="admintdright" style="vertical-align: middle;">
                        %s
                    </td>
                    <td class="admintdright" style="vertical-align: middle;">
                        <p>%s</p>
                        <p>%s</p>
                    </td>
                    <td class="admintdright" style="vertical-align: middle;">
                        <p><a href="%s/admin/webjournal/webjournaladmin.py/regenerate?journal_name=%s&amp;issue=%s&amp;ln=%s">&gt;regenerate</a></p>
                    </td>
                <tr>
            """ % (
                (issue == current_issue) and "background:#00FF00;" or "background:#F1F1F1;",
                issue,
                (issue == next_issue_number) and "?" or current_publication,
                "\n".join(
                    [
                        '<p>%s : %s <a href="%s/journal/%s/%s/%s/%s">&gt;view</a></p>'
                        % (
                            item[0],
                            item[1],
                            CFG_SITE_URL,
                            journal_name,
                            issue.split("/")[1],
                            issue.split("/")[0],
                            item[0],
                        )
                        for item in articles.iteritems()
                    ]
                ),
                (not released_on)
                and (
                    "<em>not released</em>"
                    + (
                        as_editor
                        and '<br/><a href="%s/admin/webjournal/webjournaladmin.py/issue_control?journal_name=%s">&gt;release now</a>'
                        % (CFG_SITE_URL, journal_name)
                        or ""
                    )
                )
                or "released on: %s" % released_on.strftime("%d.%m.%Y"),
                (not announced_on)
                and (
                    "<em>not announced</em>"
                    + (
                        as_editor
                        and '<br/><a href="%s/admin/webjournal/webjournaladmin.py/alert?journal_name=%s&issue=%s">&gt;announce now</a>'
                        % (CFG_SITE_URL, journal_name, issue)
                        or ""
                    )
                )
                or 'announced on: %s <br/><a href="%s/admin/webjournal/webjournaladmin.py/alert?journal_name=%s&issue=%s">&gt;re-announce</a>'
                % (announced_on.strftime("%d.%m.%Y"), CFG_SITE_URL, journal_name, issue),
                CFG_SITE_URL,
                journal_name,
                issue,
                ln,
            )
            issue_boxes.append(issue_box)
        out += """
                 <table class="admin_wvar" width="80%%" cellspacing="0">
                    <tbody>
                        <tr>
                            <th class="adminheaderleft"></th>
                            <th class="adminheaderleft">Issue / Publication</th>
                            <th class="adminheader">Articles</th>
                            <th class="adminheaderleft">Release / Announcement</th>
                            <th class="adminheaderleft">Cache Status</th>
                        <tr>
                        %s
                    </tbody>
                 </table>
                 """ % (
            "\n".join([issue_box for issue_box in issue_boxes])
        )

        return out
 def test_get_announcement_datetime(self):
     """webjournal - get the date at which an issue was announced through
     the alert system"""
     value = wju.get_announcement_datetime('03/2009', 'AtlantisTimes', ln=CFG_SITE_LANG)
     self.assertEqual(value, None)