Make Sympa + payment support optional

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-06-07 16:35:08 +02:00
parent 2a775cedc1
commit c12972b718
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
10 changed files with 56 additions and 25 deletions

View File

@ -128,10 +128,12 @@ class ValidateParticipationForm(forms.Form):
class TournamentForm(forms.ModelForm): class TournamentForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if settings.TFJM_APP != "ETEAM": if settings.NB_ROUNDS < 3:
del self.fields['date_third_phase'] del self.fields['date_third_phase']
del self.fields['solutions_available_third_phase'] del self.fields['solutions_available_third_phase']
del self.fields['syntheses_third_phase_limit'] del self.fields['syntheses_third_phase_limit']
if not settings.PAYMENT_MANAGEMENT:
del self.fields['price']
class Meta: class Meta:
model = Tournament model = Tournament

View File

@ -1,6 +1,6 @@
# Copyright (C) 2020 by Animath # Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django.conf import settings
from django.core.management import BaseCommand from django.core.management import BaseCommand
from django.db.models import Q from django.db.models import Q
from participation.models import Team, Tournament from participation.models import Team, Tournament
@ -13,6 +13,9 @@ class Command(BaseCommand):
""" """
Create Sympa mailing lists and register teams. Create Sympa mailing lists and register teams.
""" """
if not settings.ML_MANAGEMENT:
return
sympa = get_sympa_client() sympa = get_sympa_client()
sympa.create_list("equipes", "Equipes du TFJM2", "hotline", sympa.create_list("equipes", "Equipes du TFJM2", "hotline",

View File

@ -239,7 +239,8 @@ class Team(models.Model):
if not self.access_code: if not self.access_code:
# if the team got created, generate the access code, create the contact mailing list # if the team got created, generate the access code, create the contact mailing list
self.access_code = get_random_string(6) self.access_code = get_random_string(6)
self.create_mailing_list() if settings.ML_MANAGEMENT:
self.create_mailing_list()
return super().save(*args, **kwargs) return super().save(*args, **kwargs)

View File

@ -1,7 +1,9 @@
# Copyright (C) 2020 by Animath # Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from typing import Union from typing import Union
from django.conf import settings
from participation.models import Note, Participation, Passage, Pool, Team, Tournament from participation.models import Note, Participation, Passage, Pool, Team, Tournament
from registration.models import Payment from registration.models import Payment
from tfjm.lists import get_sympa_client from tfjm.lists import get_sympa_client
@ -22,7 +24,7 @@ def update_mailing_list(instance: Team, raw, **_):
""" """
When a team name or trigram got updated, update mailing lists When a team name or trigram got updated, update mailing lists
""" """
if instance.pk and not raw: if instance.pk and not raw and settings.ML_MANAGEMENT:
old_team = Team.objects.get(pk=instance.pk) old_team = Team.objects.get(pk=instance.pk)
if old_team.trigram != instance.trigram: if old_team.trigram != instance.trigram:
# Delete old mailing list, create a new one # Delete old mailing list, create a new one
@ -41,7 +43,7 @@ def create_payments(instance: Participation, created, raw, **_):
""" """
When a participation got created, create an associated payment. When a participation got created, create an associated payment.
""" """
if instance.valid and not raw: if instance.valid and not raw and settings.PAYMENT_MANAGEMENT:
for student in instance.team.students.all(): for student in instance.team.students.all():
payment_qs = Payment.objects.filter(registrations=student, final=False) payment_qs = Payment.objects.filter(registrations=student, final=False)
if payment_qs.exists(): if payment_qs.exists():

View File

@ -18,8 +18,10 @@
<dt class="col-sm-6 text-sm-end">{% trans 'place'|capfirst %}</dt> <dt class="col-sm-6 text-sm-end">{% trans 'place'|capfirst %}</dt>
<dd class="col-sm-6">{{ tournament.place }}</dd> <dd class="col-sm-6">{{ tournament.place }}</dd>
<dt class="col-sm-6 text-sm-end">{% trans 'price'|capfirst %}</dt> {% if TFJM.PAYMENT_MANAGEMENT %}
<dd class="col-sm-6">{% if tournament.price %}{{ tournament.price }} €{% else %}{% trans "Free" %}{% endif %}</dd> <dt class="col-sm-6 text-sm-end">{% trans 'price'|capfirst %}</dt>
<dd class="col-sm-6">{% if tournament.price %}{{ tournament.price }} €{% else %}{% trans "Free" %}{% endif %}</dd>
{% endif %}
<dt class="col-sm-6 text-sm-end">{% trans 'remote'|capfirst %}</dt> <dt class="col-sm-6 text-sm-end">{% trans 'remote'|capfirst %}</dt>
<dd class="col-sm-6">{{ tournament.remote|yesno }}</dd> <dd class="col-sm-6">{{ tournament.remote|yesno }}</dd>
@ -42,7 +44,7 @@
<dt class="col-sm-6 text-sm-end">{% trans 'date of maximal syntheses submission for the second round'|capfirst %}</dt> <dt class="col-sm-6 text-sm-end">{% trans 'date of maximal syntheses submission for the second round'|capfirst %}</dt>
<dd class="col-sm-6">{{ tournament.syntheses_second_phase_limit }}</dd> <dd class="col-sm-6">{{ tournament.syntheses_second_phase_limit }}</dd>
{% if TFJM_APP == "ETEAM" %} {% if TFJM.APP == "ETEAM" %}
<dt class="col-sm-6 text-sm-end">{% trans 'date of maximal syntheses submission for the third round'|capfirst %}</dt> <dt class="col-sm-6 text-sm-end">{% trans 'date of maximal syntheses submission for the third round'|capfirst %}</dt>
<dd class="col-sm-6">{{ tournament.syntheses_third_phase_limit }}</dd> <dd class="col-sm-6">{{ tournament.syntheses_third_phase_limit }}</dd>
{% endif %} {% endif %}
@ -50,14 +52,16 @@
<dt class="col-sm-6 text-sm-end">{% trans 'description'|capfirst %}</dt> <dt class="col-sm-6 text-sm-end">{% trans 'description'|capfirst %}</dt>
<dd class="col-sm-6">{{ tournament.description }}</dd> <dd class="col-sm-6">{{ tournament.description }}</dd>
<dt class="col-sm-6 text-sm-end">{% trans 'To contact organizers' %}</dt> {% if TFJM.ML_MANAGEMENT %}
<dd class="col-sm-6"><a href="mailto:{{ tournament.organizers_email }}">{{ tournament.organizers_email }}</a></dd> <dt class="col-sm-6 text-sm-end">{% trans 'To contact organizers' %}</dt>
<dd class="col-sm-6"><a href="mailto:{{ tournament.organizers_email }}">{{ tournament.organizers_email }}</a></dd>
<dt class="col-sm-6 text-sm-end">{% trans 'To contact juries' %}</dt> <dt class="col-sm-6 text-sm-end">{% trans 'To contact juries' %}</dt>
<dd class="col-sm-6"><a href="mailto:{{ tournament.jurys_email }}">{{ tournament.jurys_email }}</a></dd> <dd class="col-sm-6"><a href="mailto:{{ tournament.jurys_email }}">{{ tournament.jurys_email }}</a></dd>
<dt class="col-sm-6 text-sm-end">{% trans 'To contact valid teams' %}</dt> <dt class="col-sm-6 text-sm-end">{% trans 'To contact valid teams' %}</dt>
<dd class="col-sm-6"><a href="mailto:{{ tournament.teams_email }}">{{ tournament.teams_email }}</a></dd> <dd class="col-sm-6"><a href="mailto:{{ tournament.teams_email }}">{{ tournament.teams_email }}</a></dd>
{% endif %}
</dl> </dl>
</div> </div>
@ -77,13 +81,15 @@
<div id="teams_table"> <div id="teams_table">
{% render_table teams %} {% render_table teams %}
</div> </div>
{% if user.registration.is_admin or user.registration in tournament.organizers.all %} {% if TFJM.PAYMENT_MANAGEMENT %}
<div class="text-center"> {% if user.registration.is_admin or user.registration in tournament.organizers.all %}
<a href="{% url "participation:tournament_payments" pk=tournament.pk %}" class="btn btn-secondary"> <div class="text-center">
<i class="fas fa-money-bill-wave"></i> {% trans "Access to payments list" %} <a href="{% url "participation:tournament_payments" pk=tournament.pk %}" class="btn btn-secondary">
</a> <i class="fas fa-money-bill-wave"></i> {% trans "Access to payments list" %}
</div> </a>
</div>
{% endif %}
{% endif %} {% endif %}
{% if pools.data %} {% if pools.data %}

View File

@ -3,6 +3,7 @@
import json import json
from django.conf import settings
from django.core.management import BaseCommand from django.core.management import BaseCommand
from ...models import Payment from ...models import Payment
@ -15,6 +16,9 @@ class Command(BaseCommand):
help = "Vérifie si les paiements Hello Asso initiés sont validés ou non. Si oui, valide les inscriptions." help = "Vérifie si les paiements Hello Asso initiés sont validés ou non. Si oui, valide les inscriptions."
def handle(self, *args, **options): def handle(self, *args, **options):
if not settings.PAYMENT_MANAGEMENT:
return
for payment in Payment.objects.exclude(valid=True).filter(checkout_intent_id__isnull=False).all(): for payment in Payment.objects.exclude(valid=True).filter(checkout_intent_id__isnull=False).all():
checkout_intent = payment.get_checkout_intent() checkout_intent = payment.get_checkout_intent()
if checkout_intent is not None and 'order' in checkout_intent: if checkout_intent is not None and 'order' in checkout_intent:

View File

@ -1,6 +1,7 @@
# Copyright (C) 2024 by Animath # Copyright (C) 2024 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from django.conf import settings
from django.core.management import BaseCommand from django.core.management import BaseCommand
from ...models import Payment from ...models import Payment
@ -13,5 +14,8 @@ class Command(BaseCommand):
help = "Envoie un mail de rappel à toustes les participant⋅es qui n'ont pas encore payé ou déclaré de paiement." help = "Envoie un mail de rappel à toustes les participant⋅es qui n'ont pas encore payé ou déclaré de paiement."
def handle(self, *args, **options): def handle(self, *args, **options):
if not settings.PAYMENT_MANAGEMENT:
return
for payment in Payment.objects.filter(valid=False).filter(registrations__team__participation__valid=True).all(): for payment in Payment.objects.filter(valid=False).filter(registrations__team__participation__valid=True).all():
payment.send_remind_mail() payment.send_remind_mail()

View File

@ -5,6 +5,11 @@ from participation.models import Tournament
def tfjm_context(request): def tfjm_context(request):
return { return {
'TFJM_APP': settings.TFJM_APP, 'TFJM': {
'SINGLE_TOURNAMENT': Tournament.objects.first() if Tournament.objects.exists() and settings.TFJM_APP else None, 'APP': settings.TFJM_APP,
'ML_MANAGEMENT': settings.ML_MANAGEMENT,
'PAYMENT_MANAGEMENT': settings.PAYMENT_MANAGEMENT,
'SINGLE_TOURNAMENT':
Tournament.objects.first() if Tournament.objects.exists() and settings.TFJM_APP else None,
}
} }

View File

@ -349,6 +349,8 @@ if TFJM_APP == "TFJM":
TEAM_CODE_LENGTH = 3 TEAM_CODE_LENGTH = 3
RECOMMENDED_SOLUTIONS_COUNT = 5 RECOMMENDED_SOLUTIONS_COUNT = 5
NB_ROUNDS = 2 NB_ROUNDS = 2
ML_MANAGEMENT = True
PAYMENT_MANAGEMENT = True
PROBLEMS = [ PROBLEMS = [
"Triominos", "Triominos",
@ -364,6 +366,8 @@ elif TFJM_APP == "ETEAM":
TEAM_CODE_LENGTH = 4 TEAM_CODE_LENGTH = 4
RECOMMENDED_SOLUTIONS_COUNT = 6 RECOMMENDED_SOLUTIONS_COUNT = 6
NB_ROUNDS = 3 NB_ROUNDS = 3
ML_MANAGEMENT = False
PAYMENT_MANAGEMENT = False
PROBLEMS = [ PROBLEMS = [
"Exploring Flatland", "Exploring Flatland",

View File

@ -19,8 +19,8 @@
<a href="{% url "index" %}" class="nav-link"><i class="fas fa-home"></i> {% trans "Home" %}</a> <a href="{% url "index" %}" class="nav-link"><i class="fas fa-home"></i> {% trans "Home" %}</a>
</li> </li>
<li class="nav-item active"> <li class="nav-item active">
{% if SINGLE_TOURNAMENT %} {% if TFJM.SINGLE_TOURNAMENT %}
<a href="{% url 'participation:tournament_detail' pk=SINGLE_TOURNAMENT.pk %}" class="nav-link"> <a href="{% url 'participation:tournament_detail' pk=TFJM.SINGLE_TOURNAMENT.pk %}" class="nav-link">
<i class="fas fa-calendar-day"></i> {% trans "Tournament" %} <i class="fas fa-calendar-day"></i> {% trans "Tournament" %}
</a> </a>
{% else %} {% else %}