Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
django-better-elided-pagination
Advanced tools
A Django app to provide elided pagination that is just... better
Better Elided Pagination extends the Django Pagination class to provide elided pagination (pagination with ellipses) that does not change lengths when the selected page is near the start or end of the list. The list of pagination nodes will have a predictable and fixed length when the number of nodes exceeds the desired length of the node list.
The following illustrates the difference between Django's built in elided pagination and this project's "better" elided pagination:
Compatible with Django 3.0+
Compatible with Tailwind 1.9.6+ if using Tailwind CSS
This will install the latest stable release from PyPi.
pip install django-better-elided-pagination
The complete example in the next section assumes you are using Tailwind CSS in your project. The html_list property will generate a list of HTML nodes styled using Tailwind CSS classes. If you prefer to style the pagination nodes yourself, you may simply use:
from better_elided_pagination.paginators import BetterElidedPaginator
def some_view(request):
items = [str(x) for x in range(1, 41)] # the items to be paginated - can be a list or queryset
pagination = BetterElidedPaginator(
request,
items,
3, # items per page
)
elided_list = pagination.get_elided_page_range()
.get_elided_page_range() will return a generator fuction that you can comprehend into a list, or you can loop over to view the nodes:
print([p for p in elided_list])
The generator function will return a list of tuples with the first element representing the integer page number of the node, and the second element represeting the text label of the node.
The content that is being paginated (i.e. the actual list of items to be displayed) can be viewed by using the .item_list property of the BetterElidedPaginator class:
# continued from the example above:
item_list = pagination.item_list
print(item_list)
Import the BetterElidedPaginator to the .py file constructing pagination (views.py) in this example
# views.py
from better_elided_pagination.paginators import BetterElidedPaginator
Then use the class inside a view fuction:
# views.py
def homepage(request):
# the items to be paginated - can be a list or queryset
items = [str(x) for x in range(1, 41)]
pagination = BetterElidedPaginator(
request,
items,
3, # items per page
)
return render(request=request,
template_name="home.html",
context={
"pagination_items": pagination.html_list,
"display_items": pagination.item_list
})
In this example, the pagination is in its own template using Tailwind CSS:
# pagination.html
<div class="flex items-center space-x-1 w-full my-2">
{% for item in pagination_items %}
{{ item }}
{% endfor %}
</div>
css_classes = {
"tw_base": "rounded py-2 px-4 text-center",
"tw_enabled_hover": "hover:bg-blue-100 hover:text-gray-900 hover:shadow",
"tw_enabled_text_color": "text-gray-800",
"tw_disabled": "bg-transparent text-gray-500 cursor-default focus:shadow-none",
"tw_active": "text-white bg-blue-600 shadow-xl",
"outer_div": "",
}
FAQs
A Django app to provide elided pagination that is just... better
We found that django-better-elided-pagination demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.