# Path: accounts/utils.py
# def user_without_team(user):
#     return user.profile.team is None


from cities_light.models import Country
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Sum
from django.db.models.expressions import RawSQL
from django.db.models.functions import Coalesce
from django.dispatch import receiver
from django.db.models.signals import post_save, post_delete
from accounts.utils import user_without_team
        from challenges.models import Challenge
        from challenges.models import Challenge
        from challenges.models import Category
        from challenges.models import ChallengeSolved
        from challenges.models import Challenge
        from challenges.models import Challenge
    from SCTF.consumers import send_message_to_user
    from SCTF.consumers import send_message_to_user
    @property
    def failed_challenges(self):
        return self._all_failed_challenges.exclude(pk__in=self.solved_challenges.all())


class UserTeamRequestQuerySet(models.QuerySet):

    def pending(self):
        return self.filter(status='P')

    def accepted(self):
        return self.filter(status='A')

    def rejected(self):
        return self.filter(status='R')


class UserTeamRequest(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    team = models.ForeignKey(Team, on_delete=models.CASCADE)
    datetime = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=1, default='P', choices=(
        ('P', 'Pending'),
        ('A', 'Accepted'),
        ('R', 'Rejected'),
    ))

    objects = UserTeamRequestQuerySet.as_manager()

    def clean(self):

# Path: accounts/utils.py
# def user_without_team(user):
#     return user.profile.team is None


# Path: accounts/models.py
from cities_light.models import Country
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Sum
from django.db.models.expressions import RawSQL
from django.db.models.functions import Coalesce
from django.dispatch import receiver
from django.db.models.signals import post_save, post_delete
from accounts.utils import user_without_team
        from challenges.models import Challenge
        from challenges.models import Challenge
        from challenges.models import Category
        from challenges.models import ChallengeSolved
        from challenges.models import Challenge
        from challenges.models import Challenge
    from SCTF.consumers import send_message_to_user
    from SCTF.consumers import send_message_to_user

    @property
    def failed_challenges(self):
        return self._all_failed_challenges.exclude(pk__in=self.solved_challenges.all())


class UserTeamRequestQuerySet(models.QuerySet):

    def pending(self):
        return self.filter(status='P')

    def accepted(self):
        return self.filter(status='A')

    def rejected(self):
        return self.filter(status='R')


class UserTeamRequest(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    team = models.ForeignKey(Team, on_delete=models.CASCADE)
    datetime = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=1, default='P', choices=(
        ('P', 'Pending'),
        ('A', 'Accepted'),
        ('R', 'Rejected'),
    ))

    objects = UserTeamRequestQuerySet.as_manager()

    def clean(self):

        if not user_without_team(self.user):