Example #1
0
def output_format_show_dependencies(req, bfo, ln=CFG_SITE_LANG):
    """
    Show the dependencies of the given output format.

    @param req: the request object
    @param ln: language
    @param bfo: the filename of the output format 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/format_templates_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)

        format_name = bibformat_engine.get_output_format_attrs(
            bfo)['names']['generic']

        return page(title=_("Output Format %s Dependencies" % format_name),
                    body=bibformatadminlib.
                    perform_request_output_format_show_dependencies(bfo,
                                                                    ln=ln),
                    uid=uid,
                    language=ln,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
Example #2
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)
        % (CFG_SITE_URL, ln, _("Manage Output Formats"))
    )
    code = wash_url_argument(bfo, "str")

    try:
        uid = getUid(req)
    except MySQLdb.Error, e:
        return error_page(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
            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
Example #4
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)
Example #5
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)
Example #6
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)
Example #7
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)
Example #8
0
        ''' &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 MySQLdb.Error, e:
        return error_page(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
            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