{{ self | yesno:"Mes banissements,Banissements"}}
++ {% endif %} +
Date de début | +Date de fin | +Raison | +
---|---|---|
{{banishment.ban_date}} | +{{banishment.end_date}} | +{{ banishment.reason }} | +
diff --git a/users/forms.py b/users/forms.py index d8c6755..9f3fda1 100644 --- a/users/forms.py +++ b/users/forms.py @@ -1,7 +1,7 @@ from django import forms from django.contrib.auth.models import User, Group from dal import autocomplete -from .models import School, CotisationHistory, WhiteListHistory +from .models import School, CotisationHistory, WhiteListHistory, BanishmentHistory from preferences.models import PaymentMethod class LoginForm(forms.Form): @@ -114,6 +114,15 @@ class addWhiteListHistoryForm(forms.ModelForm): model = WhiteListHistory 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): """ Form to add and edit a :class:`users.models.School`. diff --git a/users/migrations/0013_banishmenthistory_historicalbanishmenthistory.py b/users/migrations/0013_banishmenthistory_historicalbanishmenthistory.py new file mode 100644 index 0000000..516fcef --- /dev/null +++ b/users/migrations/0013_banishmenthistory_historicalbanishmenthistory.py @@ -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), + ), + ] diff --git a/users/models.py b/users/models.py index 8311602..4cf3c38 100644 --- a/users/models.py +++ b/users/models.py @@ -152,6 +152,9 @@ class Profile(models.Model): """ 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()): return True else: @@ -227,4 +230,34 @@ def str_user(self): return self.username + " (" + self.first_name + " " + self.last_name + ", " + str(self.profile.balance) + "€, " + fin + ")" -User.add_to_class("__str__", str_user) \ No newline at end of file +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() \ No newline at end of file diff --git a/users/templates/users/profile.html b/users/templates/users/profile.html index c7b3de7..0f6786c 100644 --- a/users/templates/users/profile.html +++ b/users/templates/users/profile.html @@ -13,6 +13,7 @@
Date de début | +Date de fin | +Raison | +
---|---|---|
{{banishment.ban_date}} | +{{banishment.end_date}} | +{{ banishment.reason }} | +