You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
5.5 KiB
102 lines
5.5 KiB
from django.db import models
|
|
from django.apps import apps
|
|
from django.contrib.auth.models import AbstractUser
|
|
from django.utils.timezone import now
|
|
|
|
from django.conf import settings
|
|
from . import club, enums
|
|
from .enums import RegistrationPaymentMode
|
|
import uuid
|
|
|
|
class CustomUser(AbstractUser):
|
|
pass
|
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
|
|
last_update = models.DateTimeField(default=now)
|
|
email = models.EmailField(unique=True)
|
|
umpire_code = models.CharField(max_length=50, blank=True, null=True)
|
|
clubs = models.ManyToManyField(club.Club, blank=True, related_name='creators')
|
|
phone = models.CharField(max_length=15, null=True, blank=True)
|
|
first_name = models.CharField(max_length=50)
|
|
last_name = models.CharField(max_length=50)
|
|
licence_id = models.CharField(max_length=10, unique=True, null=True, blank=True)
|
|
country = models.CharField(max_length=40, null=True, blank=True)
|
|
|
|
summons_message_body = models.TextField(blank=True, null=True)
|
|
summons_message_signature = models.TextField(blank=True, null=True)
|
|
summons_available_payment_methods = models.TextField(blank=True, null=True)
|
|
|
|
summons_display_format = models.BooleanField(default=False)
|
|
summons_display_entry_fee = models.BooleanField(default=False)
|
|
summons_use_full_custom_message = models.BooleanField(default=False)
|
|
|
|
match_formats_default_duration = models.JSONField(blank=True, null=True)
|
|
|
|
bracket_match_format_preference = models.IntegerField(default=enums.FederalMatchCategory.NINE_GAMES, choices=enums.FederalMatchCategory.choices, null=True, blank=True)
|
|
group_stage_match_format_preference = models.IntegerField(default=enums.FederalMatchCategory.NINE_GAMES, choices=enums.FederalMatchCategory.choices, null=True, blank=True)
|
|
loser_bracket_match_format_preference = models.IntegerField(default=enums.FederalMatchCategory.NINE_GAMES, choices=enums.FederalMatchCategory.choices, null=True, blank=True)
|
|
|
|
device_id = models.CharField(max_length=50, null=True, blank=True)
|
|
agents = models.ManyToManyField('CustomUser', blank=True, related_name='owners')
|
|
loser_bracket_mode = models.IntegerField(default=0)
|
|
|
|
origin = models.IntegerField(default=enums.UserOrigin.ADMIN, choices=enums.UserOrigin.choices, null=True, blank=True)
|
|
should_synchronize = models.BooleanField(default=False)
|
|
|
|
user_role = models.IntegerField(choices=enums.UserRole.choices, null=True, blank=True)
|
|
registration_payment_mode = models.IntegerField(default=RegistrationPaymentMode.DISABLED, choices=RegistrationPaymentMode.choices)
|
|
umpire_custom_mail = models.EmailField(null=True, blank=True)
|
|
umpire_custom_contact = models.CharField(max_length=200, null=True, blank=True)
|
|
umpire_custom_phone = models.CharField(max_length=15, null=True, blank=True)
|
|
hide_umpire_mail = models.BooleanField(default=False)
|
|
hide_umpire_phone = models.BooleanField(default=True)
|
|
disable_ranking_federal_ruling = models.BooleanField(default=False)
|
|
|
|
### ### ### ### ### ### ### ### ### ### ### WARNING ### ### ### ### ### ### ### ### ### ###
|
|
### WARNING : Any added field MUST be inserted in the method below: fields_for_update() ###
|
|
### ### ### ### ### ### ### ### ### ### ### WARNING ### ### ### ### ### ### ### ### ### ###
|
|
|
|
def fields_for_update():
|
|
# returns the list of fields to update without password
|
|
return ['id', 'last_update', 'username', 'email', 'umpire_code', 'clubs', 'phone', 'first_name', 'last_name',
|
|
'licence_id', 'country',
|
|
'summons_message_body', 'summons_message_signature', 'summons_available_payment_methods',
|
|
'summons_display_format', 'summons_display_entry_fee',
|
|
'summons_use_full_custom_message', 'match_formats_default_duration', 'bracket_match_format_preference',
|
|
'group_stage_match_format_preference', 'loser_bracket_match_format_preference', 'device_id', 'loser_bracket_mode',
|
|
'origin', 'agents', 'should_synchronize', 'user_role', 'registration_payment_mode',
|
|
'umpire_custom_mail', 'umpire_custom_contact', 'umpire_custom_phone', 'hide_umpire_mail', 'hide_umpire_phone',
|
|
'disable_ranking_federal_ruling']
|
|
|
|
def __str__(self):
|
|
return self.username
|
|
|
|
def discord_string(self):
|
|
return f"{self.username} : {self.first_name} {self.last_name} | {self.email} | {self.phone}"
|
|
|
|
def event_count(self):
|
|
return self.events.count()
|
|
|
|
def full_name(self):
|
|
return f"{self.first_name} {self.last_name}"
|
|
|
|
def latest_event_club_name(self):
|
|
latest_event = self.events.order_by('-creation_date').first()
|
|
if latest_event and latest_event.club:
|
|
return latest_event.club.name
|
|
if self.licence_id:
|
|
PlayerRegistration = apps.get_model('tournaments', 'PlayerRegistration')
|
|
player_registration = PlayerRegistration.objects.filter(licence_id=self.licence_id).order_by('team_registration__registration_date').first()
|
|
try:
|
|
return player_registration.team_registration.tournament.event.club.name
|
|
except AttributeError:
|
|
return None
|
|
|
|
return None
|
|
|
|
def effective_commission_rate(self):
|
|
if self.registration_payment_mode == RegistrationPaymentMode.STRIPE:
|
|
return settings.STRIPE_FEE
|
|
if self.registration_payment_mode == RegistrationPaymentMode.NO_FEE:
|
|
return 0.0000
|
|
if self.registration_payment_mode == RegistrationPaymentMode.CORPORATE:
|
|
return 0.0000
|
|
|