mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 18:44:23 +00:00
sas: add pagination on AlbumView
This commit is contained in:
parent
8330e1eaf2
commit
b8ad2d4835
@ -114,22 +114,24 @@
|
|||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
{% macro paginate(page_obj, paginator) %}
|
{% macro paginate(page_obj, paginator) %}
|
||||||
|
{% if page_obj.has_previous() or page_obj.has_next() %}
|
||||||
{% if page_obj.has_previous() %}
|
{% if page_obj.has_previous() %}
|
||||||
<a href="?page={{ page_obj.previous_page_number() }}">{% trans %}Previous{% endtrans %}</a>
|
<a href="?page={{ page_obj.previous_page_number() }}">{% trans %}Previous{% endtrans %}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<span class="disabled">{% trans %}Previous{% endtrans %}</span>
|
<span class="disabled">{% trans %}Previous{% endtrans %}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for i in paginator.page_range %}
|
{% for i in paginator.page_range %}
|
||||||
{% if page_obj.number == i %}
|
{% if page_obj.number == i %}
|
||||||
<span class="active">{{ i }} <span class="sr-only">({% trans %}current{% endtrans %})</span></span>
|
<span class="active">{{ i }} <span class="sr-only">({% trans %}current{% endtrans %})</span></span>
|
||||||
|
{% else %}
|
||||||
|
<a href="?page={{ i }}">{{ i }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% if page_obj.has_next() %}
|
||||||
|
<a href="?page={{ page_obj.next_page_number() }}">{% trans %}Next{% endtrans %}</a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="?page={{ i }}">{{ i }}</a>
|
<span class="disabled">{% trans %}Next{% endtrans %}</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
|
||||||
{% if page_obj.has_next() %}
|
|
||||||
<a href="?page={{ page_obj.next_page_number() }}">{% trans %}Next{% endtrans %}</a>
|
|
||||||
{% else %}
|
|
||||||
<span class="disabled">{% trans %}Next{% endtrans %}</span>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{% extends "core/base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
|
{% from "core/macros.jinja" import paginate %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
{% trans %}SAS{% endtrans %}
|
{% trans %}SAS{% endtrans %}
|
||||||
@ -62,7 +63,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{% for p in album.children_pictures.order_by('id') %}
|
{% for p in pictures %}
|
||||||
<div style="display: inline-block;">
|
<div style="display: inline-block;">
|
||||||
{% if edit_mode %}
|
{% if edit_mode %}
|
||||||
<input type="checkbox" name="file_list" value="{{ p.id }}">
|
<input type="checkbox" name="file_list" value="{{ p.id }}">
|
||||||
@ -77,6 +78,8 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
<br>
|
||||||
|
{{ paginate(pictures, paginator) }}
|
||||||
{% if edit_mode %}
|
{% if edit_mode %}
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
18
sas/views.py
18
sas/views.py
@ -23,7 +23,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse, Http404
|
||||||
from django.core.urlresolvers import reverse_lazy, reverse
|
from django.core.urlresolvers import reverse_lazy, reverse
|
||||||
from core.views.forms import SelectDate
|
from core.views.forms import SelectDate
|
||||||
from django.views.generic import DetailView, TemplateView
|
from django.views.generic import DetailView, TemplateView
|
||||||
@ -32,6 +32,7 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
|
from django.core.paginator import Paginator, InvalidPage
|
||||||
|
|
||||||
from ajax_select import make_ajax_field
|
from ajax_select import make_ajax_field
|
||||||
from ajax_select.fields import AutoCompleteSelectMultipleField
|
from ajax_select.fields import AutoCompleteSelectMultipleField
|
||||||
@ -252,6 +253,14 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
|
|||||||
form_class = SASForm
|
form_class = SASForm
|
||||||
pk_url_kwarg = "album_id"
|
pk_url_kwarg = "album_id"
|
||||||
template_name = "sas/album.jinja"
|
template_name = "sas/album.jinja"
|
||||||
|
paginate_by = settings.SITH_SAS_IMAGES_PER_PAGE
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
try:
|
||||||
|
self.asked_page = int(request.GET.get("page", 1))
|
||||||
|
except ValueError:
|
||||||
|
raise Http404
|
||||||
|
return super(AlbumView, self).dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
self.form = self.get_form()
|
self.form = self.get_form()
|
||||||
@ -291,6 +300,13 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
|
|||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs = super(AlbumView, self).get_context_data(**kwargs)
|
kwargs = super(AlbumView, self).get_context_data(**kwargs)
|
||||||
|
kwargs["paginator"] = Paginator(
|
||||||
|
self.object.children_pictures.order_by("id"), self.paginate_by
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
kwargs["pictures"] = kwargs["paginator"].page(self.asked_page)
|
||||||
|
except InvalidPage:
|
||||||
|
raise Http404
|
||||||
kwargs["form"] = self.form
|
kwargs["form"] = self.form
|
||||||
kwargs["clipboard"] = SithFile.objects.filter(
|
kwargs["clipboard"] = SithFile.objects.filter(
|
||||||
id__in=self.request.session["clipboard"]
|
id__in=self.request.session["clipboard"]
|
||||||
|
@ -338,6 +338,7 @@ SITH_FORUM_PAGE_LENGTH = 30
|
|||||||
|
|
||||||
# SAS variables
|
# SAS variables
|
||||||
SITH_SAS_ROOT_DIR_ID = 4
|
SITH_SAS_ROOT_DIR_ID = 4
|
||||||
|
SITH_SAS_IMAGES_PER_PAGE = 30
|
||||||
|
|
||||||
SITH_BOARD_SUFFIX = "-bureau"
|
SITH_BOARD_SUFFIX = "-bureau"
|
||||||
SITH_MEMBER_SUFFIX = "-membres"
|
SITH_MEMBER_SUFFIX = "-membres"
|
||||||
|
Loading…
Reference in New Issue
Block a user