def test_get_output_format(self):
        """ bibformat - output format parsing and returned structure """
        bibformat_engine.CFG_BIBFORMAT_OUTPUTS_PATH = CFG_BIBFORMAT_OUTPUTS_PATH

        filename_1 = bibformat_engine.resolve_output_format_filename("test1")
        output_1 = bibformat_engine.get_output_format(filename_1,
                                                      with_attributes=True)

        self.assertEqual(output_1['attrs']['names']['generic'], "")
        self.assert_(isinstance(output_1['attrs']['names']['ln'], dict))
        self.assert_(isinstance(output_1['attrs']['names']['sn'], dict))
        self.assertEqual(output_1['attrs']['code'], "TEST1")
        self.assert_(len(output_1['attrs']['code']) <= 6)
        self.assertEqual(len(output_1['rules']), 4)
        self.assertEqual(output_1['rules'][0]['field'], '980.a')
        self.assertEqual(output_1['rules'][0]['template'],
                         'Picture_HTML_detailed.bft')
        self.assertEqual(output_1['rules'][0]['value'], 'PICTURE ')
        self.assertEqual(output_1['rules'][1]['field'], '980.a')
        self.assertEqual(output_1['rules'][1]['template'], 'Article.bft')
        self.assertEqual(output_1['rules'][1]['value'], 'ARTICLE')
        self.assertEqual(output_1['rules'][2]['field'], '980__a')
        self.assertEqual(output_1['rules'][2]['template'],
                         'Thesis_detailed.bft')
        self.assertEqual(output_1['rules'][2]['value'], 'THESIS ')
        self.assertEqual(output_1['rules'][3]['field'], '980__a')
        self.assertEqual(output_1['rules'][3]['template'], 'Pub.bft')
        self.assertEqual(output_1['rules'][3]['value'], 'PUBLICATION ')
        filename_2 = bibformat_engine.resolve_output_format_filename("TEST2")
        output_2 = bibformat_engine.get_output_format(filename_2,
                                                      with_attributes=True)

        self.assertEqual(output_2['attrs']['names']['generic'], "")
        self.assert_(isinstance(output_2['attrs']['names']['ln'], dict))
        self.assert_(isinstance(output_2['attrs']['names']['sn'], dict))
        self.assertEqual(output_2['attrs']['code'], "TEST2")
        self.assert_(len(output_2['attrs']['code']) <= 6)
        self.assertEqual(output_2['rules'], [])
        unknown_output = bibformat_engine.get_output_format(
            "unknow", with_attributes=True)
        self.assertEqual(
            unknown_output, {
                'rules': [],
                'default': "",
                'attrs': {
                    'names': {
                        'generic': "",
                        'ln': {},
                        'sn': {}
                    },
                    'description': '',
                    'code': "UNKNOW",
                    'visibility': 1,
                    'content_type': ""
                }
            })
    def test_get_output_format(self):
        """ bibformat - output format parsing and returned structure """
        bibformat_engine.CFG_BIBFORMAT_OUTPUTS_PATH = CFG_BIBFORMAT_OUTPUTS_PATH

        filename_1 = bibformat_engine.resolve_output_format_filename("test1")
        output_1 = bibformat_engine.get_output_format(filename_1, with_attributes=True)

        self.assertEqual(output_1["attrs"]["names"]["generic"], "")
        self.assert_(isinstance(output_1["attrs"]["names"]["ln"], dict))
        self.assert_(isinstance(output_1["attrs"]["names"]["sn"], dict))
        self.assertEqual(output_1["attrs"]["code"], "TEST1")
        self.assert_(len(output_1["attrs"]["code"]) <= 6)
        self.assertEqual(len(output_1["rules"]), 4)
        self.assertEqual(output_1["rules"][0]["field"], "980.a")
        self.assertEqual(output_1["rules"][0]["template"], "Picture_HTML_detailed.bft")
        self.assertEqual(output_1["rules"][0]["value"], "PICTURE ")
        self.assertEqual(output_1["rules"][1]["field"], "980.a")
        self.assertEqual(output_1["rules"][1]["template"], "Article.bft")
        self.assertEqual(output_1["rules"][1]["value"], "ARTICLE")
        self.assertEqual(output_1["rules"][2]["field"], "980__a")
        self.assertEqual(output_1["rules"][2]["template"], "Thesis_detailed.bft")
        self.assertEqual(output_1["rules"][2]["value"], "THESIS ")
        self.assertEqual(output_1["rules"][3]["field"], "980__a")
        self.assertEqual(output_1["rules"][3]["template"], "Pub.bft")
        self.assertEqual(output_1["rules"][3]["value"], "PUBLICATION ")
        filename_2 = bibformat_engine.resolve_output_format_filename("TEST2")
        output_2 = bibformat_engine.get_output_format(filename_2, with_attributes=True)

        self.assertEqual(output_2["attrs"]["names"]["generic"], "")
        self.assert_(isinstance(output_2["attrs"]["names"]["ln"], dict))
        self.assert_(isinstance(output_2["attrs"]["names"]["sn"], dict))
        self.assertEqual(output_2["attrs"]["code"], "TEST2")
        self.assert_(len(output_2["attrs"]["code"]) <= 6)
        self.assertEqual(output_2["rules"], [])
        unknown_output = bibformat_engine.get_output_format("unknow", with_attributes=True)
        self.assertEqual(
            unknown_output,
            {
                "rules": [],
                "default": "",
                "attrs": {
                    "names": {"generic": "", "ln": {}, "sn": {}},
                    "description": "",
                    "code": "UNKNOW",
                    "visibility": 1,
                    "content_type": "",
                },
            },
        )
Esempio n. 3
0
    def test_get_output_format(self):
        """ bibformat - output format parsing and returned structure """
        filename_1 = bibformat_engine.resolve_output_format_filename("test1")
        output_1 = bibformat_engine.get_output_format(filename_1,
                                                      with_attributes=True)

        self.assertEqual(output_1['attrs']['names']['generic'], "")
        self.assert_(isinstance(output_1['attrs']['names']['ln'], dict))
        self.assert_(isinstance(output_1['attrs']['names']['sn'], dict))
        self.assertEqual(output_1['attrs']['code'], "TEST1")
        self.assert_(len(output_1['attrs']['code']) <= 6)
        self.assertEqual(len(output_1['rules']), 4)
        self.assertEqual(output_1['rules'][0]['field'], '980.a')
        self.assertEqual(output_1['rules'][0]['template'],
                         'Picture_HTML_detailed.bft')
        self.assertEqual(output_1['rules'][0]['value'], 'PICTURE ')
        self.assertEqual(output_1['rules'][1]['field'], '980.a')
        self.assertEqual(output_1['rules'][1]['template'], 'Article.bft')
        self.assertEqual(output_1['rules'][1]['value'], 'ARTICLE')
        self.assertEqual(output_1['rules'][2]['field'], '980__a')
        self.assertEqual(output_1['rules'][2]['template'],
                         'Thesis_detailed.bft')
        self.assertEqual(output_1['rules'][2]['value'], 'THESIS ')
        self.assertEqual(output_1['rules'][3]['field'], '980__a')
        self.assertEqual(output_1['rules'][3]['template'], 'Pub.bft')
        self.assertEqual(output_1['rules'][3]['value'], 'PUBLICATION ')
        filename_2 = bibformat_engine.resolve_output_format_filename("TEST2")
        output_2 = bibformat_engine.get_output_format(filename_2,
                                                      with_attributes=True)

        self.assertEqual(output_2['attrs']['names']['generic'], "")
        self.assert_(isinstance(output_2['attrs']['names']['ln'], dict))
        self.assert_(isinstance(output_2['attrs']['names']['sn'], dict))
        self.assertEqual(output_2['attrs']['code'], "TEST2")
        self.assert_(len(output_2['attrs']['code']) <= 6)
        self.assertEqual(output_2['rules'], [])
        try:
            unknown_output = bibformat_engine.get_output_format(
                "unknow", with_attributes=True)
        except bibformat_engine.InvenioBibFormatError:
            pass
        else:
            self.fail("Should have raised the InvenioBibFormatError")
    def test_get_output_format(self):
        """ bibformat - output format parsing and returned structure """
        bibformat_engine.CFG_BIBFORMAT_OUTPUTS_PATH = CFG_BIBFORMAT_OUTPUTS_PATH

        filename_1 = bibformat_engine.resolve_output_format_filename("test1")
        output_1 = bibformat_engine.get_output_format(filename_1, with_attributes=True)

        self.assertEqual(output_1['attrs']['names']['generic'], "")
        self.assert_(isinstance(output_1['attrs']['names']['ln'], dict))
        self.assert_(isinstance(output_1['attrs']['names']['sn'], dict))
        self.assertEqual(output_1['attrs']['code'], "TEST1")
        self.assert_(len(output_1['attrs']['code']) <= 6)
        self.assertEqual(len(output_1['rules']), 4)
        self.assertEqual(output_1['rules'][0]['field'], '980.a')
        self.assertEqual(output_1['rules'][0]['template'], 'Picture_HTML_detailed.bft')
        self.assertEqual(output_1['rules'][0]['value'], 'PICTURE ')
        self.assertEqual(output_1['rules'][1]['field'], '980.a')
        self.assertEqual(output_1['rules'][1]['template'], 'Article.bft')
        self.assertEqual(output_1['rules'][1]['value'], 'ARTICLE')
        self.assertEqual(output_1['rules'][2]['field'], '980__a')
        self.assertEqual(output_1['rules'][2]['template'], 'Thesis_detailed.bft')
        self.assertEqual(output_1['rules'][2]['value'], 'THESIS ')
        self.assertEqual(output_1['rules'][3]['field'], '980__a')
        self.assertEqual(output_1['rules'][3]['template'], 'Pub.bft')
        self.assertEqual(output_1['rules'][3]['value'], 'PUBLICATION ')
        filename_2 = bibformat_engine.resolve_output_format_filename("TEST2")
        output_2 = bibformat_engine.get_output_format(filename_2, with_attributes=True)

        self.assertEqual(output_2['attrs']['names']['generic'], "")
        self.assert_(isinstance(output_2['attrs']['names']['ln'], dict))
        self.assert_(isinstance(output_2['attrs']['names']['sn'], dict))
        self.assertEqual(output_2['attrs']['code'], "TEST2")
        self.assert_(len(output_2['attrs']['code']) <= 6)
        self.assertEqual(output_2['rules'], [])
        unknown_output = bibformat_engine.get_output_format("unknow", with_attributes=True)
        self.assertEqual(unknown_output, {'rules':[],
                                          'default':"",
                                          'attrs':{'names':{'generic':"", 'ln':{}, 'sn':{}},
                                                   'description':'',
                                                   'code':"UNKNOW",
                                                   'visibility': 1,
                                                   'content_type':""}})
Esempio n. 5
0
def output_format_show_attributes(req, bfo, ln=CFG_SITE_LANG):
    """
    Page for output format names and descrition attributes edition.

    @param req: the request object
    @param ln: language
    @param bfo: the filename of the template to show
    @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")))

    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')

        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']

        return page(title=_("Output Format %s Attributes" % name),
                    body=bibformatadminlib.
                    perform_request_output_format_show_attributes(bfo, ln=ln),
                    uid=uid,
                    language=ln,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
    def test_get_output_format(self):
        """ bibformat - output format parsing and returned structure """
        filename_1 = bibformat_engine.resolve_output_format_filename("test1")
        output_1 = bibformat_engine.get_output_format(filename_1, with_attributes=True)

        self.assertEqual(output_1['attrs']['names']['generic'], "")
        self.assert_(isinstance(output_1['attrs']['names']['ln'], dict))
        self.assert_(isinstance(output_1['attrs']['names']['sn'], dict))
        self.assertEqual(output_1['attrs']['code'], "TEST1")
        self.assert_(len(output_1['attrs']['code']) <= 6)
        self.assertEqual(len(output_1['rules']), 4)
        self.assertEqual(output_1['rules'][0]['field'], '980.a')
        self.assertEqual(output_1['rules'][0]['template'], 'Picture_HTML_detailed.bft')
        self.assertEqual(output_1['rules'][0]['value'], 'PICTURE ')
        self.assertEqual(output_1['rules'][1]['field'], '980.a')
        self.assertEqual(output_1['rules'][1]['template'], 'Article.bft')
        self.assertEqual(output_1['rules'][1]['value'], 'ARTICLE')
        self.assertEqual(output_1['rules'][2]['field'], '980__a')
        self.assertEqual(output_1['rules'][2]['template'], 'Thesis_detailed.bft')
        self.assertEqual(output_1['rules'][2]['value'], 'THESIS ')
        self.assertEqual(output_1['rules'][3]['field'], '980__a')
        self.assertEqual(output_1['rules'][3]['template'], 'Pub.bft')
        self.assertEqual(output_1['rules'][3]['value'], 'PUBLICATION ')
        filename_2 = bibformat_engine.resolve_output_format_filename("TEST2")
        output_2 = bibformat_engine.get_output_format(filename_2, with_attributes=True)

        self.assertEqual(output_2['attrs']['names']['generic'], "")
        self.assert_(isinstance(output_2['attrs']['names']['ln'], dict))
        self.assert_(isinstance(output_2['attrs']['names']['sn'], dict))
        self.assertEqual(output_2['attrs']['code'], "TEST2")
        self.assert_(len(output_2['attrs']['code']) <= 6)
        self.assertEqual(output_2['rules'], [])
        try:
            unknown_output = bibformat_engine.get_output_format("unknow", with_attributes=True)
        except bibformat_engine.InvenioBibFormatError:
            pass
        else:
            self.fail("Should have raised the InvenioBibFormatError")
Esempio n. 7
0
def output_format_show_attributes(req, bfo, ln=CFG_SITE_LANG):
    """
    Page for output format names and descrition attributes edition.

    @param req: the request object
    @param ln: language
    @param bfo: the filename of the template to show
    @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")))

    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')

        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']

        return page(title=_("Output Format %s Attributes" % name),
                    body=bibformatadminlib.perform_request_output_format_show_attributes(bfo, ln=ln),
                    uid=uid,
                    language=ln,
                    navtrail = navtrail_previous_links ,
                    lastupdated=__lastupdated__,
                    req=req)
        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
            return page(
                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")],
            )
Esempio n. 9
0
def validate_format(req, ln=CFG_SITE_LANG, bfo=None, bft=None, bfe=None):
    """
    Returns a page showing the status of an output format or format
    template or format element. This page is called from output
    formats management page or format template management page or
    format elements documentation.

    The page only shows the status of one of the format, depending on
    the specified one. If multiple are specified, shows the first one.

    @param req: the request object
    @param ln: language
    @param bfo: an output format 6 chars code
    @param bft: a format element filename
    @param bfe: a format element name
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)

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

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        if bfo is not None: #Output format validation
            bfo = wash_url_argument(bfo, 'str')
            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")))

            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']
            title = _("Validation of Output Format %s" % name)

        elif bft is not None: #Format template validation
            bft = wash_url_argument(bft, 'str')
            navtrail_previous_links = bibformatadminlib.getnavtrail(''' &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%s">%s</a>''' % (CFG_SITE_SECURE_URL, ln, _("Manage Format Templates")))

            if not bibformatadminlib.can_read_format_template(bft): #No read permission
                try:
                    raise InvenioBibFormatError(_('Format template %s cannot not be read. %s') % (bft, ""))
                except InvenioBibFormatError, exc:
                    register_exception(req=req)
                    return page(title=_("Restricted Format Template"),
                            body = """You don't have permission to
                            view this format template.""",
                            language=ln,
                            navtrail = navtrail_previous_links,
                            lastupdated=__lastupdated__,
                            req=req)
            name = bibformat_engine.get_format_template_attrs(bft)['name']
            title = _("Validation of Format Template %s" % name)
Esempio n. 10
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)
Esempio n. 11
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)
Esempio n. 12
0
def validate_format(req, ln=CFG_SITE_LANG, bfo=None, bft=None, bfe=None):
    """
    Returns a page showing the status of an output format or format
    template or format element. This page is called from output
    formats management page or format template management page or
    format elements documentation.

    The page only shows the status of one of the format, depending on
    the specified one. If multiple are specified, shows the first one.

    @param req: the request object
    @param ln: language
    @param bfo: an output format 6 chars code
    @param bft: a format element filename
    @param bfe: a format element name
    @return: a web page
    """
    ln = wash_language(ln)
    _ = gettext_set_language(ln)

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

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        if bfo is not None:  #Output format validation
            bfo = wash_url_argument(bfo, 'str')
            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")))

            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']
            title = _("Validation of Output Format %s" % name)

        elif bft is not None:  #Format template validation
            bft = wash_url_argument(bft, 'str')
            navtrail_previous_links = bibformatadminlib.getnavtrail(
                ''' &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%s">%s</a>'''
                % (CFG_SITE_SECURE_URL, ln, _("Manage Format Templates")))

            if not bibformatadminlib.can_read_format_template(
                    bft):  #No read permission
                try:
                    raise InvenioBibFormatError(
                        _('Format template %s cannot not be read. %s') %
                        (bft, ""))
                except InvenioBibFormatError, exc:
                    register_exception(req=req)
                    return page(title=_("Restricted Format Template"),
                                body="""You don't have permission to
                            view this format template.""",
                                language=ln,
                                navtrail=navtrail_previous_links,
                                lastupdated=__lastupdated__,
                                req=req)
            name = bibformat_engine.get_format_template_attrs(bft)['name']
            title = _("Validation of Format Template %s" % name)
Esempio n. 13
0
        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
            return page(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")])