Remove cascade deletes + fix granting issue + fix broadcast code setting

sync
Laurent 10 months ago
parent 1f4fad4302
commit 4767a15f1f
  1. 6
      sync/models/data_access.py
  2. 4
      sync/signals.py
  3. 2
      tournaments/models/court.py
  4. 2
      tournaments/models/date_interval.py
  5. 2
      tournaments/models/draw_log.py
  6. 2
      tournaments/models/group_stage.py
  7. 4
      tournaments/models/match.py
  8. 2
      tournaments/models/player_registration.py
  9. 4
      tournaments/models/round.py
  10. 2
      tournaments/models/team_registration.py
  11. 4
      tournaments/models/team_score.py
  12. 2
      tournaments/models/tournament.py
  13. 4
      tournaments/signals.py

@ -21,6 +21,12 @@ class DataAccess(BaseModel):
def create_revoke_access_log(self):
self.create_access_log(self.shared_with.all(), 'REVOKE_ACCESS')
def concerned_users(self):
users = list(self.shared_with.all())
if self.related_user:
users.append(self.related_user)
return users
def create_access_log(self, users, operation):
"""Create an access log for a list of users """
model_class = sync_registry.get_model(self.model_name)

@ -161,10 +161,10 @@ def detect_foreign_key_changes(sender, instance, device_id):
for data_access in data_access_list:
if old_value:
model_name = old_value.__class__.__name__
save_model_log(data_access.shared_with.all(), 'REVOKE_ACCESS', model_name, old_value.id, old_value.get_store_id(), device_id)
save_model_log(data_access.concerned_users(), 'REVOKE_ACCESS', model_name, old_value.id, old_value.get_store_id(), device_id)
if new_value:
model_name = new_value.__class__.__name__
save_model_log(data_access.shared_with.all(), 'GRANT_ACCESS', model_name, new_value.id, new_value.get_store_id(), device_id)
save_model_log(data_access.concerned_users(), 'GRANT_ACCESS', model_name, new_value.id, new_value.get_store_id(), device_id)
# REVOKE access for old_value and GRANT new_value
print(f"Foreign key changed in {sender.__name__}: "

@ -5,7 +5,7 @@ from . import BaseModel, Club
class Court(BaseModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
index = models.IntegerField(default=0)
club = models.ForeignKey(Club, on_delete=models.CASCADE, related_name='courts')
club = models.ForeignKey(Club, on_delete=models.SET_NULL, related_name='courts', null=True)
name = models.CharField(max_length=50, null=True, blank=True)
exit_allowed = models.BooleanField(default=False)
indoor = models.BooleanField(default=False)

@ -4,7 +4,7 @@ from . import BaseModel
class DateInterval(BaseModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
event = models.ForeignKey('Event', on_delete=models.CASCADE, related_name='date_intervals')
event = models.ForeignKey('Event', on_delete=models.SET_NULL, related_name='date_intervals', null=True)
court_index = models.IntegerField()
start_date = models.DateTimeField()
end_date = models.DateTimeField()

@ -4,7 +4,7 @@ import uuid
class DrawLog(SideStoreModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
tournament = models.ForeignKey('Tournament', on_delete=models.CASCADE, related_name='draw_logs')
tournament = models.ForeignKey('Tournament', on_delete=models.SET_NULL, related_name='draw_logs', null=True)
draw_date = models.DateTimeField()
draw_seed = models.IntegerField()
draw_match_index = models.IntegerField()

@ -9,7 +9,7 @@ from django.utils import timezone
class GroupStage(SideStoreModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE, related_name='group_stages')
tournament = models.ForeignKey(Tournament, on_delete=models.SET_NULL, related_name='group_stages', null=True)
index = models.IntegerField(default=0)
size = models.IntegerField(default=4)
format = models.IntegerField(default=FederalMatchCategory.NINE_GAMES, choices=FederalMatchCategory.choices, null=True, blank=True)

@ -10,8 +10,8 @@ from ..utils.extensions import format_seconds
class Match(SideStoreModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
round = models.ForeignKey(Round, null=True, blank=True, on_delete=models.CASCADE, related_name='matches')
group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.CASCADE, related_name='matches')
round = models.ForeignKey(Round, null=True, blank=True, on_delete=models.SET_NULL, related_name='matches')
group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.SET_NULL, related_name='matches')
name = models.CharField(max_length=200, null=True, blank=True)
start_date = models.DateTimeField(null=True, blank=True)
end_date = models.DateTimeField(null=True, blank=True)

@ -4,7 +4,7 @@ import uuid
class PlayerRegistration(SideStoreModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
team_registration = models.ForeignKey(TeamRegistration, on_delete=models.CASCADE, related_name='player_registrations')
team_registration = models.ForeignKey(TeamRegistration, on_delete=models.SET_NULL, related_name='player_registrations', null=True)
first_name = models.CharField(max_length=50, blank=True)
last_name = models.CharField(max_length=50, blank=True)
licence_id = models.CharField(max_length=50, null=True, blank=True)

@ -4,9 +4,9 @@ import uuid
class Round(SideStoreModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE, related_name='rounds')
tournament = models.ForeignKey(Tournament, on_delete=models.SET_NULL, related_name='rounds', null=True)
index = models.IntegerField(default=0)
parent = models.ForeignKey('self', blank=True, null=True, on_delete=models.CASCADE, related_name='children')
parent = models.ForeignKey('self', blank=True, null=True, on_delete=models.SET_NULL, related_name='children')
format = models.IntegerField(default=FederalMatchCategory.NINE_GAMES, choices=FederalMatchCategory.choices, null=True, blank=True)
start_date = models.DateTimeField(null=True, blank=True)
group_stage_loser_bracket = models.BooleanField(default=False)

@ -6,7 +6,7 @@ from django.utils import timezone
class TeamRegistration(SideStoreModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
tournament = models.ForeignKey(Tournament, on_delete=models.CASCADE, related_name='team_registrations')
tournament = models.ForeignKey(Tournament, on_delete=models.SET_NULL, related_name='team_registrations', null=True)
group_stage = models.ForeignKey(GroupStage, null=True, blank=True, on_delete=models.SET_NULL, related_name='team_registrations')
registration_date = models.DateTimeField(null=True, blank=True)
call_date = models.DateTimeField(null=True, blank=True)

@ -4,8 +4,8 @@ import uuid
class TeamScore(SideStoreModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
match = models.ForeignKey(Match, on_delete=models.CASCADE, related_name="team_scores")
team_registration = models.ForeignKey(TeamRegistration, on_delete=models.CASCADE, null=True, blank=True, related_name="team_scores")
match = models.ForeignKey(Match, on_delete=models.SET_NULL, related_name="team_scores", null=True)
team_registration = models.ForeignKey(TeamRegistration, on_delete=models.SET_NULL, null=True, blank=True, related_name="team_scores")
score = models.CharField(max_length=50, null=True, blank=True)
walk_out = models.IntegerField(null=True, blank=True) # TODO type of WO: forfeit, injury...
lucky_loser = models.IntegerField(null=True, blank=True)

@ -20,7 +20,7 @@ class TeamSortingType(models.IntegerChoices):
class Tournament(BaseModel):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=True)
event = models.ForeignKey(Event, blank=True, null=True, on_delete=models.CASCADE, related_name="tournaments")
event = models.ForeignKey(Event, blank=True, null=True, on_delete=models.SET_NULL, related_name="tournaments")
name = models.CharField(max_length=200, null=True, blank=True)
start_date = models.DateTimeField()
end_date = models.DateTimeField(null=True, blank=True)

@ -20,8 +20,8 @@ def generate_unique_code():
return code
@receiver(post_save, sender=Club)
def assign_unique_code(sender, instance, created, **kwargs):
if created and not instance.broadcast_code:
def assign_unique_code(sender, instance, **kwargs):
if not instance.broadcast_code:
instance.broadcast_code = generate_unique_code()
instance.save()

Loading…
Cancel
Save