Пример #1
0
def perform_request_index(req, journal_name, issue_number, ln, category, editor=False, verbose=0):
    """
    Central logic function for index pages.
    Brings together format templates and MARC rules from the config, with
    the requested index page, given by the url parameters.
    From config:
        - page template for index pages -> formatting
        - MARC rule list -> Category Navigation
        - MARC tag used for issue numbers -> search (later in the format
          elements)
    Uses BibFormatObject and format_with_format_template to produce the
    required HTML.
    """
    current_issue = get_current_issue(ln, journal_name)
    if not get_release_datetime(issue_number, journal_name):
        # Unreleased issue. Display latest released issue?
        unreleased_issues_mode = get_unreleased_issue_hiding_mode(journal_name)
        if not editor and (
            unreleased_issues_mode == "all"
            or (unreleased_issues_mode == "future" and issue_is_later_than(issue_number, current_issue))
        ):
            redirect_to_url(
                req,
                "%s/journal/%s/%s/%s?ln=%s"
                % (CFG_SITE_URL, journal_name, current_issue.split("/")[1], current_issue.split("/")[0], ln),
            )
    try:
        index_page_template = get_journal_template("index", journal_name, ln)
    except InvenioWebJournalTemplateNotFoundError, e:
        register_exception(req=req)
        return e.user_box(req)
Пример #2
0
def perform_request_article(req, journal_name, issue_number, ln, category, recid, editor=False, verbose=0):
    """
    Central logic function for article pages.
    Loads the format template for article display and displays the requested
    article using BibFormat.
    'Editor' mode generates edit links on the article view page and disables
    caching.
    """
    current_issue = get_current_issue(ln, journal_name)
    if not get_release_datetime(issue_number, journal_name):
        # Unreleased issue. Display latest released issue?
        unreleased_issues_mode = get_unreleased_issue_hiding_mode(journal_name)
        if not editor and (
            unreleased_issues_mode == "all"
            or (unreleased_issues_mode == "future" and issue_is_later_than(issue_number, current_issue))
        ):
            redirect_to_url(
                req,
                "%s/journal/%s/%s/%s?ln=%s"
                % (CFG_SITE_URL, journal_name, current_issue.split("/")[1], current_issue.split("/")[0], ln),
            )

    try:
        index_page_template = get_journal_template("detailed", journal_name, ln)
    except InvenioWebJournalTemplateNotFoundError, e:
        register_exception(req=req)
        return e.user_box(req)
Пример #3
0
def perform_request_index(req, journal_name, issue_number, ln,
                          category, editor=False, verbose=0):
    """
    Central logic function for index pages.
    Brings together format templates and MARC rules from the config, with
    the requested index page, given by the url parameters.
    From config:
        - page template for index pages -> formatting
        - MARC rule list -> Category Navigation
        - MARC tag used for issue numbers -> search (later in the format
          elements)
    Uses BibFormatObject and format_with_format_template to produce the
    required HTML.
    """
    current_issue = get_current_issue(ln, journal_name)
    if not get_release_datetime(issue_number, journal_name):
        # Unreleased issue. Display latest released issue?
        unreleased_issues_mode = get_unreleased_issue_hiding_mode(journal_name)
        if not editor and \
               (unreleased_issues_mode == 'all' or \
                (unreleased_issues_mode == 'future' and \
                 issue_is_later_than(issue_number, current_issue))):
            redirect_to_url(req, "%s/journal/%s/%s/%s?ln=%s" % \
                            (CFG_SITE_URL,
                             journal_name,
                             current_issue.split('/')[1],
                             current_issue.split('/')[0],
                             ln))
    try:
        index_page_template = get_journal_template('index',
                                                   journal_name,
                                                   ln)
    except InvenioWebJournalTemplateNotFoundError, e:
        register_exception(req=req)
        return e.user_box()
Пример #4
0
def perform_request_article(req, journal_name, issue_number, ln,
                            category, recid, editor=False, verbose=0):
    """
    Central logic function for article pages.
    Loads the format template for article display and displays the requested
    article using BibFormat.
    'Editor' mode generates edit links on the article view page and disables
    caching.
    """
    current_issue = get_current_issue(ln, journal_name)
    if not get_release_datetime(issue_number, journal_name):
        # Unreleased issue. Display latest released issue?
        unreleased_issues_mode = get_unreleased_issue_hiding_mode(journal_name)
        if not editor and \
               (unreleased_issues_mode == 'all' or \
                (unreleased_issues_mode == 'future' and \
                 issue_is_later_than(issue_number, current_issue))):
            redirect_to_url(req, "%s/journal/%s/%s/%s?ln=%s" % \
                            (CFG_SITE_URL,
                             journal_name,
                             current_issue.split('/')[1],
                             current_issue.split('/')[0],
                             ln))

    try:
        index_page_template = get_journal_template('detailed',
                                                   journal_name,
                                                   ln)
    except InvenioWebJournalTemplateNotFoundError, e:
        register_exception(req=req)
        return e.user_box()
Пример #5
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)
            issue_number = grouped_issues[0]

    if estimate_release_date.lower() == 'yes':
        # Get theoretical release date
        if granularity.lower() == 'day':
            granularity = DAILY
        elif granularity.lower() == 'week':
            granularity = WEEKLY
        elif granularity.lower() == 'month':
            granularity = MONTHLY
        else:
            granularity = None
        issue_release_time = issue_to_datetime(issue_number, journal_name,
                                               granularity)
    else:
        issue_release_time = get_release_datetime(issue_number, journal_name)

    # Get a nice internationalized representation of this date
    date_text = ''
    if issue_release_time:
        if display_week_day:
            date_text = get_i18n_day_name(issue_release_time.isoweekday(),
                                          display_week_day, ln) + ' '
        month = get_i18n_month_name(issue_release_time.month,
                                    display_month,
                                    ln=ln)
        date_text += issue_release_time.strftime("%d " + month +
                                                 " %Y").lstrip('0')

    issue_url = make_journal_url(bfo.user_info['uri'], {
        'recid': '',
 def test_get_release_datetime(self):
     """webjournal - gets the date at which an issue was released from the DB"""
     value = wju.get_release_datetime('03/2009',
                                      'AtlantisTimes',
                                      ln=CFG_SITE_LANG)
     self.assertEqual(value, datetime.datetime(2009, 1, 16, 0, 0))
    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_release_datetime(self):
     """webjournal - gets the date at which an issue was released from the DB"""
     value = wju.get_release_datetime('03/2009', 'AtlantisTimes', ln=CFG_SITE_LANG)
     self.assertEqual(value, datetime.datetime(2009, 1, 16, 0, 0))
Пример #11
0
    if estimate_release_date.lower() == 'yes':
        # Get theoretical release date
        if granularity.lower() == 'day':
            granularity = DAILY
        elif granularity.lower() == 'week':
            granularity = WEEKLY
        elif granularity.lower() == 'month':
            granularity = MONTHLY
        else:
            granularity = None
        issue_release_time = issue_to_datetime(issue_number,
                                               journal_name,
                                               granularity)
    else:
        issue_release_time = get_release_datetime(issue_number,
                                                  journal_name)

    # Get a nice internationalized representation of this date
    date_text = ''
    if issue_release_time:
        if display_week_day:
            date_text = get_i18n_day_name(issue_release_time.isoweekday(),
                                          display_week_day,
                                          ln) + ' '
        month = get_i18n_month_name(issue_release_time.month,
                                    display_month,
                                    ln=ln)
        date_text += issue_release_time.strftime("%d " + month + " %Y").lstrip('0')

    issue_url = make_journal_url(bfo.user_info['uri'],
                                 {'recid': '',
Пример #12
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)