diff --git a/deposits/locale/fr/LC_MESSAGES/django.po b/deposits/locale/fr/LC_MESSAGES/django.po index a2026fb6..2f04c31f 100644 --- a/deposits/locale/fr/LC_MESSAGES/django.po +++ b/deposits/locale/fr/LC_MESSAGES/django.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2021-08-07 13:20+0200\n" +"POT-Creation-Date: 2021-08-07 18:27+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -31,11 +31,19 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" -#: deposits/forms.py:51 +#: deposits/forms.py:44 deposits/templates/deposits/aff_deposit_item.html:31 +msgid "Deposit item" +msgstr "Article" + +#: deposits/forms.py:45 deposits/templates/deposits/aff_deposits.html:48 +msgid "Payment method" +msgstr "Moyen de paiement" + +#: deposits/forms.py:46 msgid "Deposit returned" msgstr "Caution rendue" -#: deposits/forms.py:76 +#: deposits/forms.py:79 msgid "Current deposit items" msgstr "Articles sous cautions actuels" @@ -51,7 +59,7 @@ msgstr "rendu" msgid "deposit amount" msgstr "montant de la caution" -#: deposits/models.py:60 deposits/views.py:113 +#: deposits/models.py:60 deposits/views.py:114 msgid "deposit" msgstr "caution" @@ -89,36 +97,29 @@ msgstr "article" msgid "deposit items" msgstr "articles" -#: deposits/templates/deposits/aff_deposit_item.html:31 -msgid "Deposit item" -msgstr "Article" - #: deposits/templates/deposits/aff_deposit_item.html:32 -#: deposits/templates/deposits/aff_deposits.html:37 +#: deposits/templates/deposits/aff_deposits.html:44 msgid "Amount" msgstr "Montant" -#: deposits/templates/deposits/aff_deposits.html:35 +#: deposits/templates/deposits/aff_deposits.html:36 msgid "User" msgstr "Utilisateur" -#: deposits/templates/deposits/aff_deposits.html:36 +#: deposits/templates/deposits/aff_deposits.html:40 msgid "Item" msgstr "Article" -#: deposits/templates/deposits/aff_deposits.html:38 -msgid "Payment method" -msgstr "Moyen de paiement" - -#: deposits/templates/deposits/aff_deposits.html:39 +#: deposits/templates/deposits/aff_deposits.html:52 msgid "Date" msgstr "Date" -#: deposits/templates/deposits/aff_deposits.html:40 +#: deposits/templates/deposits/aff_deposits.html:56 msgid "Returned" msgstr "Rendu" #: deposits/templates/deposits/aff_profil.html:29 +#: deposits/templates/deposits/navbar.html:25 msgid "Deposits" msgstr "Cautions" @@ -143,7 +144,7 @@ msgstr "" "Attention: voulez-vous vraiment supprimer cet objet %(objet_name)s " "( %(objet)s ) ?" -#: deposits/templates/deposits/delete.html:36 deposits/views.py:69 +#: deposits/templates/deposits/delete.html:36 deposits/views.py:70 msgid "Confirm" msgstr "Confirmer" @@ -151,12 +152,12 @@ msgstr "Confirmer" msgid "Create or edit deposit" msgstr "Créer ou modifier les cautions" -#: deposits/templates/deposits/deposit.html:35 deposits/views.py:144 +#: deposits/templates/deposits/deposit.html:35 deposits/views.py:173 msgid "Add" msgstr "Ajouter" #: deposits/templates/deposits/index_deposit_item.html:27 -#: deposits/templates/deposits/navbar.html:24 +#: deposits/templates/deposits/navbar.html:33 msgid "Deposit items" msgstr "Articles sous caution" @@ -172,54 +173,82 @@ msgstr "Ajouter un article" msgid "Delete one or several deposit items" msgstr "Supprimer ou un plusieurs articles" -#: deposits/views.py:63 +#: deposits/templates/deposits/index_deposits.html:29 +msgid "List of deposits" +msgstr "Liste de cautions" + +#: deposits/templates/deposits/index_deposits.html:35 +msgid "Deposit" +msgid_plural "Deposits" +msgstr[0] "Caution" +msgstr[1] "Cautions" + +#: deposits/templates/deposits/index_deposits.html:38 +msgid "Unreturned deposit" +msgid_plural "Unreturned deposits" +msgstr[0] "Caution non rendue" +msgstr[1] "Cautions non rendues" + +#: deposits/templates/deposits/index_deposits.html:46 +msgid "Unreturned deposits" +msgstr "Cautions non rendues" + +#: deposits/templates/deposits/index_deposits.html:57 +msgid "Returned deposits" +msgstr "Cautions rendues" + +#: deposits/templates/deposits/navbar.html:30 +msgid "View deposits" +msgstr "Gérer les cautions" + +#: deposits/views.py:64 msgid "The deposit was created." msgstr "La caution a été crée." -#: deposits/views.py:70 +#: deposits/views.py:71 msgid "New deposit" msgstr "Nouvelle caution" -#: deposits/views.py:88 +#: deposits/views.py:89 msgid "The deposit was edited." msgstr "La caution a été modifiée." -#: deposits/views.py:94 deposits/views.py:167 +#: deposits/views.py:95 deposits/views.py:196 msgid "Edit" msgstr "Modifier" -#: deposits/views.py:95 +#: deposits/views.py:96 msgid "Edit deposit" msgstr "Modifier la caution" -#: deposits/views.py:110 +#: deposits/views.py:111 msgid "The deposit was deleted." msgstr "La caution a été supprimée." -#: deposits/views.py:139 +#: deposits/views.py:168 msgid "The item was created." msgstr "L'article a été créé." -#: deposits/views.py:145 +#: deposits/views.py:174 msgid "New deposit item" msgstr "Nouvel article" -#: deposits/views.py:162 +#: deposits/views.py:191 msgid "The item was edited." msgstr "L'article a été modifié." -#: deposits/views.py:168 +#: deposits/views.py:197 msgid "Edit deposit item" msgstr "Modifier l'article" -#: deposits/views.py:185 +#: deposits/views.py:214 msgid "The items were deleted." msgstr "Les articles ont été supprimés." -#: deposits/views.py:190 +#: deposits/views.py:219 msgid "Delete" msgstr "Supprimer" -#: deposits/views.py:191 +#: deposits/views.py:220 msgid "Delete deposit item" msgstr "Supprimer l'article" diff --git a/deposits/templates/deposits/aff_deposits.html b/deposits/templates/deposits/aff_deposits.html index 8b70ecee..1b32ebd4 100644 --- a/deposits/templates/deposits/aff_deposits.html +++ b/deposits/templates/deposits/aff_deposits.html @@ -32,13 +32,31 @@ with this program; if not, write to the Free Software Foundation, Inc., - - - - - - - + + + + + + + {% for deposit in deposits_list %} @@ -64,7 +82,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% trans "User" %}{% trans "Item" %}{% trans "Amount" %}{% trans "Payment method" %}{% trans "Date" %}{% trans "Returned" %} + {% trans "User" as tr_user %} + {% include 'buttons/sort.html' with prefix='deposit' col="user" text=tr_user %} + + {% trans "Item" as tr_item %} + {% include 'buttons/sort.html' with prefix='deposit' col="item" text=tr_item %} + + {% trans "Amount" as tr_amount %} + {% include 'buttons/sort.html' with prefix='deposit' col="amount" text=tr_amount %} + + {% trans "Payment method" as tr_payment %} + {% include 'buttons/sort.html' with prefix='deposit' col="payment" text=tr_payment %} + + {% trans "Date" as tr_date %} + {% include 'buttons/sort.html' with prefix='deposit' col="date" text=tr_date %} + + {% trans "Returned" as tr_returned %} + {% include 'buttons/sort.html' with prefix='deposit' col="returned" text=tr_returned %} +
- {% if deposits_list.paginator %} + {% if deposits_list.paginator and show_pagination is not False %} {% include 'pagination.html' with list=deposits_list go_to_id="deposits" %} {% endif %} diff --git a/deposits/templates/deposits/index_deposits.html b/deposits/templates/deposits/index_deposits.html new file mode 100644 index 00000000..5c6525a5 --- /dev/null +++ b/deposits/templates/deposits/index_deposits.html @@ -0,0 +1,64 @@ +{% extends 'deposits/sidebar.html' %} +{% comment %} +Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +se veut agnostique au réseau considéré, de manière à être installable en +quelques clics. + +Copyright © 2021 Jean-Romain Garnier + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +{% endcomment %} + +{% load acl %} +{% load i18n %} +{% load logs_extra %} + +{% block content %} +

{% trans "List of deposits" %}

+ +
+
+
+
+  {{ nbr_deposits }} {% blocktrans count nb=nbr_deposits %}Deposit{% plural %}Deposits{% endblocktrans %} +
+
+  {{ nbr_deposits_lent }} {% blocktrans count nb=nbr_deposits_lent %}Unreturned deposit{% plural %}Unreturned deposits{% endblocktrans %} +
+
+
+
+ +
+

{% trans "Unreturned deposits" %}

+ {% include 'deposits/aff_deposits.html' with deposits_list=lent_deposits_list show_pagination=False %} + + {% if lent_deposits_list.paginator %} + {% include 'pagination.html' with list=lent_deposits_list page_arg='lpage' go_to_id='unreturned_deposits' %} + {% endif %} +
+ +
+ +
+

{% trans "Returned deposits" %}

+ {% include 'deposits/aff_deposits.html' with deposits_list=returned_deposits_list show_pagination=False %} + + {% if returned_deposits_list.paginator %} + {% include 'pagination.html' with list=returned_deposits_list page_arg='rpage' go_to_id='returned_deposits' %} + {% endif %} +
+ +{% endblock %} diff --git a/deposits/templates/deposits/navbar.html b/deposits/templates/deposits/navbar.html index 378ee066..d704237b 100644 --- a/deposits/templates/deposits/navbar.html +++ b/deposits/templates/deposits/navbar.html @@ -21,4 +21,15 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endcomment %} {% load i18n %} -
  • {% trans "Deposit items" %}
  • +
  • + {% trans "Deposits" %} + » + +
  • diff --git a/deposits/urls.py b/deposits/urls.py index e9434298..c56099d6 100644 --- a/deposits/urls.py +++ b/deposits/urls.py @@ -32,11 +32,7 @@ urlpatterns = [ path("new_deposit/", views.new_deposit, name="new-deposit"), path("edit_deposit/", views.edit_deposit, name="edit-deposit"), path("del_deposit/", views.del_deposit, name="del-deposit"), - path( - "change_deposit_status/", - views.change_deposit_status, - name="change-deposit-status", - ), + path("index_deposits", views.index_deposits, name="index-deposits"), path("add_deposit_item", views.add_deposit_item, name="add-deposit-item"), path( "edit_deposit_item/", diff --git a/deposits/utils.py b/deposits/utils.py new file mode 100644 index 00000000..e6c732b6 --- /dev/null +++ b/deposits/utils.py @@ -0,0 +1,38 @@ +# -*- mode: python; coding: utf-8 -*- +# Re2o est un logiciel d'administration développé initiallement au Rézo Metz. Il +# se veut agnostique au réseau considéré, de manière à être installable en +# quelques clics. +# +# Copyright © 2021 Jean-Romain Garnier +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +""" +Deposits utils +""" +from re2o.base import SortTable + + +class DepositSortTable(SortTable): + """Extension of the SortTable class to handle the deposit optional app""" + + DEPOSIT_INDEX = { + "deposit_user": ["user__pseudo"], + "deposit_item": ["item__name"], + "deposit_payment": ["payment_method__moyen"], + "deposit_date": ["date"], + "deposit_returned": ["returned"], + "deposit_amount": ["deposit_amount"], + "default": ["-date"], + } diff --git a/deposits/views.py b/deposits/views.py index 8cc9b8c4..86aab85c 100644 --- a/deposits/views.py +++ b/deposits/views.py @@ -43,6 +43,7 @@ from users.models import User from .forms import DepositForm, DepositItemForm, DelDepositItemForm from .models import Deposit, DepositItem +from .utils import DepositSortTable @login_required @@ -117,13 +118,45 @@ def del_deposit(request, deposit, **_kwargs): @login_required -@can_edit(Deposit) -def change_deposit_status(request, deposit, depositid): - """View used to change a ticket's status.""" - deposit.returned = not deposit.solved - deposit.save() - return redirect( - reverse("deposits:aff-deposit", kwargs={"depositid": str(depositid)}) +@can_view_all(Deposit) +def index_deposits(request): + """ + View used to display the list of all deposits. + """ + pagination_number = GeneralOption.get_cached_value("pagination_number") + + # Get the list of all deposits, sorted according to the user's request + deposits_list = Deposit.objects.select_related("user", "item", "payment_method") + deposits_list = DepositSortTable.sort( + deposits_list, + request.GET.get("col"), + request.GET.get("order"), + DepositSortTable.DEPOSIT_INDEX, + ) + nbr_deposits = deposits_list.count() + + # Split it into 2: the list of those which have not yet been returned... + lent_deposits_list = deposits_list.filter(returned=False) + nbr_deposits_lent = lent_deposits_list.count() + lent_deposits_list = re2o_paginator( + request, lent_deposits_list, pagination_number, page_arg="lpage" + ) + + # ... and the list of those that have already been returned + returned_deposits_list = deposits_list.filter(returned=True) + returned_deposits_list = re2o_paginator( + request, returned_deposits_list, pagination_number, page_arg="rpage" + ) + + return render( + request, + "deposits/index_deposits.html", + { + "lent_deposits_list": lent_deposits_list, + "returned_deposits_list": returned_deposits_list, + "nbr_deposits": nbr_deposits, + "nbr_deposits_lent": nbr_deposits_lent, + }, ) @@ -209,7 +242,15 @@ def index_deposit_item(request): # Canonic views for optional apps def aff_profil(request, user): """View used to display the deposits on a user's profile.""" - deposits_list = Deposit.objects.filter(user=user).all().order_by("-date") + deposits_list = Deposit.objects.filter(user=user).select_related( + "user", "item", "payment_method" + ) + deposits_list = DepositSortTable.sort( + deposits_list, + request.GET.get("col"), + request.GET.get("order"), + DepositSortTable.DEPOSIT_INDEX, + ) pagination_number = GeneralOption.get_cached_value("pagination_large_number") deposits = re2o_paginator(request, deposits_list, pagination_number)