def format_template_show_attributes(req, bft, ln=CFG_SITE_LANG, new=0):
    """
    Page for template name and descrition attributes edition.

    This is also the first page shown when a format template
    has just been added. In that case new is different from
    False and we can offer specific option to user (for ex
    let him make a duplicate of existing template).

    @param req: the request object
    @param ln: language
    @param bft: the name of the template to show
    @param new: if "False", the template has not just been added
    @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 Format Templates")))

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

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        format_template = wash_url_argument(bft, 'str')
        format_name = bibformat_engine.get_format_template_attrs(bft)['name']
        is_new = wash_url_argument(new, 'int')

        if not bibformatadminlib.can_read_format_template(
                bft):  #No read permission
            try:
                raise InvenioBibFormatError(
                    _('Format template %s cannot not be read. %s') %
                    (format_template, ""))
            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)

        return page(title=_("Format Template %s Attributes" % format_name),
                    body=bibformatadminlib.
                    perform_request_format_template_show_attributes(
                        bft, ln=ln, new=is_new),
                    uid=uid,
                    language=ln,
                    navtrail=navtrail_previous_links,
                    lastupdated=__lastupdated__,
                    req=req)
def format_template_show_attributes(req, bft, ln=CFG_SITE_LANG, new=0):
    """
    Page for template name and descrition attributes edition.

    This is also the first page shown when a format template
    has just been added. In that case new is different from
    False and we can offer specific option to user (for ex
    let him make a duplicate of existing template).

    @param req: the request object
    @param ln: language
    @param bft: the name of the template to show
    @param new: if "False", the template has not just been added
    @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 Format Templates")))

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

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        format_template = wash_url_argument(bft, 'str')
        format_name = bibformat_engine.get_format_template_attrs(bft)['name']
        is_new = wash_url_argument(new, 'int')

        if not bibformatadminlib.can_read_format_template(bft): #No read permission
            try:
                raise InvenioBibFormatError(_('Format template %s cannot not be read. %s') % (format_template, ""))
            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)

        return page(title=_("Format Template %s Attributes"%format_name),
                    body=bibformatadminlib.perform_request_format_template_show_attributes(bft, ln=ln, new=is_new),
                    uid=uid,
                    language=ln,
                    navtrail = navtrail_previous_links ,
                    lastupdated=__lastupdated__,
                    req=req)
        """
    &gt; <a class="navtrail" href="%s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%s">%s</a>"""
        % (CFG_SITE_URL, ln, _("Manage Format Templates"))
    )

    try:
        uid = getUid(req)
    except MySQLdb.Error, e:
        return error_page(req)

    (auth_code, auth_msg) = check_user(req, "cfgbibformat")
    if not auth_code:
        format_template = wash_url_argument(bft, "str")
        ln_preview = wash_language(ln_for_preview)
        pattern_preview = wash_url_argument(pattern_for_preview, "str")
        if not bibformatadminlib.can_read_format_template(bft):  # No read permission
            return page(
                title=_("Restricted Format Template"),
                body="""You don't have permission
                        to view this format template.""",
                language=ln,
                navtrail=navtrail_previous_links,
                errors=[("ERR_BIBFORMAT_CANNOT_READ_TEMPLATE_FILE", format_template, "")],
                lastupdated=__lastupdated__,
                req=req,
            )

        format_name = bibformat_engine.get_format_template_attrs(bft)["name"]
        if not bibformatadminlib.can_write_format_template(bft) and chosen_option == "":  # No write permission
            return dialog_box(
                req=req,
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)
def format_template_show(req, bft, code=None, ln=CFG_SITE_LANG,
                         ln_for_preview=CFG_SITE_LANG,
                         pattern_for_preview="",
                         content_type_for_preview="text/html",
                         chosen_option=""):
    """
    Main page for template edition. Check for authentication and print formats editor.

    @param req: the request object
    @param ln: language
    @param code: the code being edited
    @param bft: the name of the template to show
    @param ln_for_preview: the language for the preview (for bfo)
    @param pattern_for_preview: the search pattern to be used for the preview (for bfo)
    @param content_type_for_preview: the (MIME) content type of the preview
    @param chosen_option: returned value for dialog_box warning
    @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 Format Templates")))

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

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        format_template = wash_url_argument(bft, 'str')
        ln_preview = wash_language(ln_for_preview)
        pattern_preview = wash_url_argument(pattern_for_preview, 'str')
        if not bibformatadminlib.can_read_format_template(bft): #No read permission
            try:
                raise InvenioBibFormatError(_('Format template %s cannot not be read. %s') % (format_template, ""))
            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)

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


        if bft.endswith('.xsl'):
            format_name += ' (XSL)'
        return page(title=_("Format Template %s"%format_name),
                body=bibformatadminlib.perform_request_format_template_show(format_template,
                                                          code=code,
                                                          ln=ln,
                                                          ln_for_preview=ln_preview,
                                                          pattern_for_preview=pattern_preview,
                                                          content_type_for_preview=content_type_for_preview),
                uid=uid,
                language=ln,
                navtrail = navtrail_previous_links,
                lastupdated=__lastupdated__,
                req=req)
def format_template_show(req,
                         bft,
                         code=None,
                         ln=CFG_SITE_LANG,
                         ln_for_preview=CFG_SITE_LANG,
                         pattern_for_preview="",
                         content_type_for_preview="text/html",
                         chosen_option=""):
    """
    Main page for template edition. Check for authentication and print formats editor.

    @param req: the request object
    @param ln: language
    @param code: the code being edited
    @param bft: the name of the template to show
    @param ln_for_preview: the language for the preview (for bfo)
    @param pattern_for_preview: the search pattern to be used for the preview (for bfo)
    @param content_type_for_preview: the (MIME) content type of the preview
    @param chosen_option: returned value for dialog_box warning
    @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 Format Templates")))

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

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        format_template = wash_url_argument(bft, 'str')
        ln_preview = wash_language(ln_for_preview)
        pattern_preview = wash_url_argument(pattern_for_preview, 'str')
        if not bibformatadminlib.can_read_format_template(
                bft):  #No read permission
            try:
                raise InvenioBibFormatError(
                    _('Format template %s cannot not be read. %s') %
                    (format_template, ""))
            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)

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

        if bft.endswith('.xsl'):
            format_name += ' (XSL)'
        return page(
            title=_("Format Template %s" % format_name),
            body=bibformatadminlib.perform_request_format_template_show(
                format_template,
                code=code,
                ln=ln,
                ln_for_preview=ln_preview,
                pattern_for_preview=pattern_preview,
                content_type_for_preview=content_type_for_preview),
            uid=uid,
            language=ln,
            navtrail=navtrail_previous_links,
            lastupdated=__lastupdated__,
            req=req)
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)
Exemple #8
0
    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")))

    try:
        uid = getUid(req)
    except MySQLdb.Error, e:
        return error_page(req)

    (auth_code, auth_msg) = check_user(req, 'cfgbibformat')
    if not auth_code:
        format_template = wash_url_argument(bft, 'str')
        ln_preview = wash_language(ln_for_preview)
        pattern_preview = wash_url_argument(pattern_for_preview, 'str')
        if not bibformatadminlib.can_read_format_template(
                bft):  #No read permission
            return page(title=_("Restricted Format Template"),
                        body="""You don't have permission
                        to view this format template.""",
                        language=ln,
                        navtrail=navtrail_previous_links,
                        errors=[("ERR_BIBFORMAT_CANNOT_READ_TEMPLATE_FILE",
                                 format_template, "")],
                        lastupdated=__lastupdated__,
                        req=req)

        format_name = bibformat_engine.get_format_template_attrs(bft)['name']
        if not bibformatadminlib.can_write_format_template(bft) and \
               chosen_option == "": #No write permission
            return dialog_box(req=req,
                              ln=ln,