Пример #1
0
def perform_request_issue_control(journal_name, issues, action, ln=CFG_SITE_LANG):
    """
    Central logic for issue control.

    Regenerates the flat files 'current_issue' and 'issue_group' of
    the journal that control which issue is currently active for the
    journal.

    Parameters:
        journal_name  -  the journal affected by 'action'
              issues  -  list of issues affected by 'action' TODO: check
              action  -  One of ['cfg', _('Add'), _('Refresh'),
                         _('Publish'), _('Update')]
                  ln  -  language
    """
    _ = gettext_set_language(ln)

    out = ""
    if action == "cfg" or action == _("Refresh") or action == _("Add"):
        # find out if we are in update or release
        current_issue = get_current_issue(ln, journal_name)
        grouped_issues = get_grouped_issues(journal_name, current_issue)
        if current_issue != grouped_issues[-1]:
            # The current issue has "pending updates", i.e. is grouped
            # with unreleased issues. Propose to update these issues
            next_issue = grouped_issues[grouped_issues.index(current_issue) + 1]
            out = wjt.tmpl_admin_update_issue(ln, journal_name, next_issue, current_issue)
        else:
            # Propose a release
            next_issues = get_next_journal_issues(
                current_issue, journal_name, n=get_journal_issue_grouping(journal_name)
            )
            if action == _("Refresh"):
                next_issues += issues
                next_issues = list(set(next_issues))  # avoid double entries
            elif action == _("Add"):
                next_issues += issues
                next_issues = list(set(next_issues))  # avoid double entries
                next_issues.sort(compare_issues)
                highest_issue_so_far = next_issues[-1]
                one_more_issue = get_next_journal_issues(highest_issue_so_far, journal_name, 1)
                next_issues += one_more_issue
                next_issues = list(set(next_issues))  # avoid double entries
            else:
                # get the next issue numbers to publish
                next_issues = get_next_journal_issues(
                    current_issue, journal_name, n=get_journal_issue_grouping(journal_name)
                )
            next_issues.sort(compare_issues)
            out = wjt.tmpl_admin_control_issue(ln, journal_name, next_issues)
    elif action == _("Publish"):
        # Publish the given issues (mark them as current issues)
        publish_issues = issues
        publish_issues = list(set(publish_issues))  # avoid double entries
        publish_issues.sort(compare_issues)
        if len(publish_issues) == 0:
            # User did not select an issue
            current_issue = get_current_issue(ln, journal_name)
            next_issues = get_next_journal_issues(
                current_issue, journal_name, n=get_journal_issue_grouping(journal_name)
            )
            out = '<p style="color:#f00;text-align:center">' + _("Please select an issue") + "</p>"
            out += wjt.tmpl_admin_control_issue(ln, journal_name, next_issues)
            return out
        try:
            release_journal_issue(publish_issues, journal_name, ln)
        except InvenioWebJournalJournalIdNotFoundDBError, e:
            register_exception(req=None)
            return e.user_box()
        out = wjt.tmpl_admin_control_issue_success_msg(ln, publish_issues, journal_name)
 def test_get_journal_issue_grouping(self):
     """webjournal - returns the number of issue that are typically released
     at the same time"""
     issue = wju.get_journal_issue_grouping('AtlantisTimes')
     self.assertEqual(issue, 2)
 def test_get_journal_issue_grouping(self):
     """webjournal - returns the number of issue that are typically released
     at the same time"""
     issue = wju.get_journal_issue_grouping('AtlantisTimes')
     self.assertEqual(issue, 2)
Пример #4
0
def perform_request_issue_control(journal_name,
                                  issues,
                                  action,
                                  ln=CFG_SITE_LANG):
    """
    Central logic for issue control.

    Regenerates the flat files 'current_issue' and 'issue_group' of
    the journal that control which issue is currently active for the
    journal.

    Parameters:
        journal_name  -  the journal affected by 'action'
              issues  -  list of issues affected by 'action' TODO: check
              action  -  One of ['cfg', _('Add'), _('Refresh'),
                         _('Publish'), _('Update')]
                  ln  -  language
    """
    _ = gettext_set_language(ln)

    out = ''
    if action == "cfg" or action == _("Refresh") or action == _("Add"):
        # find out if we are in update or release
        current_issue = get_current_issue(ln, journal_name)
        grouped_issues = get_grouped_issues(journal_name, current_issue)
        if current_issue != grouped_issues[-1]:
            # The current issue has "pending updates", i.e. is grouped
            # with unreleased issues. Propose to update these issues
            next_issue = grouped_issues[grouped_issues.index(current_issue) +
                                        1]
            out = wjt.tmpl_admin_update_issue(ln, journal_name, next_issue,
                                              current_issue)
        else:
            # Propose a release
            next_issues = get_next_journal_issues(
                current_issue,
                journal_name,
                n=get_journal_issue_grouping(journal_name))
            if action == _("Refresh"):
                next_issues += issues
                next_issues = list(set(next_issues))  # avoid double entries
            elif action == _("Add"):
                next_issues += issues
                next_issues = list(set(next_issues))  # avoid double entries
                next_issues.sort(compare_issues)
                highest_issue_so_far = next_issues[-1]
                one_more_issue = get_next_journal_issues(
                    highest_issue_so_far, journal_name, 1)
                next_issues += one_more_issue
                next_issues = list(set(next_issues))  # avoid double entries
            else:
                # get the next issue numbers to publish
                next_issues = get_next_journal_issues(
                    current_issue,
                    journal_name,
                    n=get_journal_issue_grouping(journal_name))
            next_issues.sort(compare_issues)
            out = wjt.tmpl_admin_control_issue(ln, journal_name, next_issues)
    elif action == _("Publish"):
        # Publish the given issues (mark them as current issues)
        publish_issues = issues
        publish_issues = list(set(publish_issues))  # avoid double entries
        publish_issues.sort(compare_issues)
        if len(publish_issues) == 0:
            # User did not select an issue
            current_issue = get_current_issue(ln, journal_name)
            next_issues = get_next_journal_issues(
                current_issue,
                journal_name,
                n=get_journal_issue_grouping(journal_name))
            out = '<p style="color:#f00;text-align:center">' + \
                  _('Please select an issue') + '</p>'
            out += wjt.tmpl_admin_control_issue(ln, journal_name, next_issues)
            return out
        try:
            release_journal_issue(publish_issues, journal_name, ln)
        except InvenioWebJournalJournalIdNotFoundDBError, e:
            register_exception(req=None)
            return e.user_box()
        out = wjt.tmpl_admin_control_issue_success_msg(ln, publish_issues,
                                                       journal_name)