From 53a55ee898b935d91b776e271284a5ec636a50f5 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Mon, 18 Jan 2021 18:13:58 +0100 Subject: [PATCH] Display payment status --- apps/registration/apps.py | 10 ++-- .../migrations/0003_auto_20210118_1738.py | 23 +++++++++ apps/registration/models.py | 6 ++- apps/registration/signals.py | 19 +++---- .../templates/registration/user_detail.html | 20 ++++++++ locale/fr/LC_MESSAGES/django.po | 50 +++++++++++++------ 6 files changed, 98 insertions(+), 30 deletions(-) create mode 100644 apps/registration/migrations/0003_auto_20210118_1738.py diff --git a/apps/registration/apps.py b/apps/registration/apps.py index 929e8ff..e846ea5 100644 --- a/apps/registration/apps.py +++ b/apps/registration/apps.py @@ -12,12 +12,12 @@ class RegistrationConfig(AppConfig): name = 'registration' def ready(self): - from registration.signals import create_admin_registration, invite_to_public_rooms, \ + from registration.signals import create_admin_registration, create_payment, \ set_username, send_email_link pre_save.connect(set_username, "auth.User") pre_save.connect(send_email_link, "auth.User") post_save.connect(create_admin_registration, "auth.User") - post_save.connect(invite_to_public_rooms, "registration.Registration") - post_save.connect(invite_to_public_rooms, "registration.StudentRegistration") - post_save.connect(invite_to_public_rooms, "registration.CoachRegistration") - post_save.connect(invite_to_public_rooms, "registration.AdminRegistration") + post_save.connect(create_payment, "registration.Registration") + post_save.connect(create_payment, "registration.StudentRegistration") + post_save.connect(create_payment, "registration.CoachRegistration") + post_save.connect(create_payment, "registration.AdminRegistration") diff --git a/apps/registration/migrations/0003_auto_20210118_1738.py b/apps/registration/migrations/0003_auto_20210118_1738.py new file mode 100644 index 0000000..40d843d --- /dev/null +++ b/apps/registration/migrations/0003_auto_20210118_1738.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.11 on 2021-01-18 16:38 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('registration', '0002_payment'), + ] + + operations = [ + migrations.AlterModelOptions( + name='payment', + options={'verbose_name': 'payment', 'verbose_name_plural': 'payments'}, + ), + migrations.AlterField( + model_name='payment', + name='registration', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='payment', to='registration.ParticipantRegistration', verbose_name='registration'), + ), + ] diff --git a/apps/registration/models.py b/apps/registration/models.py index afa69d7..18dc200 100644 --- a/apps/registration/models.py +++ b/apps/registration/models.py @@ -298,7 +298,7 @@ class Payment(models.Model): registration = models.OneToOneField( ParticipantRegistration, on_delete=models.CASCADE, - related_name="registration", + related_name="payment", verbose_name=_("registration"), ) @@ -337,3 +337,7 @@ class Payment(models.Model): null=True, default=False, ) + + class Meta: + verbose_name = _("payment") + verbose_name_plural = _("payments") diff --git a/apps/registration/signals.py b/apps/registration/signals.py index a0b6a21..15f5367 100644 --- a/apps/registration/signals.py +++ b/apps/registration/signals.py @@ -5,7 +5,7 @@ from django.contrib.auth.models import User from tfjm.lists import get_sympa_client from tfjm.matrix import Matrix -from .models import AdminRegistration, Registration +from .models import AdminRegistration, Payment, Registration def set_username(instance, **_): @@ -44,13 +44,14 @@ def create_admin_registration(instance, **_): AdminRegistration.objects.get_or_create(user=instance) -def invite_to_public_rooms(instance: Registration, created: bool, **_): +def create_payment(instance: Registration, **_): """ - When a user got registered, automatically invite the Matrix user into public rooms. + When a user is saved, create the associated payment. + For a free tournament, the payment is valid. """ - if not created: - Matrix.invite("#annonces:tfjm.org", f"@{instance.matrix_username}:tfjm.org") - Matrix.invite("#faq:tfjm.org", f"@{instance.matrix_username}:tfjm.org") - Matrix.invite("#je-cherche-une-equip:tfjm.org", - f"@{instance.matrix_username}:tfjm.org") - Matrix.invite("#flood:tfjm.org", f"@{instance.matrix_username}:tfjm.org") + if instance.participates: + payment = Payment.objects.get_or_create(registration=instance)[0] + if instance.team and instance.team.participation.valid and instance.team.participation.tournament.price == 0: + payment.valid = True + payment.type = "free" + payment.save() diff --git a/apps/registration/templates/registration/user_detail.html b/apps/registration/templates/registration/user_detail.html index 69131ae..39be1d4 100644 --- a/apps/registration/templates/registration/user_detail.html +++ b/apps/registration/templates/registration/user_detail.html @@ -109,6 +109,26 @@
{% trans "Grant Animath to contact me in the future about other actions:" %}
{{ user_object.registration.give_contact_to_animath|yesno }}
+ + {% if user_object.registration.participates and user_object.registration.team.participation.valid %} +
+ +
+
{% trans "Payment information:" %}
+
+ {% trans "yes,no,pending" as yesnodefault %} + {% with info=user_object.registration.payment.additional_information %} + {% if info %} + + {{ user_object.registration.payment.get_type_display }}, {% trans "valid:" %} {{ user_object.registration.payment.valid|yesno:yesnodefault }} + + {% else %} + {{ user_object.registration.payment.get_type_display }}, {% trans "valid:" %} {{ user_object.registration.payment.valid|yesno:yesnodefault }} + {% endif %} + {% endwith %} +
+
+ {% endif %} {% if user.pk == user_object.pk or user.registration.is_admin %}