예제 #1
0
파일: views.py 프로젝트: mhellmic/b2share
    def decorated(recid, *args, **kwargs):
        from invenio.modules.access.mailcookie import \
            mail_cookie_create_authorize_action
        from invenio.modules.access.local_config import VIEWRESTRCOLL
        from invenio.legacy.search_engine import guess_primary_collection_of_a_record, \
            check_user_can_view_record
        from invenio.legacy.websearch.adminlib import get_detailed_page_tabs,\
            get_detailed_page_tabs_counts
        from invenio.b2share.modules.main.utils import check_fresh_record
        # ensure recid to be integer
        recid = int(recid)

        from invenio.legacy.search_engine import record_exists, get_merged_recid
        if record_exists(recid) == 0:
            # record doesn't exist, abort so it doesn't get incorrectly cached
            abort(apache.HTTP_NOT_FOUND)  # The record is gone!
        if check_fresh_record(current_user, recid):
            return render_template('record_waitforit.html', recid=recid)

        g.collection = collection = Collection.query.filter(
            Collection.name == guess_primary_collection_of_a_record(recid)).\
            one()

        (auth_code, auth_msg) = check_user_can_view_record(current_user, recid)

        # only superadmins can use verbose parameter for obtaining debug information
        if not current_user.is_super_admin and 'verbose' in kwargs:
            kwargs['verbose'] = 0

        if auth_code and current_user.is_guest:
            cookie = mail_cookie_create_authorize_action(VIEWRESTRCOLL, {
                'collection': g.collection.name})
            url_args = {'action': cookie, 'ln': g.ln, 'referer': request.url}
            flash(_("Authorization failure"), 'error')
            return redirect(url_for('webaccount.login', **url_args))
        elif auth_code:
            flash(auth_msg, 'error')
            abort(apache.HTTP_UNAUTHORIZED)

        from invenio.modules.records.api import get_record
        from invenio.legacy.search_engine import record_exists, get_merged_recid
        # check if the current record has been deleted
        # and has been merged, case in which the deleted record
        # will be redirect to the new one
        record_status = record_exists(recid)
        merged_recid = get_merged_recid(recid)
        if record_status == -1 and merged_recid:
            return redirect(url_for('record.metadata', recid=merged_recid))
        elif record_status == -1:
            abort(apache.HTTP_GONE)  # The record is gone!

        g.bibrec = Bibrec.query.get(recid)
        record = get_record(recid)

        if record is None:
            return render_template('404.html')

        title = record.get(cfg.get('RECORDS_BREADCRUMB_TITLE_KEY'), '')

        # b = [(_('Home'), '')] + collection.breadcrumbs()[1:]
        # b += [(title, 'record.metadata', dict(recid=recid))]
        # current_app.config['breadcrumbs_map'][request.endpoint] = b
        g.record_tab_keys = []
        tabs = []
        counts = get_detailed_page_tabs_counts(recid)
        for k, v in iteritems(get_detailed_page_tabs(collection.id, recid,
                                                     g.ln)):
            t = {}
            b = 'record'
            if k == '':
                k = 'metadata'
            if k == 'comments' or k == 'reviews':
                b = 'comments'
            if k == 'linkbacks':
                b = 'weblinkback'
                k = 'index'

            t['key'] = b + '.' + k
            t['count'] = counts.get(k.capitalize(), -1)

            t.update(v)
            tabs.append(t)
            if v['visible']:
                g.record_tab_keys.append(b+'.'+k)

        if cfg.get('CFG_WEBLINKBACK_TRACKBACK_ENABLED'):
            @register_template_context_processor
            def trackback_context():
                from invenio.legacy.weblinkback.templates import get_trackback_auto_discovery_tag
                return dict(headerLinkbackTrackbackLink=get_trackback_auto_discovery_tag(recid))

        def _format_record(recid, of='hd', user_info=current_user, *args, **kwargs):
            from invenio.modules.formatter import format_record
            return format_record(recid, of, user_info=user_info, *args, **kwargs)

        @register_template_context_processor
        def record_context():
            from invenio.modules.comments.api import get_mini_reviews
            from invenio.legacy.bibdocfile.api import BibRecDocs
            all_files = [f for f in BibRecDocs(recid, human_readable=True).list_latest_files(list_hidden=False) \
                         if not f.is_icon()]
            files = [f for f in all_files if f.is_restricted(current_user)[0] == 0]
            has_private_files = len(files) < len(all_files)
            return dict(recid=recid,
                        record=record,
                        tabs=tabs,
                        title=title,
                        get_mini_reviews=get_mini_reviews,
                        collection=collection,
                        format_record=_format_record,
                        has_private_files=has_private_files,
                        files=files
                        )

        pre_template_render.send(
            "%s.%s" % (blueprint.name, f.__name__),
            recid=recid,
        )
        return f(recid, *args, **kwargs)
예제 #2
0
    def __call__(self, req, form):
        argd = wash_search_urlargd(form)

        argd['recid'] = self.recid

        argd['tab'] = self.tab

        # do we really enter here ?

        if self.format is not None:
            argd['of'] = self.format
        req.argd = argd
        uid = getUid(req)
        if uid == -1:
            return page_not_authorized(req, "../",
                text="You are not authorized to view this record.",
                                       navmenuid='search')
        elif uid > 0:
            pref = get_user_preferences(uid)
            try:
                if 'rg' not in form:
                    # fetch user rg preference only if not overridden via URL
                    argd['rg'] = int(pref['websearch_group_records'])
            except (KeyError, ValueError):
                pass

        user_info = collect_user_info(req)
        (auth_code, auth_msg) = check_user_can_view_record(user_info, self.recid)

        if argd['rg'] > CFG_WEBSEARCH_MAX_RECORDS_IN_GROUPS and acc_authorize_action(req, 'runbibedit')[0] != 0:
            argd['rg'] = CFG_WEBSEARCH_MAX_RECORDS_IN_GROUPS

        #check if the user has rights to set a high wildcard limit
        #if not, reduce the limit set by user, with the default one
        if CFG_WEBSEARCH_WILDCARD_LIMIT > 0 and (argd['wl'] > CFG_WEBSEARCH_WILDCARD_LIMIT or argd['wl'] == 0):
            if acc_authorize_action(req, 'runbibedit')[0] != 0:
                argd['wl'] = CFG_WEBSEARCH_WILDCARD_LIMIT

        # only superadmins can use verbose parameter for obtaining debug information
        if not isUserSuperAdmin(user_info):
            argd['verbose'] = 0

        if auth_code and user_info['email'] == 'guest':
            cookie = mail_cookie_create_authorize_action(VIEWRESTRCOLL, {'collection' : guess_primary_collection_of_a_record(self.recid)})
            target = CFG_SITE_SECURE_URL + '/youraccount/login' + \
                    make_canonical_urlargd({'action': cookie, 'ln' : argd['ln'], 'referer' : CFG_SITE_SECURE_URL + req.unparsed_uri}, {})
            return redirect_to_url(req, target, norobot=True)
        elif auth_code:
            return page_not_authorized(req, "../", \
                text=auth_msg, \
                navmenuid='search')

        from invenio.legacy.search_engine import record_exists, get_merged_recid
        # check if the current record has been deleted
        # and has been merged, case in which the deleted record
        # will be redirect to the new one
        record_status = record_exists(argd['recid'])
        merged_recid = get_merged_recid(argd['recid'])
        if record_status == -1 and merged_recid:
            url = CFG_SITE_URL + '/' + CFG_SITE_RECORD + '/%s?ln=%s'
            url %= (str(merged_recid), argd['ln'])
            redirect_to_url(req, url)
        elif record_status == -1:
            req.status = apache.HTTP_GONE ## The record is gone!

        # mod_python does not like to return [] in case when of=id:
        out = perform_request_search(req, **argd)
        if isinstance(out, intbitset):
            return out.fastdump()
        elif out == []:
            return str(out)
        else:
            return out
예제 #3
0
파일: views.py 프로젝트: k3njiy/invenio
    def decorated(recid, *args, **kwargs):
        from invenio.legacy.search_engine import \
            guess_primary_collection_of_a_record, \
            check_user_can_view_record

        # ensure recid to be integer
        recid = int(recid)
        g.bibrec = Bibrec.query.get(recid)

        record = get_record(recid)
        if record is None:
            return render_template('404.html')

        g.collection = collection = Collection.query.filter(
            Collection.name == guess_primary_collection_of_a_record(recid)).\
            one()

        (auth_code, auth_msg) = check_user_can_view_record(current_user, recid)

        # only superadmins can use verbose parameter for obtaining debug
        # information
        if not current_user.is_super_admin and 'verbose' in kwargs:
            kwargs['verbose'] = 0

        if auth_code:
            flash(auth_msg, 'error')
            abort(apache.HTTP_UNAUTHORIZED)

        from invenio.legacy.search_engine import record_exists, \
            get_merged_recid
        # check if the current record has been deleted
        # and has been merged, case in which the deleted record
        # will be redirect to the new one
        record_status = record_exists(recid)
        merged_recid = get_merged_recid(recid)
        if record_status == -1 and merged_recid:
            return redirect(url_for('record.metadata', recid=merged_recid))
        elif record_status == -1:
            abort(apache.HTTP_GONE)  # The record is gone!

        title = record.get(cfg.get('RECORDS_BREADCRUMB_TITLE_KEY'), '')
        tabs = []

        def _format_record(recid, of='hd', user_info=current_user, *args,
                           **kwargs):
            from invenio.modules.formatter import format_record
            return format_record(recid, of, user_info=user_info, *args,
                                 **kwargs)

        @register_template_context_processor
        def record_context():
            from invenio.modules.comments.api import get_mini_reviews
            return dict(recid=recid,
                        record=record,
                        tabs=tabs,
                        title=title,
                        get_mini_reviews=get_mini_reviews,
                        collection=collection,
                        format_record=_format_record
                        )

        pre_template_render.send(
            "%s.%s" % (blueprint.name, f.__name__),
            recid=recid,
        )
        return f(recid, *args, **kwargs)
예제 #4
0
파일: views.py 프로젝트: jirikuncar/invenio
    def decorated(recid, *args, **kwargs):
        from invenio.modules.access.mailcookie import mail_cookie_create_authorize_action
        from invenio.modules.access.local_config import VIEWRESTRCOLL
        from invenio.legacy.search_engine import guess_primary_collection_of_a_record, check_user_can_view_record

        # ensure recid to be integer
        recid = int(recid)
        g.collection = collection = Collection.query.filter(
            Collection.name == guess_primary_collection_of_a_record(recid)
        ).one()

        (auth_code, auth_msg) = check_user_can_view_record(current_user, recid)

        # only superadmins can use verbose parameter for obtaining debug
        # information
        if not current_user.is_super_admin and "verbose" in kwargs:
            kwargs["verbose"] = 0

        if auth_code and current_user.is_guest:
            cookie = mail_cookie_create_authorize_action(VIEWRESTRCOLL, {"collection": g.collection.name})
            url_args = {"action": cookie, "ln": g.ln, "referer": request.url}
            flash(_("Authorization failure"), "error")
            return redirect(url_for("webaccount.login", **url_args))
        elif auth_code:
            flash(auth_msg, "error")
            abort(apache.HTTP_UNAUTHORIZED)

        from invenio.legacy.search_engine import record_exists, get_merged_recid

        # check if the current record has been deleted
        # and has been merged, case in which the deleted record
        # will be redirect to the new one
        record_status = record_exists(recid)
        merged_recid = get_merged_recid(recid)
        if record_status == -1 and merged_recid:
            return redirect(url_for("record.metadata", recid=merged_recid))
        elif record_status == -1:
            abort(apache.HTTP_GONE)  # The record is gone!

        g.bibrec = Bibrec.query.get(recid)
        record = get_record(recid)

        if record is None:
            return render_template("404.html")

        title = record.get(cfg.get("RECORDS_BREADCRUMB_TITLE_KEY"), "")
        tabs = []

        if cfg.get("CFG_WEBLINKBACK_TRACKBACK_ENABLED"):

            @register_template_context_processor
            def trackback_context():
                from invenio.legacy.weblinkback.templates import get_trackback_auto_discovery_tag

                return {"headerLinkbackTrackbackLink": get_trackback_auto_discovery_tag(recid)}

        def _format_record(recid, of="hd", user_info=current_user, *args, **kwargs):
            from invenio.modules.formatter import format_record

            return format_record(recid, of, user_info=user_info, *args, **kwargs)

        @register_template_context_processor
        def record_context():
            from invenio.modules.comments.api import get_mini_reviews

            return dict(
                recid=recid,
                record=record,
                tabs=tabs,
                title=title,
                get_mini_reviews=get_mini_reviews,
                collection=collection,
                format_record=_format_record,
            )

        pre_template_render.send("%s.%s" % (blueprint.name, f.__name__), recid=recid)
        return f(recid, *args, **kwargs)
예제 #5
0
파일: views.py 프로젝트: chokribr/invenio-1
    def decorated(recid, *args, **kwargs):
        from invenio.modules.access.mailcookie import \
            mail_cookie_create_authorize_action
        from invenio.modules.access.local_config import VIEWRESTRCOLL
        from invenio.legacy.search_engine import \
            guess_primary_collection_of_a_record, \
            check_user_can_view_record
        # ensure recid to be integer
        recid = int(recid)
        g.collection = collection = Collection.query.filter(
            Collection.name == guess_primary_collection_of_a_record(recid)).\
            one()
        g.bibrec = Bibrec.query.get(recid)

        record = get_record(recid)
        if record is None:
            return render_template('404.html')

        (auth_code, auth_msg) = check_user_can_view_record(current_user, recid)

        # only superadmins can use verbose parameter for obtaining debug
        # information
        if not current_user.is_super_admin and 'verbose' in kwargs:
            kwargs['verbose'] = 0

        if auth_code:
            flash(auth_msg, 'error')
            abort(apache.HTTP_UNAUTHORIZED)

        from invenio.legacy.search_engine import record_exists, \
            get_merged_recid
        # check if the current record has been deleted
        # and has been merged, case in which the deleted record
        # will be redirect to the new one
        record_status = record_exists(recid)
        merged_recid = get_merged_recid(recid)
        if record_status == -1 and merged_recid:
            return redirect(url_for('record.metadata', recid=merged_recid))
        elif record_status == -1:
            abort(apache.HTTP_GONE)  # The record is gone!

        title = record.get(cfg.get('RECORDS_BREADCRUMB_TITLE_KEY'), '')
        tabs = []

        if cfg.get('CFG_WEBLINKBACK_TRACKBACK_ENABLED'):

            @register_template_context_processor
            def trackback_context():
                from invenio.legacy.weblinkback.templates import \
                    get_trackback_auto_discovery_tag
                return {
                    'headerLinkbackTrackbackLink':
                    get_trackback_auto_discovery_tag(recid)
                }

        def _format_record(recid,
                           of='hd',
                           user_info=current_user,
                           *args,
                           **kwargs):
            from invenio.modules.formatter import format_record
            return format_record(recid,
                                 of,
                                 user_info=user_info,
                                 *args,
                                 **kwargs)

        @register_template_context_processor
        def record_context():
            from invenio.modules.comments.api import get_mini_reviews
            return dict(recid=recid,
                        record=record,
                        tabs=tabs,
                        title=title,
                        get_mini_reviews=get_mini_reviews,
                        collection=collection,
                        format_record=_format_record)

        pre_template_render.send(
            "%s.%s" % (blueprint.name, f.__name__),
            recid=recid,
        )
        return f(recid, *args, **kwargs)
예제 #6
0
파일: utils.py 프로젝트: chokribr/invenio-1
def record_get_xml(recID, format='xm', decompress=zlib.decompress,
                   on_the_fly=False):
    """
    Returns an XML string of the record given by recID.

    The function builds the XML directly from the database,
    without using the standard formatting process.

    'format' allows to define the flavour of XML:
        - 'xm' for standard XML
        - 'marcxml' for MARC XML
        - 'oai_dc' for OAI Dublin Core
        - 'xd' for XML Dublin Core

    If record does not exist, returns empty string.
    If the record is deleted, returns an empty MARCXML (with recid
    controlfield, OAI ID fields and 980__c=DELETED)

    @param recID: the id of the record to retrieve
    @param format: the format to use
    @param on_the_fly: if False, try to fetch precreated one in database
    @param decompress: the library to use to decompress cache from DB
    @return: the xml string of the record
    """
    from invenio.legacy.search_engine import record_exists

    def get_creation_date(recID, fmt="%Y-%m-%d"):
        "Returns the creation date of the record 'recID'."
        out = ""
        res = run_sql("SELECT DATE_FORMAT(creation_date,%s) FROM bibrec WHERE id=%s", (fmt, recID), 1)
        if res:
            out = res[0][0]
        return out

    def get_modification_date(recID, fmt="%Y-%m-%d"):
        "Returns the date of last modification for the record 'recID'."
        out = ""
        res = run_sql("SELECT DATE_FORMAT(modification_date,%s) FROM bibrec WHERE id=%s", (fmt, recID), 1)
        if res:
            out = res[0][0]
        return out

    #_ = gettext_set_language(ln)

    out = ""

    # sanity check:
    record_exist_p = record_exists(recID)
    if record_exist_p == 0: # doesn't exist
        return out

    # print record opening tags, if needed:
    if format == "marcxml" or format == "oai_dc":
        out += "  <record>\n"
        out += "   <header>\n"

        for identifier in get_fieldvalues(recID, CFG_OAI_ID_FIELD):
            out += "    <identifier>%s</identifier>\n" % identifier
        out += "    <datestamp>%s</datestamp>\n" % get_modification_date(recID)
        out += "   </header>\n"
        out += "   <metadata>\n"

    if format.startswith("xm") or format == "marcxml":
        res = None
        if on_the_fly is False:
            # look for cached format existence:
            query = """SELECT value FROM bibfmt WHERE
            id_bibrec='%s' AND format='%s'""" % (recID, format)
            res = run_sql(query, None, 1)
        if res and record_exist_p == 1:
            # record 'recID' is formatted in 'format', so print it
            out += "%s" % decompress(res[0][0])
        else:
            # record 'recID' is not formatted in 'format' -- they are
            # not in "bibfmt" table; so fetch all the data from
            # "bibXXx" tables:
            if format == "marcxml":
                out += """    <record xmlns="http://www.loc.gov/MARC21/slim">\n"""
                out += "        <controlfield tag=\"001\">%d</controlfield>\n" % int(recID)
            elif format.startswith("xm"):
                out += """    <record>\n"""
                out += "        <controlfield tag=\"001\">%d</controlfield>\n" % int(recID)
            if record_exist_p == -1:
                # deleted record, so display only OAI ID and 980:
                oai_ids = get_fieldvalues(recID, CFG_OAI_ID_FIELD)
                if oai_ids:
                    out += "<datafield tag=\"%s\" ind1=\"%s\" ind2=\"%s\"><subfield code=\"%s\">%s</subfield></datafield>\n" % \
                           (CFG_OAI_ID_FIELD[0:3],
                            CFG_OAI_ID_FIELD[3:4],
                            CFG_OAI_ID_FIELD[4:5],
                            CFG_OAI_ID_FIELD[5:6],
                            oai_ids[0])
                out += "<datafield tag=\"980\" ind1=\" \" ind2=\" \"><subfield code=\"c\">DELETED</subfield></datafield>\n"
                from invenio.legacy.search_engine import get_merged_recid
                merged_recid = get_merged_recid(recID)
                if merged_recid: # record was deleted but merged to other record, so display this information:
                    out += "<datafield tag=\"970\" ind1=\" \" ind2=\" \"><subfield code=\"d\">%d</subfield></datafield>\n" % merged_recid
            else:
                # controlfields
                query = "SELECT b.tag,b.value,bb.field_number FROM bib00x AS b, bibrec_bib00x AS bb "\
                        "WHERE bb.id_bibrec='%s' AND b.id=bb.id_bibxxx AND b.tag LIKE '00%%' "\
                        "ORDER BY bb.field_number, b.tag ASC" % recID
                res = run_sql(query)
                for row in res:
                    field, value = row[0], row[1]
                    value = encode_for_xml(value)
                    out += """        <controlfield tag="%s">%s</controlfield>\n""" % \
                           (encode_for_xml(field[0:3]), value)
                # datafields
                i = 1 # Do not process bib00x and bibrec_bib00x, as
                      # they are controlfields. So start at bib01x and
                      # bibrec_bib00x (and set i = 0 at the end of
                      # first loop)
                for digit1 in range(0, 10):
                    for digit2 in range(i, 10):
                        bx = "bib%d%dx" % (digit1, digit2)
                        bibx = "bibrec_bib%d%dx" % (digit1, digit2)
                        query = "SELECT b.tag,b.value,bb.field_number FROM %s AS b, %s AS bb "\
                                "WHERE bb.id_bibrec='%s' AND b.id=bb.id_bibxxx AND b.tag LIKE '%s%%' "\
                                "ORDER BY bb.field_number, b.tag ASC" % (bx,
                                                                         bibx,
                                                                         recID,
                                                                         str(digit1)+str(digit2))
                        res = run_sql(query)
                        field_number_old = -999
                        field_old = ""
                        for row in res:
                            field, value, field_number = row[0], row[1], row[2]
                            ind1, ind2 = field[3], field[4]
                            if ind1 == "_" or ind1 == "":
                                ind1 = " "
                            if ind2 == "_" or ind2 == "":
                                ind2 = " "
                            # print field tag
                            if field_number != field_number_old or \
                                   field[:-1] != field_old[:-1]:
                                if field_number_old != -999:
                                    out += """        </datafield>\n"""
                                out += """        <datafield tag="%s" ind1="%s" ind2="%s">\n""" % \
                                       (encode_for_xml(field[0:3]),
                                        encode_for_xml(ind1),
                                        encode_for_xml(ind2))
                                field_number_old = field_number
                                field_old = field
                            # print subfield value
                            value = encode_for_xml(value)
                            out += """            <subfield code="%s">%s</subfield>\n""" % \
                                   (encode_for_xml(field[-1:]), value)

                        # all fields/subfields printed in this run, so close the tag:
                        if field_number_old != -999:
                            out += """        </datafield>\n"""
                    i = 0 # Next loop should start looking at bib%0 and bibrec_bib00x
            # we are at the end of printing the record:
            out += "    </record>\n"

    elif format == "xd" or format == "oai_dc":
        # XML Dublin Core format, possibly OAI -- select only some bibXXx fields:
        out += """    <dc xmlns="http://purl.org/dc/elements/1.1/"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                         xsi:schemaLocation="http://purl.org/dc/elements/1.1/
                                             http://www.openarchives.org/OAI/1.1/dc.xsd">\n"""
        if record_exist_p == -1:
            out += ""
        else:
            for f in get_fieldvalues(recID, "041__a"):
                out += "        <language>%s</language>\n" % f

            for f in get_fieldvalues(recID, "100__a"):
                out += "        <creator>%s</creator>\n" % encode_for_xml(f)

            for f in get_fieldvalues(recID, "700__a"):
                out += "        <creator>%s</creator>\n" % encode_for_xml(f)

            for f in get_fieldvalues(recID, "245__a"):
                out += "        <title>%s</title>\n" % encode_for_xml(f)

            for f in get_fieldvalues(recID, "65017a"):
                out += "        <subject>%s</subject>\n" % encode_for_xml(f)

            for f in get_fieldvalues(recID, "8564_u"):
                out += "        <identifier>%s</identifier>\n" % encode_for_xml(f)

            for f in get_fieldvalues(recID, "520__a"):
                out += "        <description>%s</description>\n" % encode_for_xml(f)

            out += "        <date>%s</date>\n" % get_creation_date(recID)
        out += "    </dc>\n"


    # print record closing tags, if needed:
    if format == "marcxml" or format == "oai_dc":
        out += "   </metadata>\n"
        out += "  </record>\n"

    return out
예제 #7
0
파일: views.py 프로젝트: cjhak/b2share
    def decorated(recid, *args, **kwargs):
        from invenio.modules.access.mailcookie import \
            mail_cookie_create_authorize_action
        from invenio.modules.access.local_config import VIEWRESTRCOLL
        from invenio.legacy.search_engine import \
            guess_primary_collection_of_a_record, \
            check_user_can_view_record
        from invenio.b2share.modules.main.utils import check_fresh_record
        # ensure recid to be integer
        recid = int(recid)

        from invenio.legacy.search_engine import record_exists, get_merged_recid
        if record_exists(recid) == 0:
            # record doesn't exist, abort so it doesn't get incorrectly cached
            abort(apache.HTTP_NOT_FOUND)  # The record is gone!
        if check_fresh_record(current_user, recid):
            return render_template('record_waitforit.html', recid=recid)

        g.collection = collection = Collection.query.filter(
            Collection.name == guess_primary_collection_of_a_record(recid)).\
            one()

        (auth_code, auth_msg) = check_user_can_view_record(current_user, recid)

        # only superadmins can use verbose parameter for obtaining debug
        # information
        if not current_user.is_super_admin and 'verbose' in kwargs:
            kwargs['verbose'] = 0

        if auth_code and current_user.is_guest:
            cookie = mail_cookie_create_authorize_action(
                VIEWRESTRCOLL, {'collection': g.collection.name})
            url_args = {'action': cookie, 'ln': g.ln, 'referer': request.url}
            flash(_("Authorization failure"), 'error')
            return redirect(url_for('webaccount.login', **url_args))
        elif auth_code:
            flash(auth_msg, 'error')
            abort(apache.HTTP_UNAUTHORIZED)

        from invenio.legacy.search_engine import record_exists, \
            get_merged_recid
        # check if the current record has been deleted
        # and has been merged, case in which the deleted record
        # will be redirect to the new one
        record_status = record_exists(recid)
        merged_recid = get_merged_recid(recid)
        if record_status == -1 and merged_recid:
            return redirect(url_for('record.metadata', recid=merged_recid))
        elif record_status == -1:
            abort(apache.HTTP_GONE)  # The record is gone!

        g.bibrec = Bibrec.query.get(recid)
        record = get_record(recid)

        if record is None:
            return render_template('404.html')

        title = record.get(cfg.get('RECORDS_BREADCRUMB_TITLE_KEY'), '')
        tabs = []

        if cfg.get('CFG_WEBLINKBACK_TRACKBACK_ENABLED'):

            @register_template_context_processor
            def trackback_context():
                from invenio.legacy.weblinkback.templates import \
                    get_trackback_auto_discovery_tag
                return {
                    'headerLinkbackTrackbackLink':
                    get_trackback_auto_discovery_tag(recid)
                }

        def _format_record(recid,
                           of='hd',
                           user_info=current_user,
                           *args,
                           **kwargs):
            from invenio.modules.formatter import format_record
            return format_record(recid,
                                 of,
                                 user_info=user_info,
                                 *args,
                                 **kwargs)

        @register_template_context_processor
        def record_context():
            from invenio.modules.comments.api import get_mini_reviews
            from invenio.legacy.bibdocfile.api import BibRecDocs
            all_files = [f for f in BibRecDocs(recid, human_readable=True).list_latest_files(list_hidden=False) \
                         if not f.is_icon()]
            files = [
                f for f in all_files if f.is_restricted(current_user)[0] == 0
            ]
            has_private_files = len(files) < len(all_files)
            return dict(recid=recid,
                        record=record,
                        tabs=tabs,
                        title=title,
                        get_mini_reviews=get_mini_reviews,
                        collection=collection,
                        format_record=_format_record,
                        has_private_files=has_private_files,
                        files=files)

        pre_template_render.send(
            "%s.%s" % (blueprint.name, f.__name__),
            recid=recid,
        )
        return f(recid, *args, **kwargs)