mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-10-31 02:49:53 +01:00 
			
		
		
		
	Display tournament list
This commit is contained in:
		| @@ -1,4 +1,4 @@ | |||||||
| from django.core.management import BaseCommand | from django.core.management import BaseCommand, CommandError | ||||||
| from django.db import transaction | from django.db import transaction | ||||||
|  |  | ||||||
| from member.models import TFJMUser, Document, Solution, Synthesis, Authorization, MotivationLetter | from member.models import TFJMUser, Document, Solution, Synthesis, Authorization, MotivationLetter | ||||||
| @@ -61,6 +61,17 @@ class Command(BaseCommand): | |||||||
|                     Tournament.objects.create(**obj_dict) |                     Tournament.objects.create(**obj_dict) | ||||||
|         print(self.style.SUCCESS("Tournaments imported")) |         print(self.style.SUCCESS("Tournaments imported")) | ||||||
|  |  | ||||||
|  |     @staticmethod | ||||||
|  |     def validation_status(status): | ||||||
|  |         if status == "NOT_READY": | ||||||
|  |             return "0invalid" | ||||||
|  |         elif status == "WAITING": | ||||||
|  |             return "1waiting" | ||||||
|  |         elif status == "VALIDATED": | ||||||
|  |             return "2valid" | ||||||
|  |         else: | ||||||
|  |             raise CommandError("Unknown status: {}".format(status)) | ||||||
|  |  | ||||||
|     @transaction.atomic |     @transaction.atomic | ||||||
|     def import_teams(self): |     def import_teams(self): | ||||||
|         self.stdout.write("Importing teams...") |         self.stdout.write("Importing teams...") | ||||||
| @@ -84,7 +95,7 @@ class Command(BaseCommand): | |||||||
|                     "trigram": args[2], |                     "trigram": args[2], | ||||||
|                     "tournament": Tournament.objects.get(pk=args[3]), |                     "tournament": Tournament.objects.get(pk=args[3]), | ||||||
|                     "inscription_date": args[13], |                     "inscription_date": args[13], | ||||||
|                     "validation_status": args[14].lower(), |                     "validation_status": Command.validation_status(args[14]), | ||||||
|                     "selected_for_final": args[15], |                     "selected_for_final": args[15], | ||||||
|                     "access_code": args[16], |                     "access_code": args[16], | ||||||
|                     "year": args[17], |                     "year": args[17], | ||||||
| @@ -93,6 +104,19 @@ class Command(BaseCommand): | |||||||
|                     Team.objects.create(**obj_dict) |                     Team.objects.create(**obj_dict) | ||||||
|         print(self.style.SUCCESS("Teams imported")) |         print(self.style.SUCCESS("Teams imported")) | ||||||
|  |  | ||||||
|  |     @staticmethod | ||||||
|  |     def role(role): | ||||||
|  |         if role == "ADMIN": | ||||||
|  |             return "0admin" | ||||||
|  |         elif role == "ORGANIZER": | ||||||
|  |             return "1volunteer" | ||||||
|  |         elif role == "ENCADRANT": | ||||||
|  |             return "2coach" | ||||||
|  |         elif role == "PARTICIPANT": | ||||||
|  |             return "3participant" | ||||||
|  |         else: | ||||||
|  |             raise CommandError("Unknown role: {}".format(role)) | ||||||
|  |  | ||||||
|     @transaction.atomic |     @transaction.atomic | ||||||
|     def import_users(self): |     def import_users(self): | ||||||
|         self.stdout.write("Importing users...") |         self.stdout.write("Importing users...") | ||||||
| @@ -130,7 +154,7 @@ class Command(BaseCommand): | |||||||
|                     "responsible_phone": args[15], |                     "responsible_phone": args[15], | ||||||
|                     "responsible_email": args[16], |                     "responsible_email": args[16], | ||||||
|                     "description": args[17].replace("\\n", "\n") if args[17] else None, |                     "description": args[17].replace("\\n", "\n") if args[17] else None, | ||||||
|                     "role": args[18].lower(), |                     "role": Command.role(args[18]), | ||||||
|                     "team": Team.objects.get(pk=args[19]) if args[19] else None, |                     "team": Team.objects.get(pk=args[19]) if args[19] else None, | ||||||
|                     "year": args[20], |                     "year": args[20], | ||||||
|                     "date_joined": args[23], |                     "date_joined": args[23], | ||||||
|   | |||||||
| @@ -127,10 +127,10 @@ class TFJMUser(AbstractUser): | |||||||
|     role = models.CharField( |     role = models.CharField( | ||||||
|         max_length=16, |         max_length=16, | ||||||
|         choices=[ |         choices=[ | ||||||
|             ("admin", _("admin")), |             ("0admin", _("admin")), | ||||||
|             ("organizer", _("organizer")), |             ("1volunteer", _("organizer")), | ||||||
|             ("encadrant", _("encadrant")), |             ("2coach", _("coach")), | ||||||
|             ("participant", _("participant")), |             ("3participant", _("participant")), | ||||||
|         ] |         ] | ||||||
|     ) |     ) | ||||||
|  |  | ||||||
| @@ -141,15 +141,15 @@ class TFJMUser(AbstractUser): | |||||||
|  |  | ||||||
|     @property |     @property | ||||||
|     def participates(self): |     def participates(self): | ||||||
|         return self.role == "participant" or self.role == "encadrant" |         return self.role == "3participant" or self.role == "2encadrant" | ||||||
|  |  | ||||||
|     @property |     @property | ||||||
|     def organizes(self): |     def organizes(self): | ||||||
|         return self.role == "organizer" or self.role == "admin" |         return self.role == "1volunteer" or self.role == "0admin" | ||||||
|  |  | ||||||
|     @property |     @property | ||||||
|     def admin(self): |     def admin(self): | ||||||
|         return self.role == "admin" |         return self.role == "0admin" | ||||||
|  |  | ||||||
|     class Meta: |     class Meta: | ||||||
|         verbose_name = _("user") |         verbose_name = _("user") | ||||||
|   | |||||||
| @@ -100,9 +100,9 @@ class Team(models.Model): | |||||||
|     validation_status = models.CharField( |     validation_status = models.CharField( | ||||||
|         max_length=8, |         max_length=8, | ||||||
|         choices=[ |         choices=[ | ||||||
|             ("invalid", _("Registration not validated")), |             ("0invalid", _("Registration not validated")), | ||||||
|             ("waiting", _("Waiting for validation")), |             ("1waiting", _("Waiting for validation")), | ||||||
|             ("valid", _("Registration validated")), |             ("1valid", _("Registration validated")), | ||||||
|         ], |         ], | ||||||
|         verbose_name=_("validation status"), |         verbose_name=_("validation status"), | ||||||
|     ) |     ) | ||||||
| @@ -184,9 +184,9 @@ class Payment(models.Model): | |||||||
|     validation_status = models.CharField( |     validation_status = models.CharField( | ||||||
|         max_length=8, |         max_length=8, | ||||||
|         choices=[ |         choices=[ | ||||||
|             ("invalid", _("Registration not validated")), |             ("0invalid", _("Registration not validated")), | ||||||
|             ("waiting", _("Waiting for validation")), |             ("1waiting", _("Waiting for validation")), | ||||||
|             ("valid", _("Registration validated")), |             ("2valid", _("Registration validated")), | ||||||
|         ], |         ], | ||||||
|         verbose_name=_("validation status"), |         verbose_name=_("validation status"), | ||||||
|     ) |     ) | ||||||
|   | |||||||
							
								
								
									
										20
									
								
								apps/tournament/tables.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								apps/tournament/tables.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | |||||||
|  | import django_tables2 as tables | ||||||
|  | from django.utils.translation import gettext as _ | ||||||
|  |  | ||||||
|  | from .models import Tournament | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class TournamentTable(tables.Table): | ||||||
|  |     date_start = tables.Column( | ||||||
|  |         verbose_name=_("dates").capitalize(), | ||||||
|  |     ) | ||||||
|  |  | ||||||
|  |     def render_date_start(self, record): | ||||||
|  |         return _("From {start:%b %d %Y} to {end:%b %d %Y}").format(start=record.date_start, end=record.date_end) | ||||||
|  |  | ||||||
|  |     class Meta: | ||||||
|  |         model = Tournament | ||||||
|  |         fields = ("name", "date_start", "date_inscription", "date_solutions", "size", ) | ||||||
|  |         attrs = { | ||||||
|  |             'class': 'table table-condensed table-striped table-hover' | ||||||
|  |         } | ||||||
							
								
								
									
										9
									
								
								apps/tournament/urls.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								apps/tournament/urls.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | from django.urls import path | ||||||
|  |  | ||||||
|  | from .views import TournamentListView | ||||||
|  |  | ||||||
|  | app_name = "tournament" | ||||||
|  |  | ||||||
|  | urlpatterns = [ | ||||||
|  |     path('list/', TournamentListView.as_view(), name="list"), | ||||||
|  | ] | ||||||
| @@ -1,3 +1,24 @@ | |||||||
| from django.shortcuts import render | from django.db.models import Q | ||||||
|  | from django.utils.translation import gettext_lazy as _ | ||||||
|  | from django_tables2.views import SingleTableView | ||||||
|  |  | ||||||
| # Create your views here. | from member.models import TFJMUser | ||||||
|  | from .models import Tournament | ||||||
|  | from .tables import TournamentTable | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class TournamentListView(SingleTableView): | ||||||
|  |     model = Tournament | ||||||
|  |     table_class = TournamentTable | ||||||
|  |     extra_context = dict(title=_("Tournaments list"),) | ||||||
|  |  | ||||||
|  |     def get_context_data(self, **kwargs): | ||||||
|  |         context = super().get_context_data(**kwargs) | ||||||
|  |  | ||||||
|  |         team_users = TFJMUser.objects.filter(Q(team__isnull=False) | Q(role="admin") | Q(role="organizer")) | ||||||
|  |         valid_team_users = team_users.filter(Q(team__validation_status="valid") | Q(role="admin") | Q(role="organizer")) | ||||||
|  |  | ||||||
|  |         context["team_users_emails"] = [user.email for user in team_users] | ||||||
|  |         context["valid_team_users_emails"] = [user.email for user in valid_team_users] | ||||||
|  |  | ||||||
|  |         return context | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ msgid "" | |||||||
| msgstr "" | msgstr "" | ||||||
| "Project-Id-Version: TFJM2\n" | "Project-Id-Version: TFJM2\n" | ||||||
| "Report-Msgid-Bugs-To: \n" | "Report-Msgid-Bugs-To: \n" | ||||||
| "POT-Creation-Date: 2020-04-29 06:24+0000\n" | "POT-Creation-Date: 2020-04-29 14:09+0000\n" | ||||||
| "PO-Revision-Date: 2020-04-29 02:30+0000\n" | "PO-Revision-Date: 2020-04-29 02:30+0000\n" | ||||||
| "Last-Translator: Yohann D'ANELLO <yohann.danello@animath.fr>\n" | "Last-Translator: Yohann D'ANELLO <yohann.danello@animath.fr>\n" | ||||||
| "Language-Team: fr <LL@li.org>\n" | "Language-Team: fr <LL@li.org>\n" | ||||||
| @@ -125,8 +125,8 @@ msgid "organizer" | |||||||
| msgstr "oragnisateur" | msgstr "oragnisateur" | ||||||
|  |  | ||||||
| #: apps/member/models.py:132 | #: apps/member/models.py:132 | ||||||
| msgid "encadrant" | msgid "coach" | ||||||
| msgstr "encadrant" | msgstr "" | ||||||
|  |  | ||||||
| #: apps/member/models.py:133 | #: apps/member/models.py:133 | ||||||
| msgid "participant" | msgid "participant" | ||||||
| @@ -190,6 +190,8 @@ msgstr "autorisation" | |||||||
| msgid "authorizations" | msgid "authorizations" | ||||||
| msgstr "autorisations" | msgstr "autorisations" | ||||||
|  |  | ||||||
|  | #: apps/member/models.py:206 | ||||||
|  | #, python-brace-format | ||||||
| msgid "{authorization} for user {user}" | msgid "{authorization} for user {user}" | ||||||
| msgstr "{authorization} pour l'utilisateur {user}" | msgstr "{authorization} pour l'utilisateur {user}" | ||||||
|  |  | ||||||
| @@ -390,6 +392,18 @@ msgstr "paiements" | |||||||
| msgid "Payment of {user}" | msgid "Payment of {user}" | ||||||
| msgstr "Paiement de {user}" | msgstr "Paiement de {user}" | ||||||
|  |  | ||||||
|  | #: apps/tournament/tables.py:9 | ||||||
|  | msgid "dates" | ||||||
|  | msgstr "dates" | ||||||
|  |  | ||||||
|  | #: apps/tournament/tables.py:13 | ||||||
|  | msgid "From {start:%b %d %Y} to {end:%b %d %Y}" | ||||||
|  | msgstr "Du {start: %d %b %Y} au {end:%d %b %Y}" | ||||||
|  |  | ||||||
|  | #: apps/tournament/views.py:13 | ||||||
|  | msgid "Tournaments list" | ||||||
|  | msgstr "Liste des tournois" | ||||||
|  |  | ||||||
| #: templates/base.html:11 | #: templates/base.html:11 | ||||||
| msgid "The inscription site of the TFJM²." | msgid "The inscription site of the TFJM²." | ||||||
| msgstr "Le site d'inscription au TFJM²." | msgstr "Le site d'inscription au TFJM²." | ||||||
| @@ -403,6 +417,11 @@ msgstr "Votre adresse e-mail a bien été validée." | |||||||
| msgid "You can now <a href=\"%(login_url)s\">log in</a>." | msgid "You can now <a href=\"%(login_url)s\">log in</a>." | ||||||
| msgstr "Vous pouvez désormais <a href=\"%(login_url)s\">vous connecter</a>" | msgstr "Vous pouvez désormais <a href=\"%(login_url)s\">vous connecter</a>" | ||||||
|  |  | ||||||
|  | #: templates/registration/email_validation_complete.html:10 | ||||||
|  | msgid "" | ||||||
|  | "You must pay now your membership in the Kfet to complete your registration." | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
| #: templates/registration/email_validation_complete.html:13 | #: templates/registration/email_validation_complete.html:13 | ||||||
| msgid "" | msgid "" | ||||||
| "The link was invalid. The token may have expired. Please send us an email to " | "The link was invalid. The token may have expired. Please send us an email to " | ||||||
| @@ -432,7 +451,8 @@ msgid "" | |||||||
| "page. Would you like to login to a different account?" | "page. Would you like to login to a different account?" | ||||||
| msgstr "" | msgstr "" | ||||||
| "Vous êtes déjà connecté sous le nom %(user)s, mais vous n'êtes pas autorisés " | "Vous êtes déjà connecté sous le nom %(user)s, mais vous n'êtes pas autorisés " | ||||||
| "à accéder à cette page. Souhaitez-vous vous connecter sous un compte différent ?" | "à accéder à cette page. Souhaitez-vous vous connecter sous un compte " | ||||||
|  | "différent ?" | ||||||
|  |  | ||||||
| #: templates/registration/login.html:23 | #: templates/registration/login.html:23 | ||||||
| msgid "Forgotten your password or username?" | msgid "Forgotten your password or username?" | ||||||
| @@ -533,3 +553,6 @@ msgstr "Anglais" | |||||||
| #: tfjm/settings.py:136 | #: tfjm/settings.py:136 | ||||||
| msgid "French" | msgid "French" | ||||||
| msgstr "Français" | msgstr "Français" | ||||||
|  |  | ||||||
|  | #~ msgid "encadrant" | ||||||
|  | #~ msgstr "encadrant" | ||||||
|   | |||||||
| @@ -73,7 +73,7 @@ | |||||||
|                     <a href="/" class="nav-link"><i class="fas fa-home"></i> Accueil</a> |                     <a href="/" class="nav-link"><i class="fas fa-home"></i> Accueil</a> | ||||||
|                 </li> |                 </li> | ||||||
|                 <li class="nav-item active"> |                 <li class="nav-item active"> | ||||||
|                     <a class="nav-link" href="/tournois"><i class="fas fa-calendar"></i> Liste des tournois</a> |                     <a class="nav-link" href="{% url "tournament:list" %}"><i class="fas fa-calendar"></i> Liste des tournois</a> | ||||||
|                     {% if user.organizes %} |                     {% if user.organizes %} | ||||||
|                         <ul class="deroule"> |                         <ul class="deroule"> | ||||||
|                             {% if user.admin %} |                             {% if user.admin %} | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								templates/tournament/tournament_list.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								templates/tournament/tournament_list.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | {% extends "base.html" %} | ||||||
|  |  | ||||||
|  | {% load django_tables2 getconfig i18n %} | ||||||
|  |  | ||||||
|  | {% block content %} | ||||||
|  |     {% if user.is_authenticated and user.admin %} | ||||||
|  |         <div class="alert alert-info"> | ||||||
|  |             <a href="mailto:contact@tfm.org?subject=TFJM²%20{{ "TFJM_YEAR"|get_env }}&bcc={{ team_users_emails|join:"," }}">{% trans "Send a mail to all people that are in a team" %}</a><br> | ||||||
|  |             <a href="mailto:contact@tfm.org?subject=TFJM²%20{{ "TFJM_YEAR"|get_env }}&bcc={{ valid_team_users_emails|join:"," }}">{% trans "Send a mail to all people that are in a valid team" %}</a> | ||||||
|  |         </div> | ||||||
|  |     {% endif %} | ||||||
|  |     {% render_table table %} | ||||||
|  | {% endblock %} | ||||||
| @@ -69,6 +69,8 @@ MIDDLEWARE = [ | |||||||
|  |  | ||||||
| ROOT_URLCONF = 'tfjm.urls' | ROOT_URLCONF = 'tfjm.urls' | ||||||
|  |  | ||||||
|  | LOGIN_REDIRECT_URL = "index" | ||||||
|  |  | ||||||
| TEMPLATES = [ | TEMPLATES = [ | ||||||
|     { |     { | ||||||
|         'BACKEND': 'django.template.backends.django.DjangoTemplates', |         'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user