8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-24 04:13:12 +00:00

fix: Tweak deposits app

This commit is contained in:
Jean-Romain Garnier 2021-08-06 15:09:01 +02:00
parent 32b126d839
commit 3a5437dd8a
7 changed files with 18 additions and 115 deletions

View file

@ -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):

View file

@ -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 _(

View file

@ -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 %}
<h2>{% blocktrans with id=deposit.id %}Deposit #{{id}}{% endblocktrans %}
{% if deposit.returned %}
<span class="badge badge-success">{% trans "Returned" %}</span>
{% else %}
<span class="badge badge-danger">{% trans "Not returned" %}</span>
{% endif %}
</h2>
<div class="panel panel-default">
<div class="panel-heading">
{% trans "Lent to" %}
<a href="{% url 'users:profil' deposit.user.id%}">
{{ deposit.user.get_full_name }}
</a>
{{ deposit.date | naturalday}}.
<div class="text-right">
{% can_edit deposit %}
<a class="btn btn-info btn-sm" role="button" href="{% url 'deposits:edit-deposit' deposit.id %}"><i class="fa fa-edit"></i> {% trans "Edit" %}</a>
{% if not deposit.returned %}
<a class="btn btn-success btn-sm" role="button" href="{% url 'deposits:change-deposit-status' deposit.id %}"><i class="fa fa-check"></i> {% trans "Mark as returned" %}</a>
{% else %}
<a class="btn btn-warning btn-sm" role="button" href="{% url 'deposits:change-deposit-status' deposit.id %}"><i class="fa fa-close"></i> {% trans "Mark as not returned" %}</a>
{% endif %}
{% acl_end %}
{% history_button deposit text=True %}
</div>
</div>
<div class="panel-body">
<p><b>{% trans "Item:" %}</b> {{deposit.item}}</p>
</div>
</div>
<div class="text-right">
<a class="btn btn-primary" role="button" href="{% url 'deposits:aff-deposits' %}"><i class="fa fa-reorder"></i> {% trans "All deposits" %}</a>
</div>
{% endblock %}

View file

@ -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.,
<table class="table">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">{% trans "User" %}</th>
<th scope="col">{% trans "Item" %}</th>
<th scope="col">{% trans "Amount" %}</th>
<th scope="col">{% trans "Date" %}</th>
<th scope="col">{% trans "Returned" %}</th>
<th scope="col">{% trans "Returned" %}</th>
<th scope="col"></th>
</tr>
{% for deposit in deposits_list %}
<tr>
<td>
<a href="{% url 'deposits:aff-deposit' deposit.id%}" class="btn btn-primary btn-sm" role="button">
<i class="fa fa-balance-scale"></i>
</a>
</td>
<td><a href="{% url 'users:profil' deposit.user.id%}" role="button">{{ deposit.user.get_short_name }}</a></td>
<td><a href="{% url 'users:profil' deposit.user.id %}" role="button">{{ deposit.user.get_short_name }}</a></td>
<td>{{ deposit.item.name }}</td>
<td>{{ deposit.item.deposit_amount }} €</td>
<td>{{ deposit.date }}</td>
@ -52,7 +49,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td><i class="fa fa-check" style="color:green"></i></td>
{% else %}
<td><i class="fa fa-times" style="color:red"></i></td>
{% endif %}
{% endif %}
<td class="text-right">
{% can_edit deposit %}
{% include 'buttons/edit.html' with href='deposits:edit-deposit' id=deposit.id %}
{% acl_end %}
{% history_button deposit %}
</td>
</tr>
{% endfor %}

View file

@ -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.,
<a class="btn btn-primary btn-sm" role="button" href="{% url 'deposits:add-deposit-item' %}">
<i class="fa fa-plus"></i> {% trans "Add a deposit item" %}
</a>
{% acl_end %}
{% can_delete DepositItem %}
<a class="btn btn-danger btn-sm" role="button" href="{% url 'deposits:del-deposit-item' %}">
<i class="fa fa-trash"></i> {% trans "Delete one or several deposit items" %}
</a>

View file

@ -32,7 +32,6 @@ urlpatterns = [
path("new_deposit/<int:userid>", views.new_deposit, name="new-deposit"),
path("edit_deposit/<int:depositid>", views.edit_deposit, name="edit-deposit"),
path("del_deposit/<int:depositid>", views.del_deposit, name="del-deposit"),
path("aff_deposit/<int:depositid>", views.aff_deposit, name="aff-deposit"),
path(
"change_deposit_status/<int:depositid>",
views.change_deposit_status,

View file

@ -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(