feat(archive): add pagination
This commit is contained in:
parent
be6e2dad68
commit
2c88d9b973
@ -20,7 +20,8 @@ BASE_DIR = Path(__file__).resolve().parent.parent
|
|||||||
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
# SECURITY WARNING: keep the secret key used in production secret!
|
||||||
SECRET_KEY = os.getenv('SECRET', 'django-insecure-c%g@wujt4dco#e%k-!25o3)0%t+wm5=k%l(m!kk^p_g%kknod!')
|
SECRET_KEY = os.getenv(
|
||||||
|
'SECRET', 'django-insecure-c%g@wujt4dco#e%k-!25o3)0%t+wm5=k%l(m!kk^p_g%kknod!')
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
# SECURITY WARNING: don't run with debug turned on in production!
|
||||||
DEBUG = os.getenv('DEBUG', 'False')
|
DEBUG = os.getenv('DEBUG', 'False')
|
||||||
@ -156,3 +157,5 @@ REST_FRAMEWORK = {
|
|||||||
'rest_framework.permissions.IsAuthenticated',
|
'rest_framework.permissions.IsAuthenticated',
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
URLS_PER_PAGE = 20
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<div class="post-preview">
|
||||||
{% if urls|length > 0 %}
|
{% if urls|length > 0 %}
|
||||||
{% for url in urls %}
|
{% for url in urls %}
|
||||||
<!-- Post preview-->
|
<!-- Post preview-->
|
||||||
@ -23,8 +24,25 @@
|
|||||||
<hr class="my-4" />
|
<hr class="my-4" />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class="post-preview">
|
|
||||||
<h2 class="post-title">У вас нет ссылок в архиве</h2>
|
<h2 class="post-title">У вас нет ссылок в архиве</h2>
|
||||||
</div>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="pagination container row justify-content-end">
|
||||||
|
<div></div>
|
||||||
|
<div class="step-links col-auto">
|
||||||
|
{% if urls.has_previous %}
|
||||||
|
<a href="?page=1">«</a>
|
||||||
|
<a href="?page={{ urls.previous_page_number }}">‹</a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<span class="current">
|
||||||
|
страница {{ urls.number }} из {{ urls.paginator.num_pages }}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
{% if urls.has_next %}
|
||||||
|
<a href="?page={{ urls.next_page_number }}">›</a>
|
||||||
|
<a href="?page={{ urls.paginator.num_pages }}">»</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -1,6 +1,8 @@
|
|||||||
from multiprocessing import context
|
from multiprocessing import context
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
|
from django.core.paginator import Paginator
|
||||||
|
from django.conf import settings
|
||||||
from later42.models.urls import URL
|
from later42.models.urls import URL
|
||||||
|
|
||||||
|
|
||||||
@ -22,6 +24,9 @@ def archive(request, url_id=None):
|
|||||||
try:
|
try:
|
||||||
urls = URL.objects.filter(
|
urls = URL.objects.filter(
|
||||||
user=request.user, archived=True).order_by('-id')
|
user=request.user, archived=True).order_by('-id')
|
||||||
|
paginator = Paginator(urls, settings.URLS_PER_PAGE)
|
||||||
|
page_number = request.GET.get('page')
|
||||||
|
urls = paginator.get_page(page_number)
|
||||||
except:
|
except:
|
||||||
urls = []
|
urls = []
|
||||||
context = {'urls': urls}
|
context = {'urls': urls}
|
||||||
|
Loading…
Reference in New Issue
Block a user