diff --git a/deposits/forms.py b/deposits/forms.py index 12627278..d21c697e 100644 --- a/deposits/forms.py +++ b/deposits/forms.py @@ -27,7 +27,6 @@ from django.forms import Form, ModelForm from django.utils.translation import ugettext_lazy as _ from re2o.mixins import FormRevMixin -from re2o.widgets import AutocompleteModelWidget from .models import Deposit, DepositItem @@ -38,21 +37,17 @@ class DepositForm(FormRevMixin, ModelForm): """ def __init__(self, *args, creation=False, **kwargs): + user = kwargs.pop("user") super(DepositForm, self).__init__(*args, **kwargs) if not creation: - self.fields["user"].label = _("Member") - self.fields["user"].empty_label = _("Select the proprietary member") self.fields["returned"].label = _("Deposit returned") else: self.fields = {"item": self.fields["item"]} class Meta: model = Deposit - fields = ("user", "item", "returned") - widgets = { - "user": AutocompleteModelWidget(url="/users/user-autocomplete"), - } + fields = ("item", "returned") class DepositItemForm(FormRevMixin, ModelForm): diff --git a/deposits/models.py b/deposits/models.py index 7de37e67..d41fcfc3 100644 --- a/deposits/models.py +++ b/deposits/models.py @@ -42,15 +42,13 @@ class Deposit(RevMixin, AclMixin, models.Model): * an item (borrowed in exchange for the deposit) Every deposit is dated throught the 'date' value. A deposit has a 'returned' value (default: False) which means that the item - was returned by the user and the deposit was payed back. The - 'returned_date' attribute stores when the item was returned. + was returned by the user and the deposit was payed back. """ user = models.ForeignKey("users.User", on_delete=models.PROTECT) item = models.ForeignKey("DepositItem", on_delete=models.PROTECT) date = models.DateTimeField(auto_now_add=True, verbose_name=_("date")) returned = models.BooleanField(default=False, verbose_name=_("returned")) - return_date = models.DateTimeField(default=None, null=True, verbose_name=_("return date")) class Meta: abstract = False @@ -60,12 +58,11 @@ class Deposit(RevMixin, AclMixin, models.Model): def __str__(self): if self.returned: return _( - "Deposit from {name} for {item} at {date}, returned at {return_date}" + "Deposit from {name} for {item} at {date}, returned" ).format( name=self.user.get_full_name(), item=self.item, date=self.date, - return_date=self.return_date, ) else: return _( diff --git a/deposits/templates/deposits/aff_deposit.html b/deposits/templates/deposits/aff_deposit.html deleted file mode 100644 index f9284d7b..00000000 --- a/deposits/templates/deposits/aff_deposit.html +++ /dev/null @@ -1,74 +0,0 @@ -{% extends 'users/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 bootstrap3 %} -{% load i18n %} -{% load humanize %} -{% load logs_extra %} -{% load acl %} - -{% block title %}{% trans "Deposits" %}{% endblock %} - -{% block content %} - -

{% blocktrans with id=deposit.id %}Deposit #{{id}}{% endblocktrans %} -{% if deposit.returned %} -{% trans "Returned" %} -{% else %} -{% trans "Not returned" %} -{% endif %} -

- -
-
- {% trans "Lent to" %} - - {{ deposit.user.get_full_name }} - - {{ deposit.date | naturalday}}. - -
- {% can_edit deposit %} - {% trans "Edit" %} - {% if not deposit.returned %} - {% trans "Mark as returned" %} - {% else %} - {% trans "Mark as not returned" %} - {% endif %} - {% acl_end %} - {% history_button deposit text=True %} -
-
-
- -

{% trans "Item:" %} {{deposit.item}}

- -
- -
- -
- {% trans "All deposits" %} -
- -{% endblock %} diff --git a/deposits/templates/deposits/aff_deposits.html b/deposits/templates/deposits/aff_deposits.html index f5eeff6a..f496083a 100644 --- a/deposits/templates/deposits/aff_deposits.html +++ b/deposits/templates/deposits/aff_deposits.html @@ -21,7 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc., {% endcomment %} {% load bootstrap3 %} +{% load acl %} {% load i18n %} +{% load logs_extra %} {% block content %} @@ -30,21 +32,16 @@ with this program; if not, write to the Free Software Foundation, Inc., - - + + {% for deposit in deposits_list %} - - + @@ -52,7 +49,13 @@ with this program; if not, write to the Free Software Foundation, Inc., {% else %} - {% endif %} + {% endif %} + {% endfor %} diff --git a/deposits/templates/deposits/index_deposit_item.html b/deposits/templates/deposits/index_deposit_item.html index 0bfe5bc0..6dc391da 100644 --- a/deposits/templates/deposits/index_deposit_item.html +++ b/deposits/templates/deposits/index_deposit_item.html @@ -21,7 +21,6 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. {% endcomment %} -{% load bootstrap3 %} {% load acl %} {% load i18n %} @@ -33,8 +32,6 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Add a deposit item" %} - {% acl_end %} - {% can_delete DepositItem %} {% trans "Delete one or several deposit items" %} diff --git a/deposits/urls.py b/deposits/urls.py index 51ef34e0..e9434298 100644 --- a/deposits/urls.py +++ b/deposits/urls.py @@ -32,7 +32,6 @@ 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("aff_deposit/", views.aff_deposit, name="aff-deposit"), path( "change_deposit_status/", views.change_deposit_status, diff --git a/deposits/views.py b/deposits/views.py index 9cca8a75..8cc9b8c4 100644 --- a/deposits/views.py +++ b/deposits/views.py @@ -35,7 +35,6 @@ from re2o.acl import ( can_delete, can_delete_set, can_edit, - can_view, can_view_all, ) from re2o.base import re2o_paginator @@ -117,19 +116,6 @@ def del_deposit(request, deposit, **_kwargs): ) -@login_required -@can_view(Deposit) -def aff_deposit(request, deposit, **_kwargs): - """ - View used to view an existing deposit. - """ - return render( - request, - "deposits/aff_deposit.html", - {"deposit": deposit}, - ) - - @login_required @can_edit(Deposit) def change_deposit_status(request, deposit, depositid): @@ -194,7 +180,7 @@ def del_deposit_item(request, instances): """ item = DelDepositItemForm(request.POST or None, instances=instances) if item.is_valid(): - item_del = item.cleaned_data["items"] + item_del = item.cleaned_data["deposit_items"] item_del.delete() messages.success(request, _("The items were deleted.")) return redirect(reverse("deposits:index-deposit-item")) @@ -228,7 +214,7 @@ def aff_profil(request, user): deposits = re2o_paginator(request, deposits_list, pagination_number) context = { - "user": user, + "users": user, "deposits_list": deposits, } return render_to_string(
{% trans "User" %} {% trans "Item" %} {% trans "Amount" %} {% trans "Date" %}{% trans "Returned" %}{% trans "Returned" %}
- - - - {{ deposit.user.get_short_name }}{{ deposit.user.get_short_name }} {{ deposit.item.name }} {{ deposit.item.deposit_amount }} € {{ deposit.date }} + {% can_edit deposit %} + {% include 'buttons/edit.html' with href='deposits:edit-deposit' id=deposit.id %} + {% acl_end %} + {% history_button deposit %} +