Ejemplo n.º 1
0
                title=_("Restricted Output Format"),
                body="""You don't have permission to
                        view this output format.""",
                language=ln,
                navtrail=navtrail_previous_links,
                errors=[("ERR_BIBFORMAT_CANNOT_READ_OUTPUT_FILE", bfo, "")],
                lastupdated=__lastupdated__,
                req=req,
            )

        output_format = bibformat_engine.get_output_format(code=bfo, with_attributes=True)
        name = output_format["attrs"]["names"]["generic"]
        if name == "":
            name = bfo

        if not bibformatadminlib.can_write_output_format(bfo) and chosen_option == "":  # No write permission
            return dialog_box(
                req=req,
                ln=ln,
                title="File Permission on %s" % name,
                message="You don't have write permission "
                "on <i>%s</i>.<br/> You can view the output "
                "format, but not edit it." % name,
                navtrail=navtrail_previous_links,
                options=[_("Ok")],
            )

        return page(
            title=_("Output Format %s Rules" % name),
            body=bibformatadminlib.perform_request_output_format_show(
                bfo=bfo, ln=ln, r_fld=r_fld, r_val=r_val, r_tpl=r_tpl, default=default, r_upd=r_upd, args=args
Ejemplo n.º 2
0
def output_format_show(req, bfo, ln=CFG_SITE_LANG,
                       r_fld=[], r_val=[], r_tpl=[],
                       default="", r_upd="", chosen_option="",
                       **args):
    """
    Show a single output format. Check for authentication and print output format settings.

    The page either shows the output format from file, or from user's
    POST session, as we want to let him edit the rules without
    saving. Policy is: r_fld, r_val, rules_tpl are list of attributes
    of the rules.  If they are empty, load from file. Else use
    POST. The i th value of each list is one of the attributes of rule
    i. Rule i is the i th rule in order of evaluation.  All list have
    the same number of item.

    r_upd contains an action that has to be performed on rules. It
    can composed of a number (i, the rule we want to modify) and an
    operator : "save" to save the rules, "add" or "del".
    syntax: operator [number]
    For eg: r_upd = _("Save Changes") saves all rules (no int should be specified).
    For eg: r_upd = _("Add New Rule") adds a rule (no int should be specified).
    For eg: r_upd = _("Remove Rule") + " 5"  deletes rule at position 5.
    The number is used only for operation delete.

    An action can also be in **args. We must look there for string starting
    with '(+|-) [number]' to increase (+) or decrease (-) a rule given by its
    index (number).
    For example "+ 5" increase priority of rule 5 (put it at fourth position).
    The string in **args can be followed by some garbage that looks like .x
    or .y, as this is returned as the coordinate of the click on the
    <input type="image">. We HAVE to use args and reason on its keys, because for <input> of
    type image, iexplorer does not return the value of the tag, but only the name.

    Action is executed only if we are working from user's POST session
    (means we must have loaded the output format first, which is
    totally normal and expected behaviour)


    @param req: the request object
    @param bfo: the filename of the output format to show
    @param ln: language
    @param r_fld: the list of 'field' attribute for each rule
    @param r_val: the list of 'value' attribute for each rule
    @param r_tpl: the list of 'template' attribute for each rule
    @param default: the default format template used by this output format
    @param r_upd: the rule that we want to increase/decrease in order of evaluation
    @param chosen_option: emptry string when user has not yet confirmed to go on
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = bibformatadminlib.getnavtrail(''' &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/output_formats_manage?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln, _("Manage Output Formats")))
    code = wash_url_argument(bfo, 'str')

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        bfo = wash_url_argument(bfo, 'str')
        default = wash_url_argument(default, 'str')
        r_upd = wash_url_argument(r_upd, 'str')

        if not bibformatadminlib.can_read_output_format(bfo): #No read permission
            try:
                raise InvenioBibFormatError(_('Output format %s cannot not be read. %s') % (bfo, ""))
            except InvenioBibFormatError, exc:
                register_exception(req=req)
                return page(title=_("Restricted Output Format"),
                            body = """You don't have permission to
                            view this output format.""",
                            language=ln,
                            navtrail = navtrail_previous_links,
                            lastupdated=__lastupdated__,
                            req=req)

        output_format = bibformat_engine.get_output_format(code=bfo,
                                                           with_attributes=True)
        name = output_format['attrs']['names']['generic']
        if name == "":
            name = bfo

        if not bibformatadminlib.can_write_output_format(bfo) and \
               chosen_option == "":#No write permission
            return dialog_box(req=req,
                              ln=ln,
                              title="File Permission on %s" % name,
                              message="You don't have write permission " \
                              "on <i>%s</i>.<br/> You can view the output " \
                              "format, but not edit it." % name,
                              navtrail=navtrail_previous_links,
                              options=[ _("Ok")])

        return page(title=_('Output Format %s Rules' % name),
                    body=bibformatadminlib.perform_request_output_format_show(bfo=bfo,
                                                                              ln=ln,
                                                                              r_fld=r_fld,
                                                                              r_val=r_val,
                                                                              r_tpl=r_tpl,
                                                                              default=default,
                                                                              r_upd=r_upd,
                                                                              args=args),
                    uid=uid,
                    language=ln,
                    navtrail = navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
Ejemplo n.º 3
0
def output_format_show(req,
                       bfo,
                       ln=CFG_SITE_LANG,
                       r_fld=[],
                       r_val=[],
                       r_tpl=[],
                       default="",
                       r_upd="",
                       chosen_option="",
                       **args):
    """
    Show a single output format. Check for authentication and print output format settings.

    The page either shows the output format from file, or from user's
    POST session, as we want to let him edit the rules without
    saving. Policy is: r_fld, r_val, rules_tpl are list of attributes
    of the rules.  If they are empty, load from file. Else use
    POST. The i th value of each list is one of the attributes of rule
    i. Rule i is the i th rule in order of evaluation.  All list have
    the same number of item.

    r_upd contains an action that has to be performed on rules. It
    can composed of a number (i, the rule we want to modify) and an
    operator : "save" to save the rules, "add" or "del".
    syntax: operator [number]
    For eg: r_upd = _("Save Changes") saves all rules (no int should be specified).
    For eg: r_upd = _("Add New Rule") adds a rule (no int should be specified).
    For eg: r_upd = _("Remove Rule") + " 5"  deletes rule at position 5.
    The number is used only for operation delete.

    An action can also be in **args. We must look there for string starting
    with '(+|-) [number]' to increase (+) or decrease (-) a rule given by its
    index (number).
    For example "+ 5" increase priority of rule 5 (put it at fourth position).
    The string in **args can be followed by some garbage that looks like .x
    or .y, as this is returned as the coordinate of the click on the
    <input type="image">. We HAVE to use args and reason on its keys, because for <input> of
    type image, iexplorer does not return the value of the tag, but only the name.

    Action is executed only if we are working from user's POST session
    (means we must have loaded the output format first, which is
    totally normal and expected behaviour)


    @param req: the request object
    @param bfo: the filename of the output format to show
    @param ln: language
    @param r_fld: the list of 'field' attribute for each rule
    @param r_val: the list of 'value' attribute for each rule
    @param r_tpl: the list of 'template' attribute for each rule
    @param default: the default format template used by this output format
    @param r_upd: the rule that we want to increase/decrease in order of evaluation
    @param chosen_option: emptry string when user has not yet confirmed to go on
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)
    navtrail_previous_links = bibformatadminlib.getnavtrail(
        ''' &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/output_formats_manage?ln=%s">%s</a>'''
        % (CFG_SITE_SECURE_URL, ln, _("Manage Output Formats")))
    code = wash_url_argument(bfo, 'str')

    try:
        uid = getUid(req)
    except:
        return error_page('Error', req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        bfo = wash_url_argument(bfo, 'str')
        default = wash_url_argument(default, 'str')
        r_upd = wash_url_argument(r_upd, 'str')

        if not bibformatadminlib.can_read_output_format(
                bfo):  #No read permission
            try:
                raise InvenioBibFormatError(
                    _('Output format %s cannot not be read. %s') % (bfo, ""))
            except InvenioBibFormatError, exc:
                register_exception(req=req)
                return page(title=_("Restricted Output Format"),
                            body="""You don't have permission to
                            view this output format.""",
                            language=ln,
                            navtrail=navtrail_previous_links,
                            lastupdated=__lastupdated__,
                            req=req)

        output_format = bibformat_engine.get_output_format(
            code=bfo, with_attributes=True)
        name = output_format['attrs']['names']['generic']
        if name == "":
            name = bfo

        if not bibformatadminlib.can_write_output_format(bfo) and \
               chosen_option == "":#No write permission
            return dialog_box(req=req,
                              ln=ln,
                              title="File Permission on %s" % name,
                              message="You don't have write permission " \
                              "on <i>%s</i>.<br/> You can view the output " \
                              "format, but not edit it." % name,
                              navtrail=navtrail_previous_links,
                              options=[ _("Ok")])

        return page(title=_('Output Format %s Rules' % name),
                    body=bibformatadminlib.perform_request_output_format_show(
                        bfo=bfo,
                        ln=ln,
                        r_fld=r_fld,
                        r_val=r_val,
                        r_tpl=r_tpl,
                        default=default,
                        r_upd=r_upd,
                        args=args),
                    uid=uid,
                    language=ln,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
Ejemplo n.º 4
0
                register_exception(req=req)
                return page(title=_("Restricted Output Format"),
                            body = """You don't have permission to
                            view this output format.""",
                            language=ln,
                            navtrail = navtrail_previous_links,
                            lastupdated=__lastupdated__,
                            req=req)

        output_format = bibformat_engine.get_output_format(code=bfo,
                                                           with_attributes=True)
        name = output_format['attrs']['names']['generic']
        if name == "":
            name = bfo

        if not bibformatadminlib.can_write_output_format(bfo) and \
               chosen_option == "":#No write permission
            return dialog_box(req=req,
                              ln=ln,
                              title="File Permission on %s" % name,
                              message="You don't have write permission " \
                              "on <i>%s</i>.<br/> You can view the output " \
                              "format, but not edit it." % name,
                              navtrail=navtrail_previous_links,
                              options=[ _("Ok")])

        return page(title=_('Output Format %s Rules' % name),
                    body=bibformatadminlib.perform_request_output_format_show(bfo=bfo,
                                                                              ln=ln,
                                                                              r_fld=r_fld,
                                                                              r_val=r_val,
Ejemplo n.º 5
0
                        body="""You don't have permission to
                        view this output format.""",
                        language=ln,
                        navtrail=navtrail_previous_links,
                        errors=[("ERR_BIBFORMAT_CANNOT_READ_OUTPUT_FILE", bfo,
                                 "")],
                        lastupdated=__lastupdated__,
                        req=req)

        output_format = bibformat_engine.get_output_format(
            code=bfo, with_attributes=True)
        name = output_format['attrs']['names']['generic']
        if name == "":
            name = bfo

        if not bibformatadminlib.can_write_output_format(bfo) and \
               chosen_option == "":#No write permission
            return dialog_box(req=req,
                              ln=ln,
                              title="File Permission on %s" % name,
                              message="You don't have write permission " \
                              "on <i>%s</i>.<br/> You can view the output " \
                              "format, but not edit it." % name,
                              navtrail=navtrail_previous_links,
                              options=[ _("Ok")])

        return page(title=_('Output Format %s Rules' % name),
                    body=bibformatadminlib.perform_request_output_format_show(
                        bfo=bfo,
                        ln=ln,
                        r_fld=r_fld,