wuyue92tree/django-adminlte-ui

adminlteui/templates/admin/pagination.html, error at line 31 -> {% adminlte_paginator_number cl i %}

boazcstrike opened this issue · 3 comments

I want to share with you an error that occurred on a huge dataset count.

The error was:

Exception Value: | can only concatenate str (not "int") to str
Exception Location: adminlteui/templatetags/adminlte_list.py, line 42, in adminlte_paginator_number

adminlteui/templates/admin/pagination.html, error at line 31

<div class="col-sm-7">
    <div class="dataTables_paginate paging_simple_numbers"
         id="example2_paginate">
        <ul class="pagination">
            {% if pagination_required %}
            <li class="paginate_button previous disabled"
                id="example2_previous">
                <a href="#" aria-controls="example2" data-dt-idx="0"
                   tabindex="0">{% trans 'Previous' %}</a></li>
            {% for i in page_range %}
            {% adminlte_paginator_number cl i %} <----- error occurred here
            {% endfor %}
            <li class="paginate_button next disabled" id="example2_next">
                <a href="#"
                   aria-controls="example2"
                   data-dt-idx="7"
                   tabindex="0">{% trans 'Next' %}</a>
            </li>
            {% endif %}
        </ul>
    </div>
</div>

Exception Location: adminlteui/templatetags/adminlte_list.py, line 42, in adminlte_paginator_number

@register.simple_tag
def adminlte_paginator_number(cl, i):
    """
    Generate an individual page index link in a paginated list.
    """
    if i == DOT:
        # <li class="paginate_button active"><a href="#" aria-controls="example2" data-dt-idx="3" tabindex="0">{}</a></li>'
        return format_html(
            '<li class="paginate_button"><a href="javascript:void(0);" aria-controls="example2" data-dt-idx="3" tabindex="0">… </a></li>')
    elif i == cl.page_num:
        return format_html(
            '<li class="paginate_button active"><a href="javascript:void(0);" aria-controls="example2" data-dt-idx="3" tabindex="0">{}</a></li>',
            i + 1)
    else:
        return format_html(
            '<li class="paginate_button "><a href="{}" {} aria-controls="example2" data-dt-idx="3" tabindex="0">{}</a></li>',
            cl.get_query_string({PAGE_VAR: i}),
            mark_safe(
                ' class="end"' if i == cl.paginator.num_pages - 1 else ''),
            i + 1, # <----------------- line 42 error
        )

Hope this helps.

I have the same problem as you

重写一下这个方法即可
Uploading 微信图片_20210712103251.png…

I've created a temporary fix for this

@register.simple_tag
def adminlte_paginator_number(cl, i):
    """
    Generate an individual page index link in a paginated list.
    """
    if i == DOT:
        # <li class="paginate_button active"><a href="#" aria-controls="example2" data-dt-idx="3" tabindex="0">{}</a></li>'
        return format_html(
            '<li class="paginate_button"><a href="javascript:void(0);" aria-controls="example2" data-dt-idx="3" tabindex="0">… </a></li>')
    elif i == cl.page_num:
        return format_html(
            '<li class="paginate_button active"><a href="javascript:void(0);" aria-controls="example2" data-dt-idx="3" tabindex="0">{}</a></li>',
            i + 1)
    else:
        return format_html(
            '<li class="paginate_button "><a href="{}" {} aria-controls="example2" data-dt-idx="3" tabindex="0">{}</a></li>',
            cl.get_query_string({PAGE_VAR: i}),
            mark_safe(
                ' class="end"' if i == cl.paginator.num_pages - 1 else ''),
            # i + 1, # <----------------- line 42 error
# changed to string,
            '>',
        )

Hope these help.