mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-27 23:22:25 +00:00
fix: Tweak deposits app
This commit is contained in:
parent
32b126d839
commit
3a5437dd8a
7 changed files with 18 additions and 115 deletions
|
@ -27,7 +27,6 @@ from django.forms import Form, ModelForm
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from re2o.mixins import FormRevMixin
|
from re2o.mixins import FormRevMixin
|
||||||
from re2o.widgets import AutocompleteModelWidget
|
|
||||||
|
|
||||||
from .models import Deposit, DepositItem
|
from .models import Deposit, DepositItem
|
||||||
|
|
||||||
|
@ -38,21 +37,17 @@ class DepositForm(FormRevMixin, ModelForm):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, *args, creation=False, **kwargs):
|
def __init__(self, *args, creation=False, **kwargs):
|
||||||
|
user = kwargs.pop("user")
|
||||||
super(DepositForm, self).__init__(*args, **kwargs)
|
super(DepositForm, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
if not creation:
|
if not creation:
|
||||||
self.fields["user"].label = _("Member")
|
|
||||||
self.fields["user"].empty_label = _("Select the proprietary member")
|
|
||||||
self.fields["returned"].label = _("Deposit returned")
|
self.fields["returned"].label = _("Deposit returned")
|
||||||
else:
|
else:
|
||||||
self.fields = {"item": self.fields["item"]}
|
self.fields = {"item": self.fields["item"]}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Deposit
|
model = Deposit
|
||||||
fields = ("user", "item", "returned")
|
fields = ("item", "returned")
|
||||||
widgets = {
|
|
||||||
"user": AutocompleteModelWidget(url="/users/user-autocomplete"),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class DepositItemForm(FormRevMixin, ModelForm):
|
class DepositItemForm(FormRevMixin, ModelForm):
|
||||||
|
|
|
@ -42,15 +42,13 @@ class Deposit(RevMixin, AclMixin, models.Model):
|
||||||
* an item (borrowed in exchange for the deposit)
|
* an item (borrowed in exchange for the deposit)
|
||||||
Every deposit is dated throught the 'date' value.
|
Every deposit is dated throught the 'date' value.
|
||||||
A deposit has a 'returned' value (default: False) which means that the item
|
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
|
was returned by the user and the deposit was payed back.
|
||||||
'returned_date' attribute stores when the item was returned.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
user = models.ForeignKey("users.User", on_delete=models.PROTECT)
|
user = models.ForeignKey("users.User", on_delete=models.PROTECT)
|
||||||
item = models.ForeignKey("DepositItem", on_delete=models.PROTECT)
|
item = models.ForeignKey("DepositItem", on_delete=models.PROTECT)
|
||||||
date = models.DateTimeField(auto_now_add=True, verbose_name=_("date"))
|
date = models.DateTimeField(auto_now_add=True, verbose_name=_("date"))
|
||||||
returned = models.BooleanField(default=False, verbose_name=_("returned"))
|
returned = models.BooleanField(default=False, verbose_name=_("returned"))
|
||||||
return_date = models.DateTimeField(default=None, null=True, verbose_name=_("return date"))
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = False
|
abstract = False
|
||||||
|
@ -60,12 +58,11 @@ class Deposit(RevMixin, AclMixin, models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.returned:
|
if self.returned:
|
||||||
return _(
|
return _(
|
||||||
"Deposit from {name} for {item} at {date}, returned at {return_date}"
|
"Deposit from {name} for {item} at {date}, returned"
|
||||||
).format(
|
).format(
|
||||||
name=self.user.get_full_name(),
|
name=self.user.get_full_name(),
|
||||||
item=self.item,
|
item=self.item,
|
||||||
date=self.date,
|
date=self.date,
|
||||||
return_date=self.return_date,
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return _(
|
return _(
|
||||||
|
|
|
@ -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 %}
|
|
|
@ -21,7 +21,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
|
|
||||||
{% load bootstrap3 %}
|
{% load bootstrap3 %}
|
||||||
|
{% load acl %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load logs_extra %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
|
@ -30,21 +32,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="col"></th>
|
|
||||||
<th scope="col">{% trans "User" %}</th>
|
<th scope="col">{% trans "User" %}</th>
|
||||||
<th scope="col">{% trans "Item" %}</th>
|
<th scope="col">{% trans "Item" %}</th>
|
||||||
<th scope="col">{% trans "Amount" %}</th>
|
<th scope="col">{% trans "Amount" %}</th>
|
||||||
<th scope="col">{% trans "Date" %}</th>
|
<th scope="col">{% trans "Date" %}</th>
|
||||||
<th scope="col">{% trans "Returned" %}</th>
|
<th scope="col">{% trans "Returned" %}</th>
|
||||||
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for deposit in deposits_list %}
|
{% for deposit in deposits_list %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td><a href="{% url 'users:profil' deposit.user.id %}" role="button">{{ deposit.user.get_short_name }}</a></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>{{ deposit.item.name }}</td>
|
<td>{{ deposit.item.name }}</td>
|
||||||
<td>{{ deposit.item.deposit_amount }} €</td>
|
<td>{{ deposit.item.deposit_amount }} €</td>
|
||||||
<td>{{ deposit.date }}</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>
|
<td><i class="fa fa-check" style="color:green"></i></td>
|
||||||
{% else %}
|
{% else %}
|
||||||
<td><i class="fa fa-times" style="color:red"></i></td>
|
<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>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
|
|
@ -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.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
|
|
||||||
{% load bootstrap3 %}
|
|
||||||
{% load acl %}
|
{% load acl %}
|
||||||
{% load i18n %}
|
{% 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' %}">
|
<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" %}
|
<i class="fa fa-plus"></i> {% trans "Add a deposit item" %}
|
||||||
</a>
|
</a>
|
||||||
{% acl_end %}
|
|
||||||
{% can_delete DepositItem %}
|
|
||||||
<a class="btn btn-danger btn-sm" role="button" href="{% url 'deposits:del-deposit-item' %}">
|
<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" %}
|
<i class="fa fa-trash"></i> {% trans "Delete one or several deposit items" %}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -32,7 +32,6 @@ urlpatterns = [
|
||||||
path("new_deposit/<int:userid>", views.new_deposit, name="new-deposit"),
|
path("new_deposit/<int:userid>", views.new_deposit, name="new-deposit"),
|
||||||
path("edit_deposit/<int:depositid>", views.edit_deposit, name="edit-deposit"),
|
path("edit_deposit/<int:depositid>", views.edit_deposit, name="edit-deposit"),
|
||||||
path("del_deposit/<int:depositid>", views.del_deposit, name="del-deposit"),
|
path("del_deposit/<int:depositid>", views.del_deposit, name="del-deposit"),
|
||||||
path("aff_deposit/<int:depositid>", views.aff_deposit, name="aff-deposit"),
|
|
||||||
path(
|
path(
|
||||||
"change_deposit_status/<int:depositid>",
|
"change_deposit_status/<int:depositid>",
|
||||||
views.change_deposit_status,
|
views.change_deposit_status,
|
||||||
|
|
|
@ -35,7 +35,6 @@ from re2o.acl import (
|
||||||
can_delete,
|
can_delete,
|
||||||
can_delete_set,
|
can_delete_set,
|
||||||
can_edit,
|
can_edit,
|
||||||
can_view,
|
|
||||||
can_view_all,
|
can_view_all,
|
||||||
)
|
)
|
||||||
from re2o.base import re2o_paginator
|
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
|
@login_required
|
||||||
@can_edit(Deposit)
|
@can_edit(Deposit)
|
||||||
def change_deposit_status(request, deposit, depositid):
|
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)
|
item = DelDepositItemForm(request.POST or None, instances=instances)
|
||||||
if item.is_valid():
|
if item.is_valid():
|
||||||
item_del = item.cleaned_data["items"]
|
item_del = item.cleaned_data["deposit_items"]
|
||||||
item_del.delete()
|
item_del.delete()
|
||||||
messages.success(request, _("The items were deleted."))
|
messages.success(request, _("The items were deleted."))
|
||||||
return redirect(reverse("deposits:index-deposit-item"))
|
return redirect(reverse("deposits:index-deposit-item"))
|
||||||
|
@ -228,7 +214,7 @@ def aff_profil(request, user):
|
||||||
|
|
||||||
deposits = re2o_paginator(request, deposits_list, pagination_number)
|
deposits = re2o_paginator(request, deposits_list, pagination_number)
|
||||||
context = {
|
context = {
|
||||||
"user": user,
|
"users": user,
|
||||||
"deposits_list": deposits,
|
"deposits_list": deposits,
|
||||||
}
|
}
|
||||||
return render_to_string(
|
return render_to_string(
|
||||||
|
|
Loading…
Reference in a new issue