Returns all the comments (reviews) of a specific internal record or external basket record.
    :param recID:  record id where (internal record IDs > 0) or (external basket record IDs < -100)
    :param display_order:       hh = highest helpful score, review only
                                lh = lowest helpful score, review only
                                hs = highest star score, review only
                                ls = lowest star score, review only
                                od = oldest date
                                nd = newest date
    :param display_since:       all= no filtering by date
                                nd = n days ago
                                nw = n weeks ago
                                nm = n months ago
                                ny = n years ago
                                where n is a single digit integer between 0 and 9
    :param nb_per_page: number of results per page
    :param page: results page
    :param voted: boolean, active if user voted for a review, see perform_request_vote function
    :param reported: boolean, active if user reported a certain comment/review, perform_request_report function
    :param subscribed: int, 1 if user just subscribed to discussion, -1 if unsubscribed
    :param reviews: boolean, enabled if reviews, disabled for comments
    :param uid: the id of the user who is reading comments
    :param can_send_comments: if user can send comment or not
    :param can_attach_files: if user can attach file to comment or not
    :param user_is_subscribed_to_discussion: True if user already receives new comments by email
    :param user_can_unsubscribe_from_discussion: True is user is allowed to unsubscribe from discussion
    :return html body.

def perform_request_display_comments_or_remarks(
        req,
        recID,
        display_order='od',
        display_since='all',
        nb_per_page=100,
        page=1,
        ln=CFG_SITE_LANG,
        voted=-1,
        reported=-1,
        subscribed=0,
        reviews=0,
        uid=-1,
        can_send_comments=False,
        can_attach_files=False,
        user_is_subscribed_to_discussion=False,
        user_can_unsubscribe_from_discussion=False,
        display_comment_rounds=None):
    """
    Returns all the comments (reviews) of a specific internal record or external basket record.
    :param recID:  record id where (internal record IDs > 0) or (external basket record IDs < -100)
    :param display_order:       hh = highest helpful score, review only
                                lh = lowest helpful score, review only
                                hs = highest star score, review only
                                ls = lowest star score, review only
                                od = oldest date
                                nd = newest date
    :param display_since:       all= no filtering by date
                                nd = n days ago
                                nw = n weeks ago
                                nm = n months ago
                                ny = n years ago
                                where n is a single digit integer between 0 and 9
    :param nb_per_page: number of results per page
    :param page: results page
    :param voted: boolean, active if user voted for a review, see perform_request_vote function
    :param reported: boolean, active if user reported a certain comment/review, perform_request_report function
    :param subscribed: int, 1 if user just subscribed to discussion, -1 if unsubscribed
    :param reviews: boolean, enabled if reviews, disabled for comments
    :param uid: the id of the user who is reading comments
    :param can_send_comments: if user can send comment or not
    :param can_attach_files: if user can attach file to comment or not
    :param user_is_subscribed_to_discussion: True if user already receives new comments by email
    :param user_can_unsubscribe_from_discussion: True is user is allowed to unsubscribe from discussion
    :return html body.
    """
    _ = gettext_set_language(ln)

    warnings = []
    nb_reviews = 0
    nb_comments = 0

    # wash arguments
    recID = wash_url_argument(recID, 'int')
    ln = wash_language(ln)
    display_order = wash_url_argument(display_order, 'str')
    display_since = wash_url_argument(display_since, 'str')
    nb_per_page = wash_url_argument(nb_per_page, 'int')
    page = wash_url_argument(page, 'int')
    voted = wash_url_argument(voted, 'int')
    reported = wash_url_argument(reported, 'int')
    reviews = wash_url_argument(reviews, 'int')

    # vital argument check
    (valid, error_body) = check_recID_is_in_range(recID, warnings, ln)
    if not(valid):
        return error_body

    # CERN hack begins: filter out ATLAS comments
    from invenio.config import CFG_CERN_SITE
    if CFG_CERN_SITE:
        restricted_comments_p = False
        for report_number in get_fieldvalues(recID, '088__a'):
            if report_number.startswith("ATL-"):
                restricted_comments_p = True
                break
        if restricted_comments_p:
            err_code, err_msg = acc_authorize_action(
                uid, 'viewrestrcoll', collection='ATLAS Communications')
            if err_code:
                return err_msg
    # CERN hack ends

    # Query the database and filter results
    user_info = UserInfo(uid)
    res = query_retrieve_comments_or_remarks(
        recID,
        display_order,
        display_since,
        reviews,
        user_info=user_info)
    # res2 = query_retrieve_comments_or_remarks(recID, display_order, display_since, not reviews, user_info=user_info)
    nb_res = len(res)

    filters = [
        CmtRECORDCOMMENT.id_bibrec == recID,
        CmtRECORDCOMMENT.status.notin_(['dm', 'da'])
    ]

    nb_reviews = CmtRECORDCOMMENT.count(*(
        filters + [
            CmtRECORDCOMMENT.star_score > 0
        ]
    ))

    nb_comments = CmtRECORDCOMMENT.count(*(
        filters + [
            CmtRECORDCOMMENT.star_score == 0
        ]
    ))

    # checking non vital arguemnts - will be set to default if wrong
    # if page <= 0 or page.lower() != 'all':
    if page < 0:
        page = 1
        try:
            raise InvenioWebCommentWarning(
                _('Bad page number --> showing first page.'))
        except InvenioWebCommentWarning as exc:
            register_exception(stream='warning', req=req)
            warnings.append((exc.message, ''))
        # warnings.append(('WRN_WEBCOMMENT_INVALID_PAGE_NB',))
    if nb_per_page < 0:
        nb_per_page = 100
        try:
            raise InvenioWebCommentWarning(
                _('Bad number of results per page --> showing 10 results per page.'))
        except InvenioWebCommentWarning as exc:
            register_exception(stream='warning', req=req)
            warnings.append((exc.message, ''))
        # warnings.append(('WRN_WEBCOMMENT_INVALID_NB_RESULTS_PER_PAGE',))
    if CFG_WEBCOMMENT_ALLOW_REVIEWS and reviews:
        if display_order not in ['od', 'nd', 'hh', 'lh', 'hs', 'ls']:
            display_order = 'hh'
            try:
                raise InvenioWebCommentWarning(
                    _('Bad display order --> showing most helpful first.'))
            except InvenioWebCommentWarning as exc:
                register_exception(stream='warning', req=req)
                warnings.append((exc.message, ''))
            # warnings.append(('WRN_WEBCOMMENT_INVALID_REVIEW_DISPLAY_ORDER',))
    else:
        if display_order not in ['od', 'nd']:
            display_order = 'od'
            try:
                raise InvenioWebCommentWarning(
                    _('Bad display order --> showing oldest first.'))
            except InvenioWebCommentWarning as exc:
                register_exception(stream='warning', req=req)
                warnings.append((exc.message, ''))
            # warnings.append(('WRN_WEBCOMMENT_INVALID_DISPLAY_ORDER',))

    if not display_comment_rounds:
        display_comment_rounds = []

    # filter results according to page and number of reults per page
    if nb_per_page > 0:
        if nb_res > 0:
            last_page = int(math.ceil(nb_res / float(nb_per_page)))
        else:
            last_page = 1
        if page > last_page:
            page = 1
            try:
                raise InvenioWebCommentWarning(
                    _('Bad page number --> showing first page.'))
            except InvenioWebCommentWarning as exc:
                register_exception(stream='warning', req=req)
                warnings.append((exc.message, ''))
            # warnings.append(("WRN_WEBCOMMENT_INVALID_PAGE_NB",))
        if nb_res > nb_per_page:  # if more than one page of results
            if page < last_page:
                res = res[(page - 1) * (nb_per_page): (page * nb_per_page)]
            else:
                res = res[(page - 1) * (nb_per_page):]
        else:  # one page of results
            pass
    else:
        last_page = 1

    # Add information regarding visibility of comment for user
    user_collapsed_comments = get_user_collapsed_comments_for_record(
        uid,
        recID)
    if reviews:
        res = [row[:] + (row[10] in user_collapsed_comments,) for row in res]
    else:
        res = [row[:] + (row[6] in user_collapsed_comments,) for row in res]

    # Send to template
    avg_score = 0.0
    # comments not allowed by admin
    if not CFG_WEBCOMMENT_ALLOW_COMMENTS and not CFG_WEBCOMMENT_ALLOW_REVIEWS:
        try:
            raise InvenioWebCommentError(
                _('Comments on records have been disallowed by the administrator.'))
        except InvenioWebCommentError as exc:
            register_exception(req=req)
            body = webcomment_templates.tmpl_error(exc.message, ln)
            return body
       # errors.append(('ERR_WEBCOMMENT_COMMENTS_NOT_ALLOWED',))
    if reported > 0:
        try:
            raise InvenioWebCommentWarning(
                _('Your feedback has been recorded, many thanks.'))
        except InvenioWebCommentWarning as exc:
            register_exception(stream='warning', req=req)
            warnings.append((exc.message, 'green'))
        # warnings.append(('WRN_WEBCOMMENT_FEEDBACK_RECORDED',))
    elif reported == 0:
        try:
            raise InvenioWebCommentWarning(
                _('You have already reported an abuse for this comment.'))
        except InvenioWebCommentWarning as exc:
            register_exception(stream='warning', req=req)
            warnings.append((exc.message, ''))
        # warnings.append(('WRN_WEBCOMMENT_ALREADY_REPORTED',))
    elif reported == -2:
        try:
            raise InvenioWebCommentWarning(
                _('The comment you have reported no longer exists.'))
        except InvenioWebCommentWarning as exc:
            register_exception(stream='warning', req=req)
            warnings.append((exc.message, ''))
        # warnings.append(('WRN_WEBCOMMENT_INVALID_REPORT',))
    if CFG_WEBCOMMENT_ALLOW_REVIEWS and reviews:
        avg_score = calculate_avg_score(res)
        if voted > 0:
            try:
                raise InvenioWebCommentWarning(
                    _('Your feedback has been recorded, many thanks.'))
            except InvenioWebCommentWarning as exc:
                register_exception(stream='warning', req=req)
                warnings.append((exc.message, 'green'))
            # warnings.append(('WRN_WEBCOMMENT_FEEDBACK_RECORDED',))
        elif voted == 0:
            try:
                raise InvenioWebCommentWarning(
                    _('Sorry, you have already voted. This vote has not been recorded.'))
            except InvenioWebCommentWarning as exc:
                register_exception(stream='warning', req=req)
                warnings.append((exc.message, ''))
            # warnings.append(('WRN_WEBCOMMENT_ALREADY_VOTED',))
    if subscribed == 1:
        try:
            raise InvenioWebCommentWarning(
                _('You have been subscribed to this discussion. From now on, you will receive an email whenever a new comment is posted.'))
        except InvenioWebCommentWarning as exc:
            register_exception(stream='warning', req=req)
            warnings.append((exc.message, 'green'))
        # warnings.append(('WRN_WEBCOMMENT_SUBSCRIBED',))
    elif subscribed == -1:
        try:
            raise InvenioWebCommentWarning(
                _('You have been unsubscribed from this discussion.'))
        except InvenioWebCommentWarning as exc:
            register_exception(stream='warning', req=req)
            warnings.append((exc.message, 'green'))
        # warnings.append(('WRN_WEBCOMMENT_UNSUBSCRIBED',))

    grouped_comments = group_comments_by_round(res, reviews)

    # Clean list of comments round names
    if not display_comment_rounds:
        display_comment_rounds = []
    elif 'all' in display_comment_rounds:
        display_comment_rounds = [cmtgrp[0] for cmtgrp in grouped_comments]
    elif 'latest' in display_comment_rounds:
        if grouped_comments:
            display_comment_rounds.append(grouped_comments[-1][0])
        display_comment_rounds.remove('latest')

    body = webcomment_templates.tmpl_get_comments(
        req,
        recID,
        ln,
        nb_per_page,
        page,
        last_page,
        display_order,
        display_since,
        CFG_WEBCOMMENT_ALLOW_REVIEWS,
        grouped_comments,
        nb_comments,
        avg_score,
        warnings,
        border=0,
        reviews=reviews,
        total_nb_reviews=nb_reviews,
        uid=uid,
        can_send_comments=can_send_comments,
        can_attach_files=can_attach_files,
        user_is_subscribed_to_discussion=user_is_subscribed_to_discussion,
        user_can_unsubscribe_from_discussion=user_can_unsubscribe_from_discussion,
        display_comment_rounds=display_comment_rounds)
    return body