mirror of
				https://gitlab.com/animath/si/plateforme.git
				synced 2025-11-04 03:42:11 +01:00 
			
		
		
		
	@@ -1,12 +1,13 @@
 | 
			
		||||
# Copyright (C) 2024 by Animath
 | 
			
		||||
# SPDX-License-Identifier: GPL-3.0-or-later
 | 
			
		||||
 | 
			
		||||
from asgiref.sync import sync_to_async
 | 
			
		||||
from django.contrib.auth.models import User
 | 
			
		||||
from django.db import models
 | 
			
		||||
from django.db.models import Q, QuerySet
 | 
			
		||||
from django.utils.text import format_lazy
 | 
			
		||||
from django.utils.translation import gettext_lazy as _
 | 
			
		||||
from participation.models import Tournament
 | 
			
		||||
from participation.models import Pool, Team, Tournament
 | 
			
		||||
from registration.models import ParticipantRegistration, Registration, VolunteerRegistration
 | 
			
		||||
from tfjm.permissions import PermissionType
 | 
			
		||||
 | 
			
		||||
@@ -141,9 +142,6 @@ class Channel(models.Model):
 | 
			
		||||
 | 
			
		||||
        qs |= Channel.objects.filter(invited=user)
 | 
			
		||||
 | 
			
		||||
        print(user)
 | 
			
		||||
        print(qs.query)
 | 
			
		||||
 | 
			
		||||
        return qs
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
@@ -182,6 +180,65 @@ class Message(models.Model):
 | 
			
		||||
        verbose_name=_("content"),
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    def get_author_name(self):
 | 
			
		||||
        registration = self.author.registration
 | 
			
		||||
 | 
			
		||||
        author_name = f"{self.author.first_name} {self.author.last_name}"
 | 
			
		||||
        if registration.is_volunteer:
 | 
			
		||||
            if registration.is_admin:
 | 
			
		||||
                author_name += " (CNO)"
 | 
			
		||||
 | 
			
		||||
            if self.channel.pool:
 | 
			
		||||
                if registration == self.channel.pool.jury_president:
 | 
			
		||||
                    author_name += " (P. jury)"
 | 
			
		||||
                elif registration in self.channel.pool.juries.all():
 | 
			
		||||
                    author_name += " (Juré⋅e)"
 | 
			
		||||
                elif registration in self.channel.pool.tournament.organizers.all():
 | 
			
		||||
                    author_name += " (CRO)"
 | 
			
		||||
                else:
 | 
			
		||||
                    author_name += " (Bénévole)"
 | 
			
		||||
            elif self.channel.tournament:
 | 
			
		||||
                if registration in self.channel.tournament.organizers.all():
 | 
			
		||||
                    author_name += " (CRO)"
 | 
			
		||||
                elif any([registration.id == pool.jury_president
 | 
			
		||||
                          for pool in self.channel.tournament.pools.all()]):
 | 
			
		||||
                    pools = ", ".join([pool.short_name
 | 
			
		||||
                                       for pool in self.channel.tournament.pools.all()
 | 
			
		||||
                                       if pool.jury_president == registration])
 | 
			
		||||
                    author_name += f" (P. jury {pools})"
 | 
			
		||||
                elif any([pool.juries.contains(registration)
 | 
			
		||||
                          for pool in self.channel.tournament.pools.all()]):
 | 
			
		||||
                    pools = ", ".join([pool.short_name
 | 
			
		||||
                                       for pool in self.channel.tournament.pools.all()
 | 
			
		||||
                                       if pool.juries.acontains(registration)])
 | 
			
		||||
                    author_name += f" (Juré⋅e {pools})"
 | 
			
		||||
                else:
 | 
			
		||||
                    author_name += " (Bénévole)"
 | 
			
		||||
            else:
 | 
			
		||||
                if registration.organized_tournaments.exists():
 | 
			
		||||
                    tournaments = ", ".join([tournament.name
 | 
			
		||||
                                             for tournament in registration.organized_tournaments.all()])
 | 
			
		||||
                    author_name += f" (CRO {tournaments})"
 | 
			
		||||
                if Pool.objects.filter(jury_president=registration).exists():
 | 
			
		||||
                    tournaments = Tournament.objects.filter(pools__jury_president=registration).distinct()
 | 
			
		||||
                    tournaments = ", ".join([tournament.name for tournament in tournaments])
 | 
			
		||||
                    author_name += f" (P. jury {tournaments})"
 | 
			
		||||
                elif registration.jury_in.exists():
 | 
			
		||||
                    tournaments = Tournament.objects.filter(pools__juries=registration).distinct()
 | 
			
		||||
                    tournaments = ", ".join([tournament.name for tournament in tournaments])
 | 
			
		||||
                    author_name += f" (Juré⋅e {tournaments})"
 | 
			
		||||
        else:
 | 
			
		||||
            if registration.team_id:
 | 
			
		||||
                team = Team.objects.get(id=registration.team_id)
 | 
			
		||||
                author_name += f" ({team.trigram})"
 | 
			
		||||
            else:
 | 
			
		||||
                author_name += " (sans équipe)"
 | 
			
		||||
 | 
			
		||||
        return author_name
 | 
			
		||||
 | 
			
		||||
    async def aget_author_name(self):
 | 
			
		||||
        return await sync_to_async(self.get_author_name)()
 | 
			
		||||
 | 
			
		||||
    class Meta:
 | 
			
		||||
        verbose_name = _("message")
 | 
			
		||||
        verbose_name_plural = _("messages")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user