mirror of
https://github.com/nanoy42/coope
synced 2024-12-24 16:03:47 +00:00
Add banishment
This commit is contained in:
parent
4060a22c50
commit
ad6b78c8e7
6 changed files with 155 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from dal import autocomplete
|
from dal import autocomplete
|
||||||
from .models import School, CotisationHistory, WhiteListHistory
|
from .models import School, CotisationHistory, WhiteListHistory, BanishmentHistory
|
||||||
from preferences.models import PaymentMethod
|
from preferences.models import PaymentMethod
|
||||||
|
|
||||||
class LoginForm(forms.Form):
|
class LoginForm(forms.Form):
|
||||||
|
@ -114,6 +114,15 @@ class addWhiteListHistoryForm(forms.ModelForm):
|
||||||
model = WhiteListHistory
|
model = WhiteListHistory
|
||||||
fields = ("duration", "reason")
|
fields = ("duration", "reason")
|
||||||
|
|
||||||
|
|
||||||
|
class addBanishmentHistoryForm(forms.ModelForm):
|
||||||
|
"""
|
||||||
|
Form to add a :class:`users.models.BanishmentHistory` to user (:class:`django.contrib.auth.models.User`).
|
||||||
|
"""
|
||||||
|
class Meta:
|
||||||
|
model = BanishmentHistory
|
||||||
|
fields = ("end_date", "reason")
|
||||||
|
|
||||||
class SchoolForm(forms.ModelForm):
|
class SchoolForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
Form to add and edit a :class:`users.models.School`.
|
Form to add and edit a :class:`users.models.School`.
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
# Generated by Django 2.1 on 2019-10-06 09:25
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import simple_history.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('users', '0012_auto_20190925_0125'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='BanishmentHistory',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('ban_date', models.DateTimeField(auto_now_add=True, verbose_name='Date du banissement')),
|
||||||
|
('end_date', models.DateTimeField(verbose_name='Date de fin')),
|
||||||
|
('reason', models.CharField(blank=True, max_length=255, verbose_name='Raison')),
|
||||||
|
('coopeman', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='banishment_made', to=settings.AUTH_USER_MODEL)),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='Client')),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'Historique banissement',
|
||||||
|
'verbose_name_plural': 'Historique banissements',
|
||||||
|
},
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='HistoricalBanishmentHistory',
|
||||||
|
fields=[
|
||||||
|
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
|
||||||
|
('ban_date', models.DateTimeField(blank=True, editable=False, verbose_name='Date du banissement')),
|
||||||
|
('end_date', models.DateTimeField(verbose_name='Date de fin')),
|
||||||
|
('reason', models.CharField(blank=True, max_length=255, verbose_name='Raison')),
|
||||||
|
('history_id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('history_change_reason', models.CharField(max_length=100, null=True)),
|
||||||
|
('history_date', models.DateTimeField()),
|
||||||
|
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
|
||||||
|
('coopeman', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||||
|
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||||
|
('user', models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
options={
|
||||||
|
'verbose_name': 'historical Historique banissement',
|
||||||
|
'ordering': ('-history_date', '-history_id'),
|
||||||
|
'get_latest_by': 'history_date',
|
||||||
|
},
|
||||||
|
bases=(simple_history.models.HistoricalChanges, models.Model),
|
||||||
|
),
|
||||||
|
]
|
|
@ -152,6 +152,9 @@ class Profile(models.Model):
|
||||||
"""
|
"""
|
||||||
Test if a client is adherent.
|
Test if a client is adherent.
|
||||||
"""
|
"""
|
||||||
|
banishments = self.user.banishmenthistory_set.order_by("-end_date")
|
||||||
|
if banishments and banishments[0].end_date > timezone.now():
|
||||||
|
return False
|
||||||
if(self.cotisationEnd and self.cotisationEnd > timezone.now()):
|
if(self.cotisationEnd and self.cotisationEnd > timezone.now()):
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
@ -228,3 +231,33 @@ def str_user(self):
|
||||||
|
|
||||||
|
|
||||||
User.add_to_class("__str__", str_user)
|
User.add_to_class("__str__", str_user)
|
||||||
|
|
||||||
|
class BanishmentHistory(models.Model):
|
||||||
|
"""
|
||||||
|
Stores banishment history.
|
||||||
|
"""
|
||||||
|
class Meta:
|
||||||
|
verbose_name = "Historique banissement"
|
||||||
|
verbose_name_plural = "Historique banissements"
|
||||||
|
|
||||||
|
user = models.ForeignKey(User, on_delete=models.PROTECT, verbose_name="Client")
|
||||||
|
"""
|
||||||
|
Client (:class:`django.contrib.auth.models.User`).
|
||||||
|
"""
|
||||||
|
ban_date = models.DateTimeField(auto_now_add=True, verbose_name="Date du banissement")
|
||||||
|
"""
|
||||||
|
Date of the beginning of the whitelist.
|
||||||
|
"""
|
||||||
|
end_date = models.DateTimeField(verbose_name="Date de fin")
|
||||||
|
"""
|
||||||
|
End date of the whitelist.
|
||||||
|
"""
|
||||||
|
coopeman = models.ForeignKey(User, on_delete=models.PROTECT, related_name="banishment_made")
|
||||||
|
"""
|
||||||
|
User (:class:`django.contrib.auth.models.User`) who registered the cotisation.
|
||||||
|
"""
|
||||||
|
reason = models.CharField(max_length=255, verbose_name="Raison", blank=True)
|
||||||
|
"""
|
||||||
|
Reason of the whitelist
|
||||||
|
"""
|
||||||
|
history = HistoricalRecords()
|
|
@ -13,6 +13,7 @@
|
||||||
</li>
|
</li>
|
||||||
<li><a href="#fourth">{% if self %} Mes cotisations {% else %} Cotisations {% endif %}</a></li>
|
<li><a href="#fourth">{% if self %} Mes cotisations {% else %} Cotisations {% endif %}</a></li>
|
||||||
<li><a href="#fifth">{% if self %} Mes accès gracieux {% else %} Accès gracieux {% endif %}</a></li>
|
<li><a href="#fifth">{% if self %} Mes accès gracieux {% else %} Accès gracieux {% endif %}</a></li>
|
||||||
|
<li><a href="#sixth">{% if self %} Mes banissements {% else %} Banissements {% endif %}</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
@ -278,4 +279,35 @@
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<section id="sixth" class="main">
|
||||||
|
<header class="major">
|
||||||
|
<h2>{{ self | yesno:"Mes banissements,Banissements"}}</h2>
|
||||||
|
</header>
|
||||||
|
<section>
|
||||||
|
{% if perms.users.add_banishmenthistory %}
|
||||||
|
<a class="button" href="{% url 'users:addBanishmentHistory' user.pk %}"><i class="fa fa-hand-paper"></i> Ajouter un banissement</a><br><br>
|
||||||
|
{% endif %}
|
||||||
|
<div class="table-wrapper">
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date de début</th>
|
||||||
|
<th>Date de fin</th>
|
||||||
|
<th>Raison</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for banishment in banishments %}
|
||||||
|
<tr>
|
||||||
|
<td>{{banishment.ban_date}}</td>
|
||||||
|
<td>{{banishment.end_date}}</td>
|
||||||
|
<td>{{ banishment.reason }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</section>
|
||||||
{%endblock%}
|
{%endblock%}
|
|
@ -45,4 +45,5 @@ urlpatterns = [
|
||||||
path('exportCSV', views.export_csv, name="exportCSV"),
|
path('exportCSV', views.export_csv, name="exportCSV"),
|
||||||
path('switchActivateUser/<int:pk>', views.switch_activate_user, name="switchActivateUser"),
|
path('switchActivateUser/<int:pk>', views.switch_activate_user, name="switchActivateUser"),
|
||||||
path('genUserInfos/<int:pk>', views.gen_user_infos, name="genUserInfos"),
|
path('genUserInfos/<int:pk>', views.gen_user_infos, name="genUserInfos"),
|
||||||
|
path('addBanishmentHistory/<int:pk>', views.addBanishmentHistory, name="addBanishmentHistory"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -27,8 +27,8 @@ import os
|
||||||
|
|
||||||
from django_tex.views import render_to_pdf
|
from django_tex.views import render_to_pdf
|
||||||
from coopeV3.acl import admin_required, superuser_required, self_or_has_perm, active_required
|
from coopeV3.acl import admin_required, superuser_required, self_or_has_perm, active_required
|
||||||
from .models import CotisationHistory, WhiteListHistory, School
|
from .models import CotisationHistory, WhiteListHistory, School, BanishmentHistory
|
||||||
from .forms import CreateUserForm, LoginForm, CreateGroupForm, EditGroupForm, SelectUserForm, GroupsEditForm, EditPasswordForm, addCotisationHistoryForm, addCotisationHistoryForm, addWhiteListHistoryForm, SelectNonAdminUserForm, SelectNonSuperUserForm, SchoolForm, ExportForm
|
from .forms import CreateUserForm, LoginForm, CreateGroupForm, EditGroupForm, SelectUserForm, GroupsEditForm, EditPasswordForm, addCotisationHistoryForm, addCotisationHistoryForm, addWhiteListHistoryForm, SelectNonAdminUserForm, SelectNonSuperUserForm, SchoolForm, ExportForm, addBanishmentHistoryForm
|
||||||
from gestion.models import Reload, Consumption, ConsumptionHistory, MenuHistory
|
from gestion.models import Reload, Consumption, ConsumptionHistory, MenuHistory
|
||||||
from preferences.models import GeneralPreferences
|
from preferences.models import GeneralPreferences
|
||||||
|
|
||||||
|
@ -132,6 +132,7 @@ def profile(request, pk):
|
||||||
whitelists = WhiteListHistory.objects.filter(user=user)
|
whitelists = WhiteListHistory.objects.filter(user=user)
|
||||||
reloads = Reload.objects.filter(customer=user).order_by('-date')[:5]
|
reloads = Reload.objects.filter(customer=user).order_by('-date')[:5]
|
||||||
consumptionsChart = Consumption.objects.filter(customer=user)
|
consumptionsChart = Consumption.objects.filter(customer=user)
|
||||||
|
banishments = BanishmentHistory.objects.filter(user=user)
|
||||||
products_pre = []
|
products_pre = []
|
||||||
quantities_pre = []
|
quantities_pre = []
|
||||||
for ch in consumptionsChart:
|
for ch in consumptionsChart:
|
||||||
|
@ -162,6 +163,7 @@ def profile(request, pk):
|
||||||
"quantities": quantities,
|
"quantities": quantities,
|
||||||
"lastConsumptions": lastConsumptions,
|
"lastConsumptions": lastConsumptions,
|
||||||
"lastMenus": lastMenus,
|
"lastMenus": lastMenus,
|
||||||
|
"banishments": banishments
|
||||||
})
|
})
|
||||||
|
|
||||||
@active_required
|
@active_required
|
||||||
|
@ -654,6 +656,26 @@ def addWhiteListHistory(request, pk):
|
||||||
return redirect(reverse('users:profile', kwargs={'pk':user.pk}))
|
return redirect(reverse('users:profile', kwargs={'pk':user.pk}))
|
||||||
return render(request, "form.html", {"form": form, "form_title": "Ajout d'un accès gracieux pour " + user.username, "form_button": "Ajouter", "form_button_icon": "plus-square"})
|
return render(request, "form.html", {"form": form, "form_title": "Ajout d'un accès gracieux pour " + user.username, "form_button": "Ajouter", "form_button_icon": "plus-square"})
|
||||||
|
|
||||||
|
########## Banishment ##########
|
||||||
|
|
||||||
|
@active_required
|
||||||
|
@login_required
|
||||||
|
@permission_required('users.add_banishmenthistory')
|
||||||
|
def addBanishmentHistory(request, pk):
|
||||||
|
"""
|
||||||
|
Displays a :class:`users.forms.addBanishmenthisotryForm` to add a :class:`~users.models.BanishmentHistory` to the requested user (:class:`django.contrib.auth.models.User`).
|
||||||
|
"""
|
||||||
|
user = get_object_or_404(User, pk=pk)
|
||||||
|
form = addBanishmentHistoryForm(request.POST or None)
|
||||||
|
if(form.is_valid()):
|
||||||
|
ban = form.save(commit=False)
|
||||||
|
ban.user = user
|
||||||
|
ban.coopeman = request.user
|
||||||
|
ban.save()
|
||||||
|
messages.success(request, "Le banissement a bien été ajouté")
|
||||||
|
return redirect(reverse('users:profile', kwargs={'pk':user.pk}))
|
||||||
|
return render(request, "form.html", {"form": form, "form_title": "Ajout d'un banissement pour " + user.username, "form_button": "Ajouter", "form_button_icon": "plus-square", "extra_html": "La date doit être au format JJ/MM/AAAA HH:ii"})
|
||||||
|
|
||||||
########## Schools ##########
|
########## Schools ##########
|
||||||
|
|
||||||
@active_required
|
@active_required
|
||||||
|
|
Loading…
Reference in a new issue