Commit f417c5d1 authored by Floréal Cabanettes's avatar Floréal Cabanettes

Add pagination to recipes in panel

parent 69ecba16
......@@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-10-22 21:58+0200\n"
"PO-Revision-Date: 2017-10-22 21:59+0200\n"
"POT-Creation-Date: 2017-10-29 12:02+0100\n"
"PO-Revision-Date: 2017-10-29 12:03+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: fr\n"
......@@ -340,7 +340,7 @@ msgstr "Titre"
#: templates/panel/recipes.html:61
msgid "Author"
msgstr "Auteur :"
msgstr "Auteur"
#: templates/panel/recipes.html:70
msgid "Date"
......@@ -415,7 +415,7 @@ msgid "Cook:"
msgstr "Cuisson :"
#: templates/website/login.html:7 templates/website/login.html:19
#: templates/website/login.html:49 templates/website/sidebar.html:16
#: templates/website/login.html:49 templates/website/sidebar.html:17
msgid "Login"
msgstr "Connexion"
......@@ -427,11 +427,11 @@ msgstr "Votre nom d'utilisateur ou votre mot de passe est incorrect."
msgid "Please try again."
msgstr "Veuillez réessayer."
#: templates/website/login.html:39 templates/website/sidebar.html:20
#: templates/website/login.html:39 templates/website/sidebar.html:21
msgid "Username:"
msgstr "Nom d'utilisateur :"
#: templates/website/login.html:43 templates/website/sidebar.html:24
#: templates/website/login.html:43 templates/website/sidebar.html:25
msgid "Password:"
msgstr "Mot de passe :"
......@@ -490,7 +490,7 @@ msgctxt "category url"
msgid "category"
msgstr "categorie"
#: templates/website/sidebar.html:30
#: templates/website/sidebar.html:31
msgid "Login me"
msgstr "Se connecter"
......
......@@ -30,7 +30,27 @@ div.powered-by {
width: 200px;
}
form.top-actions select, form.top-actions button{
div.pagination {
float: right;
margin: 0;
height: 30px;
}
ul.pagination {
margin: 0;
}
div.list-recipes table {
margin-bottom: 10px;
}
@media screen and (max-width: 1180px) {
div.pagination.top {
float: none !important;
}
}
form.top-actions select, form.top-actions button, div.pagination{
display: inline-block;
vertical-align: middle;
margin-right: 5px;
......
......@@ -10,4 +10,5 @@ favicon_view = RedirectView.as_view(url='/static/favicon.ico', permanent=True)
urlpatterns = [
url(r'^$', IndexView.as_view(), name='index'),
url(r'^recipes/$', RecipesView.as_view(), name='recipes'),
url(r'^recipes/' + _("page") + '/(?P<page>\d+)$', RecipesView.as_view(), name='recipes_page'),
]
......@@ -10,6 +10,7 @@ from django.contrib.auth.models import User
from django_gravatar.helpers import get_gravatar_url
from .GenericView import GenericView
import locale
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
class RecipesView(View):
......@@ -18,7 +19,7 @@ class RecipesView(View):
def __sort_dates(a):
return a[0] + a[2]
def get(self, request):
def get(self, request, page=1):
if not self.request.user.is_authenticated:
return redirect('%s?next=%s' % (settings.LOGIN_URL, request.path))
recipes = Recipe.objects.all().order_by("pub_date").reverse()
......@@ -29,7 +30,12 @@ class RecipesView(View):
locale.setlocale(locale.LC_TIME, LOCALE)
all_dates = set()
show_recipes = []
for recipe in recipes:
paginator = Paginator(recipes, 15)
try:
page_recipe = paginator.page(page)
except (PageNotAnInteger, EmptyPage):
page_recipe = paginator.page(1)
for recipe in page_recipe:
month_int = recipe.pub_date.month
month = recipe.pub_date.strftime("%B")
year = recipe.pub_date.year
......@@ -70,5 +76,7 @@ class RecipesView(View):
"all_dates": all_dates,
"categories": GenericView.categories(),
"recipes": show_recipes,
"page_recipe": page_recipe,
"additionnal_kwargs": {},
}
return render(request, 'panel/recipes.html', context)
{% extends "panel/base.html" %}
{% load l10n %}
{% load i18n %}
{% load bootstrap_pagination %}
{% block content %}
<section class="content-header">
<h1>
......@@ -44,6 +45,10 @@
</select>
<button>{% trans "Filter" context "verb" %}</button>
</form>
<div class="pagination top">
{% bootstrap_paginate page_recipe url_view_name="recipes_page" url_extra_kwargs=additionnal_kwargs range=4 %}
</div>
</div>
<!-- Table -->
......@@ -110,5 +115,21 @@
</tbody>
</table>
</div>
<div class="form-apply-recipes">
<form class="grouped-actions top-actions" action="#">
<select class="form-control" id="sel-action">
<option>{% trans "Grouped actions" %}</option>
<option>{% trans "Publish" %}</option>
<option>{% trans "Unpublish" %}</option>
<option>{% trans "Move to trash" %}</option>
</select>
<button>{% trans "Apply" %}</button>
</form>
<div class="pagination">
{% bootstrap_paginate page_recipe url_view_name="recipes_page" url_extra_kwargs=additionnal_kwargs range=4 %}
</div>
</div>
</section>
{% endblock %}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment