Exemplo n.º 1
0
def perform_administrate(ln=CFG_SITE_LANG, journal_name=None,
                         as_editor=True):
    """
    Administration of a journal

    Show the current and next issues/publications, and display links
    to more specific administrative pages.

    Parameters:
        journal_name  -  the journal to be administrated
                  ln  -  language
        with_editor_rights  -  True if can edit configuration. Read-only mode otherwise
    """
    if journal_name is None:
        try:
            journal_name = guess_journal_name(ln)
        except InvenioWebJournalNoJournalOnServerError as e:
            return e.user_box()

    if not can_read_xml_config(journal_name):
        return '<span style="color:#f00">Configuration could not be read. Please check that %s/webjournal/%s/%s-config.xml exists and can be read by the server.</span><br/>' % (CFG_ETCDIR, journal_name, journal_name)

    current_issue = get_current_issue(ln, journal_name)
    current_publication = get_issue_number_display(current_issue,
                                                   journal_name,
                                                   ln)
    issue_list = get_grouped_issues(journal_name, current_issue)
    next_issue_number = get_next_journal_issues(issue_list[-1], journal_name, 1)

    return wjt.tmpl_admin_administrate(journal_name,
                                       current_issue,
                                       current_publication,
                                       issue_list,
                                       next_issue_number[0],
                                       ln,
                                       as_editor=as_editor)
Exemplo n.º 2
0
def perform_administrate(ln=CFG_SITE_LANG, journal_name=None,
                         as_editor=True):
    """
    Administration of a journal

    Show the current and next issues/publications, and display links
    to more specific administrative pages.

    Parameters:
        journal_name  -  the journal to be administrated
                  ln  -  language
        with_editor_rights  -  True if can edit configuration. Read-only mode otherwise
    """
    if journal_name is None:
        try:
            journal_name = guess_journal_name(ln)
        except InvenioWebJournalNoJournalOnServerError as e:
            return e.user_box()

    if not can_read_xml_config(journal_name):
        return '<span style="color:#f00">Configuration could not be read. Please check that %s/webjournal/%s/%s-config.xml exists and can be read by the server.</span><br/>' % (CFG_ETCDIR, journal_name, journal_name)

    current_issue = get_current_issue(ln, journal_name)
    current_publication = get_issue_number_display(current_issue,
                                                   journal_name,
                                                   ln)
    issue_list = get_grouped_issues(journal_name, current_issue)
    next_issue_number = get_next_journal_issues(issue_list[-1], journal_name, 1)

    return wjt.tmpl_admin_administrate(journal_name,
                                       current_issue,
                                       current_publication,
                                       issue_list,
                                       next_issue_number[0],
                                       ln,
                                       as_editor=as_editor)
Exemplo n.º 3
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 as e:
            register_exception(req=None)
            return e.user_box()
        out = wjt.tmpl_admin_control_issue_success_msg(ln,
                                                       publish_issues,
                                                       journal_name)

    elif action == _("Update"):
        try:
            try:
                update_issue = issues[0]
            except:
                raise InvenioWebJournalReleaseUpdateError(ln, journal_name)
        except InvenioWebJournalReleaseUpdateError as e:
            register_exception(req=None)
            return e.user_box()
        try:
            release_journal_update(update_issue, journal_name, ln)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=None)
            return e.user_box()
        out = wjt.tmpl_admin_updated_issue_msg(ln,
                                               update_issue,
                                               journal_name)

    return out
Exemplo n.º 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 as e:
            register_exception(req=None)
            return e.user_box()
        out = wjt.tmpl_admin_control_issue_success_msg(ln,
                                                       publish_issues,
                                                       journal_name)

    elif action == _("Update"):
        try:
            try:
                update_issue = issues[0]
            except:
                raise InvenioWebJournalReleaseUpdateError(ln, journal_name)
        except InvenioWebJournalReleaseUpdateError as e:
            register_exception(req=None)
            return e.user_box()
        try:
            release_journal_update(update_issue, journal_name, ln)
        except InvenioWebJournalJournalIdNotFoundDBError as e:
            register_exception(req=None)
            return e.user_box()
        out = wjt.tmpl_admin_updated_issue_msg(ln,
                                               update_issue,
                                               journal_name)

    return out