mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-23 07:23:46 +00:00
feat: Deposits app draft
This commit is contained in:
parent
2efe778ed8
commit
824d882b81
18 changed files with 1011 additions and 0 deletions
0
deposits/__init__.py
Normal file
0
deposits/__init__.py
Normal file
41
deposits/admin.py
Normal file
41
deposits/admin.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
# -*- 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.
|
||||
"""
|
||||
Deposit admin model
|
||||
"""
|
||||
|
||||
|
||||
from django.contrib import admin
|
||||
from reversion.admin import VersionAdmin
|
||||
|
||||
from .models import Deposit, DepositItem
|
||||
|
||||
|
||||
class DepositAdmin(VersionAdmin):
|
||||
pass
|
||||
|
||||
|
||||
class DepositItemAdmin(VersionAdmin):
|
||||
pass
|
||||
|
||||
|
||||
admin.site.register(Deposit, DepositAdmin)
|
||||
admin.site.register(DepositItem, DepositItemAdmin)
|
27
deposits/apps.py
Normal file
27
deposits/apps.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
# -*- 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.
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class DepositsConfig(AppConfig):
|
||||
"""Configuration of the optional deposits app."""
|
||||
|
||||
name = "deposits"
|
85
deposits/forms.py
Normal file
85
deposits/forms.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
# -*- 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.
|
||||
"""
|
||||
Deposit form
|
||||
"""
|
||||
|
||||
from django import forms
|
||||
from django.forms import Form, ModelForm
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from re2o.field_permissions import FieldPermissionFormMixin
|
||||
from re2o.mixins import FormRevMixin
|
||||
from re2o.widgets import AutocompleteModelWidget
|
||||
|
||||
from .models import Deposit, DepositItem
|
||||
|
||||
|
||||
class DepositForm(FieldPermissionFormMixin, FormRevMixin, ModelForm):
|
||||
"""
|
||||
Form used to manage and create an invoice and its fields.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, creation=False, **kwargs):
|
||||
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")
|
||||
|
||||
class Meta:
|
||||
model = Deposit
|
||||
fields = ("user", "item", "returned")
|
||||
widgets = {
|
||||
"user": AutocompleteModelWidget(url="/users/user-autocomplete"),
|
||||
}
|
||||
|
||||
|
||||
class DepositItemForm(FormRevMixin, ModelForm):
|
||||
"""
|
||||
Form used to create a deposit item.
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = DepositItem
|
||||
fields = "__all__"
|
||||
|
||||
|
||||
class DelDepositItemForm(FormRevMixin, Form):
|
||||
"""
|
||||
Form used to delete one or more of the currently available deposit items.
|
||||
The user must choose the one to delete by checking the boxes.
|
||||
"""
|
||||
|
||||
deposit_items = forms.ModelMultipleChoiceField(
|
||||
queryset=DepositItem.objects.none(),
|
||||
label=_("Current deposit items"),
|
||||
widget=forms.CheckboxSelectMultiple,
|
||||
)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
instances = kwargs.pop("instances", None)
|
||||
super(DelDepositItemForm, self).__init__(*args, **kwargs)
|
||||
if instances:
|
||||
self.fields["deposit_items"].queryset = instances
|
||||
else:
|
||||
self.fields["deposit_items"].queryset = DepositItem.objects.all()
|
19
deposits/locale/fr/LC_MESSAGES/django.po
Normal file
19
deposits/locale/fr/LC_MESSAGES/django.po
Normal file
|
@ -0,0 +1,19 @@
|
|||
# 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.
|
131
deposits/models.py
Normal file
131
deposits/models.py
Normal file
|
@ -0,0 +1,131 @@
|
|||
# -*- 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 © 2019 Arthur Grisel-Davy
|
||||
# Copyright © 2020 Gabriel Détraz
|
||||
#
|
||||
# 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.
|
||||
"""
|
||||
Deposit model
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from re2o.mixins import AclMixin, RevMixin
|
||||
|
||||
|
||||
class Deposit(RevMixin, AclMixin, models.Model):
|
||||
"""
|
||||
The model for a deposit. It reprensents the fact that a user made a deposit
|
||||
as a guarantee for an item which should be returned to get the deposit
|
||||
back.
|
||||
|
||||
A deposit is linked to :
|
||||
* a user (the one who made the deposit)
|
||||
* 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.
|
||||
"""
|
||||
|
||||
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, verbose_name=_("return date"))
|
||||
|
||||
class Meta:
|
||||
abstract = False
|
||||
verbose_name = _("deposit")
|
||||
verbose_name_plural = _("deposits")
|
||||
|
||||
def __str__(self):
|
||||
if self.returned:
|
||||
return _(
|
||||
"Deposit from {name} for {item} at {date}, returned at {return_date}"
|
||||
).format(
|
||||
name=self.user.get_full_name(),
|
||||
item=self.item,
|
||||
date=self.date,
|
||||
return_date=self.return_date,
|
||||
)
|
||||
else:
|
||||
return _(
|
||||
"Deposit from {name} for {item} at {date}, not yet returned"
|
||||
).format(
|
||||
name=self.user.get_full_name(),
|
||||
item=self.item,
|
||||
date=self.date,
|
||||
)
|
||||
|
||||
def can_view(self, user_request, *_args, **_kwargs):
|
||||
"""Check that the user has the right to view the deposit or that it
|
||||
belongs to them."""
|
||||
if (
|
||||
not user_request.has_perm("deposits.view_deposit")
|
||||
and self.user != user_request
|
||||
):
|
||||
return (
|
||||
False,
|
||||
_("You don't have the right to view other deposits than yours."),
|
||||
("deposits.view_deposit",),
|
||||
)
|
||||
else:
|
||||
return True, None, None
|
||||
|
||||
@staticmethod
|
||||
def can_view_all(user_request, *_args, **_kwargs):
|
||||
"""Check that the user has access to the list of all tickets."""
|
||||
can = user_request.has_perm("deposits.view_deposit")
|
||||
return (
|
||||
can,
|
||||
_("You don't have the right to view the list of deposits.")
|
||||
if not can
|
||||
else None,
|
||||
("deposits.view_deposit",),
|
||||
)
|
||||
|
||||
|
||||
class DepositItem(RevMixin, AclMixin, models.Model):
|
||||
"""An item for a deposit.
|
||||
|
||||
Attributes:
|
||||
name: the name of this deposit item.
|
||||
deposit_amount: the amount needed to be deposited by users.
|
||||
"""
|
||||
|
||||
name = models.CharField(
|
||||
max_length=255,
|
||||
blank=False,
|
||||
null=False,
|
||||
unique=True,
|
||||
verbose_name=_("designation"),
|
||||
)
|
||||
deposit_amount = models.DecimalField(
|
||||
max_digits=5, decimal_places=2, verbose_name=_("deposit amount")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = "deposit item"
|
||||
verbose_name_plural = "deposit items"
|
||||
|
||||
def __str__(self):
|
||||
return _("Deposit item {name}").format(name=self.name)
|
74
deposits/templates/deposits/aff_deposit.html
Normal file
74
deposits/templates/deposits/aff_deposit.html
Normal file
|
@ -0,0 +1,74 @@
|
|||
{% 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 %}
|
48
deposits/templates/deposits/aff_deposit_item.html
Normal file
48
deposits/templates/deposits/aff_deposit_item.html
Normal file
|
@ -0,0 +1,48 @@
|
|||
{% 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 %}
|
||||
{% load design %}
|
||||
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{% trans "Deposit" %}</th>
|
||||
<th>{% trans "Amount" %}</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for item in item_list %}
|
||||
<tr>
|
||||
<td>{{ item.name }}</td>
|
||||
<td>{{ item.deposit_amount }}</td>
|
||||
<td class="text-right">
|
||||
{% can_edit item %}
|
||||
{% include 'buttons/edit.html' with href='deposits:edit-deposit-item' id=item.id %}
|
||||
{% acl_end %}
|
||||
{% history_button item %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
66
deposits/templates/deposits/aff_deposits.html
Normal file
66
deposits/templates/deposits/aff_deposits.html
Normal file
|
@ -0,0 +1,66 @@
|
|||
{% 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 %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="table-responsive">
|
||||
|
||||
<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>
|
||||
</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>{{ deposit.item.name }}</td>
|
||||
<td>{{ deposit.item.deposit_amount }} €</td>
|
||||
<td>{{ deposit.date }}</td>
|
||||
{% if deposit.returned %}
|
||||
<td><i class="fa fa-check" style="color:green"></i></td>
|
||||
{% else %}
|
||||
<td><i class="fa fa-times" style="color:red"></i></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
{% if deposits_list.paginator %}
|
||||
{% include 'pagination.html' with list=deposits_list go_to_id="deposits" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
48
deposits/templates/deposits/aff_profil.html
Normal file
48
deposits/templates/deposits/aff_profil.html
Normal file
|
@ -0,0 +1,48 @@
|
|||
{% 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 %}
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading clearfix profil" data-parent="#accordion" data-toggle="collapse" data-target="#deposits">
|
||||
<h3 class="panel-title pull-left">
|
||||
<i class="fa fa-balance-scale"></i> {% trans "Deposits" %}
|
||||
</h3>
|
||||
</div>
|
||||
<div id="deposits" class="panel-collapse collapse">
|
||||
<div class="panel-body">
|
||||
{% can_create Deposit %}
|
||||
<a class="btn btn-primary btn-sm" role="button" href="{% url 'deposits:new-deposit' %}">
|
||||
<i class="fa fa-balance-scale"></i> {% trans "Add a deposit" %}
|
||||
</a>
|
||||
{% acl_end %}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{% if deposits_list %}
|
||||
{% include 'deposits/aff_deposits.html' with deposits_list=deposits_list %}
|
||||
{% else %}
|
||||
<p>{% trans "No deposit" %}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
39
deposits/templates/deposits/delete.html
Normal file
39
deposits/templates/deposits/delete.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
{% 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 bootstrap3 %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Deletion of subscriptions" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
<h4>
|
||||
{% blocktrans %}Warning: are you sure you really want to delete this {{ objet_name }} object ( {{ objet }} )?{% endblocktrans %}
|
||||
</h4>
|
||||
{% trans "Confirm" as tr_confirm %}
|
||||
{% bootstrap_button tr_confirm button_type='submit' icon='trash' button_class='btn-danger' %}
|
||||
</form>
|
||||
{% endblock %}
|
44
deposits/templates/deposits/deposit.html
Normal file
44
deposits/templates/deposits/deposit.html
Normal file
|
@ -0,0 +1,44 @@
|
|||
{% 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 bootstrap3 %}
|
||||
{% load staticfiles%}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Create or edit deposit" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if title %}
|
||||
<h3>{{ title }}</h3>
|
||||
{% else %}
|
||||
<h3>{% trans "Add" %}</h3>
|
||||
{% endif %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form depositform %}
|
||||
{% bootstrap_button action_name button_type='submit' icon='ok' button_class='btn-success' %}
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
43
deposits/templates/deposits/index_deposit_item.html
Normal file
43
deposits/templates/deposits/index_deposit_item.html
Normal file
|
@ -0,0 +1,43 @@
|
|||
{% 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 bootstrap3 %}
|
||||
{% load acl %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans "Deposit items" %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{% trans "List of deposit items" %}</h2>
|
||||
{% can_create DepositItem %}
|
||||
<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>
|
||||
{% acl_end %}
|
||||
{% include 'deposits/aff_deposit_item.html' with item_list=item_list %}
|
||||
{% endblock %}
|
24
deposits/templates/deposits/navbar.html
Normal file
24
deposits/templates/deposits/navbar.html
Normal file
|
@ -0,0 +1,24 @@
|
|||
{% 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 i18n %}
|
||||
<li><a href="{% url 'deposits:index-deposit-item' %}"><i class="fa fa-balance-scale"></i> {% trans "Deposit items" %}</a></li>
|
28
deposits/templates/deposits/sidebar.html
Normal file
28
deposits/templates/deposits/sidebar.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
{% extends 'base.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 %}
|
||||
|
||||
{% block sidebar %}
|
||||
{% endblock %}
|
3
deposits/tests.py
Normal file
3
deposits/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
49
deposits/urls.py
Normal file
49
deposits/urls.py
Normal file
|
@ -0,0 +1,49 @@
|
|||
# -*- 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 url
|
||||
"""
|
||||
|
||||
from django.urls import path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = "deposits"
|
||||
|
||||
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,
|
||||
name="change-deposit-status",
|
||||
),
|
||||
path("add_deposit_item", views.add_deposit_item, name="add-deposit-item"),
|
||||
path(
|
||||
"edit_deposit_item/<int:itemid>",
|
||||
views.edit_deposit_item,
|
||||
name="edit-deposit-item",
|
||||
),
|
||||
path("del_deposit_item", views.del_deposit_item, name="del-deposit-item"),
|
||||
path("index_deposit_item", views.index_deposit_item, name="index-deposit-item"),
|
||||
]
|
242
deposits/views.py
Normal file
242
deposits/views.py
Normal file
|
@ -0,0 +1,242 @@
|
|||
# -*- 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 views
|
||||
"""
|
||||
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.shortcuts import redirect, render
|
||||
from django.template.loader import render_to_string
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from preferences.models import GeneralOption
|
||||
from re2o.acl import (
|
||||
can_create,
|
||||
can_delete,
|
||||
can_delete_set,
|
||||
can_edit,
|
||||
can_view,
|
||||
can_view_all,
|
||||
)
|
||||
from re2o.base import re2o_paginator
|
||||
from re2o.views import form
|
||||
from users.models import User
|
||||
|
||||
from .forms import DepositForm, DepositItemForm, DelDepositItemForm
|
||||
from .models import Deposit, DepositItem
|
||||
|
||||
|
||||
@login_required
|
||||
@can_create(Deposit)
|
||||
@can_edit(User)
|
||||
def new_deposit(request, user, userid):
|
||||
"""
|
||||
View called to create a new deposit.
|
||||
"""
|
||||
deposit = Deposit(user=user)
|
||||
# Building the invoice form and the article formset
|
||||
deposit_form = DepositForm(
|
||||
request.POST or None, instance=deposit, user=request.user, creation=True
|
||||
)
|
||||
|
||||
if deposit_form.is_valid():
|
||||
deposit_form.save()
|
||||
messages.success(request, _("The deposit was created."))
|
||||
return redirect(reverse("users:profil", kwargs={"userid": deposit.user.pk}))
|
||||
|
||||
return form(
|
||||
{
|
||||
"depositform": deposit_form,
|
||||
"action_name": _("Confirm"),
|
||||
"title": _("New deposit"),
|
||||
},
|
||||
"deposits/deposit.html",
|
||||
request,
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_edit(Deposit)
|
||||
def edit_deposit(request, deposit, **_kwargs):
|
||||
"""
|
||||
View used to edit an existing deposit.
|
||||
"""
|
||||
deposit_form = DepositForm(
|
||||
request.POST or None, instance=deposit, user=request.user
|
||||
)
|
||||
if deposit_form.is_valid():
|
||||
deposit_form.save()
|
||||
messages.success(request, _("The deposit was edited."))
|
||||
return redirect(reverse("users:profil", kwargs={"userid": deposit.user.pk}))
|
||||
|
||||
return form(
|
||||
{
|
||||
"depositform": deposit_form,
|
||||
"action_name": _("Edit"),
|
||||
"title": _("Edit deposit"),
|
||||
},
|
||||
"deposits/deposit.html",
|
||||
request,
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_delete(Deposit)
|
||||
def del_deposit(request, deposit, **_kwargs):
|
||||
"""
|
||||
View used to delete an existing deposit.
|
||||
"""
|
||||
if request.method == "POST":
|
||||
deposit.delete()
|
||||
messages.success(request, _("The deposit was deleted."))
|
||||
return redirect(reverse("users:profil", kwargs={"userid": deposit.user.pk}))
|
||||
return form(
|
||||
{"object": deposit, "objet_name": _("deposit")},
|
||||
"deposits/delete.html",
|
||||
request,
|
||||
)
|
||||
|
||||
|
||||
@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):
|
||||
"""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)})
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_create(DepositItem)
|
||||
def add_deposit_item(request):
|
||||
"""
|
||||
View used to add a deposit item.
|
||||
"""
|
||||
item = DepositItemForm(request.POST or None)
|
||||
if item.is_valid():
|
||||
item.save()
|
||||
messages.success(request, _("The item was created."))
|
||||
return redirect(reverse("deposits:index-deposit-item"))
|
||||
return form(
|
||||
{
|
||||
"depositform": item,
|
||||
"action_name": _("Add"),
|
||||
"title": _("New deposit item"),
|
||||
},
|
||||
"deposits/deposit.html",
|
||||
request,
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_edit(DepositItem)
|
||||
def edit_deposit_item(request, item_instance, **_kwargs):
|
||||
"""
|
||||
View used to edit a deposit item.
|
||||
"""
|
||||
item = DepositItemForm(request.POST or None, instance=item_instance)
|
||||
if item.is_valid():
|
||||
if item.changed_data:
|
||||
item.save()
|
||||
messages.success(request, _("The item was edited."))
|
||||
return redirect(reverse("deposits:index-deposit-item"))
|
||||
return form(
|
||||
{
|
||||
"depositform": item,
|
||||
"action_name": _("Edit"),
|
||||
"title": _("Edit deposit item"),
|
||||
},
|
||||
"deposits/deposit.html",
|
||||
request,
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_delete_set(DepositItem)
|
||||
def del_deposit_item(request, instances):
|
||||
"""
|
||||
View used to delete one of the deposit items.
|
||||
"""
|
||||
item = DelDepositItemForm(request.POST or None, instances=instances)
|
||||
if item.is_valid():
|
||||
item_del = item.cleaned_data["items"]
|
||||
item_del.delete()
|
||||
messages.success(request, _("The items were deleted."))
|
||||
return redirect(reverse("deposits:index-deposit-item"))
|
||||
return form(
|
||||
{
|
||||
"depositform": item,
|
||||
"action_name": _("Delete"),
|
||||
"title": _("Delete deposit item"),
|
||||
},
|
||||
"deposits/deposit.html",
|
||||
request,
|
||||
)
|
||||
|
||||
|
||||
@login_required
|
||||
@can_view_all(DepositItem)
|
||||
def index_deposit_item(request):
|
||||
"""
|
||||
View used to display the list of all available deposit items.
|
||||
"""
|
||||
# TODO : Offer other means of sorting
|
||||
item_list = DepositItem.objects.order_by("name")
|
||||
return render(request, "deposits/index_deposit_item.html", {"item_list": item_list})
|
||||
|
||||
|
||||
# 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")
|
||||
pagination_number = GeneralOption.get_cached_value("pagination_large_number")
|
||||
|
||||
deposits = re2o_paginator(request, deposits_list, pagination_number)
|
||||
context = {
|
||||
"deposits_list": deposits,
|
||||
}
|
||||
return render_to_string(
|
||||
"deposits/aff_profil.html", context=context, request=request, using=None
|
||||
)
|
||||
|
||||
|
||||
def navbar_user():
|
||||
"""View used to display a link to deposit items in the navbar (in the dropdown
|
||||
menu Treasury).
|
||||
"""
|
||||
return ("cotisations", render_to_string("deposits/navbar.html"))
|
Loading…
Reference in a new issue