diff --git a/sync/models/base.py b/sync/models/base.py index 3ac7535..9ae9ac3 100644 --- a/sync/models/base.py +++ b/sync/models/base.py @@ -190,7 +190,7 @@ class BaseModel(models.Model): for parent in parents_by_model.values(): if isinstance(parent, BaseModel): if parent.related_user: - print(f'related_user found in {parent}') + print(f'*** related_user found in {parent}') return parent.related_user else: return parent.find_related_user(processed_objects) @@ -226,7 +226,7 @@ class BaseModel(models.Model): def get_shared_children_from_relationships(self, relationships, processed_objects): - print(f'>>> {self.__class__.__name__} : relationships = {relationships}') + # print(f'>>> {self.__class__.__name__} : relationships = {relationships}') current = [self] for relationship in relationships: # print(f'> relationship = {relationship}') diff --git a/sync/signals.py b/sync/signals.py index d11cdf2..3daa230 100644 --- a/sync/signals.py +++ b/sync/signals.py @@ -74,7 +74,7 @@ def synchronization_notifications(sender, instance, created=False, **kwargs): def notify_impacted_users(instance): device_id = device_registry.get_device_id(instance.id) users = related_users_registry.get_users(instance.id) - # logger.info(f'>>> notify_impacted_users: {users} for {instance.id}') + logger.info(f'>>> notify_impacted_users: {users} for {instance.id}') if users: user_ids = [user.id for user in users] diff --git a/sync/views.py b/sync/views.py index e2d1f12..fd94605 100644 --- a/sync/views.py +++ b/sync/views.py @@ -287,7 +287,6 @@ class LogProcessingResult: def process_logs(self, logs): """Process logs to collect basic operations and handle grant/revoke efficiently.""" for log in logs: - self.last_log_date = log.date try: if log.operation in ['POST', 'PUT', 'RELATIONSHIP_SET']: data = get_serialized_data_by_id(log.model_name, log.model_id) @@ -324,7 +323,10 @@ class LogProcessingResult: self.shared_relationship_sets[log.model_name][log.model_id] = data elif log.operation == 'SHARED_RELATIONSHIP_REMOVED': self.shared_relationship_removals[log.model_name].append(log.data_identifier_dict()) + + self.last_log_date = log.date # set dates after having retrieved informations except ObjectDoesNotExist: + logger.warning(f'log processing failed, unable to find {log.model_name} : {log.model_id}') pass # Convert updates dict to list for each model diff --git a/tournaments/admin.py b/tournaments/admin.py index c7511c8..837b4b2 100644 --- a/tournaments/admin.py +++ b/tournaments/admin.py @@ -13,7 +13,7 @@ from biz.models import Prospect, ProspectGroup from .models import Club, TeamScore, Tournament, CustomUser, Event, Round, GroupStage, Match, TeamRegistration, PlayerRegistration, Purchase, Court, DateInterval, FailedApiCall, Log, DeviceToken, DrawLog, UnregisteredTeam, UnregisteredPlayer, Image from .forms import CustomUserCreationForm, CustomUserChangeForm -from .filters import TeamScoreTournamentListFilter, MatchTournamentListFilter, SimpleTournamentListFilter, MatchTypeListFilter, SimpleIndexListFilter, StartDateRangeFilter, UserWithEventsFilter, UserWithPurchasesFilter, UserWithProspectFilter +from .filters import TeamScoreTournamentListFilter, MatchTournamentListFilter, SimpleTournamentListFilter, MatchTypeListFilter, SimpleIndexListFilter, StartDateRangeFilter, UserWithEventsFilter, UserWithPurchasesFilter, UserWithProspectFilter, TeamScoreRoundIndexFilter from sync.admin import SyncedObjectAdmin import logging @@ -365,7 +365,7 @@ class TeamRegistrationAdmin(SyncedObjectAdmin): class TeamScoreAdmin(SyncedObjectAdmin): list_display = ['team_registration', 'score', 'walk_out', 'match'] - list_filter = [TeamScoreTournamentListFilter] + list_filter = [TeamScoreRoundIndexFilter, TeamScoreTournamentListFilter] search_fields = ['id', 'team_registration__player_registrations__first_name', 'team_registration__player_registrations__last_name'] raw_id_fields = ['team_registration', 'match'] list_per_page = 50 # Controls pagination on the list view diff --git a/tournaments/filters.py b/tournaments/filters.py index f55cfbb..416ea0b 100644 --- a/tournaments/filters.py +++ b/tournaments/filters.py @@ -1,5 +1,5 @@ from django.contrib import admin -from .models import Tournament, Match +from .models import Tournament, Match, Round from django.db.models import Q, Count from django.utils.translation import gettext_lazy as _ from django.utils import timezone @@ -189,3 +189,28 @@ class UserWithProspectFilter(admin.SimpleListFilter): prospect_emails = Prospect.objects.values_list('email', flat=True).filter(email__isnull=False) return queryset.exclude(email__in=prospect_emails) return queryset + +class TeamScoreRoundIndexFilter(admin.SimpleListFilter): + title = _("Round Index") + parameter_name = "round_index" + + def lookups(self, request, model_admin): + # Get distinct round indexes from matches that have team scores + round_indexes = Round.objects.filter( + matches__team_scores__isnull=False + ).values_list('index', flat=True).distinct().order_by('index') + + # Create lookup tuples with round names + lookups = [] + for index in round_indexes: + round_obj = Round.objects.filter(index=index, parent__isnull=True).first() + if round_obj: + lookups.append((index, round_obj.name())) + else: + lookups.append((index, f"Index {index}")) + return lookups + + def queryset(self, request, queryset): + if self.value(): + return queryset.filter(match__round__index=self.value()) + return queryset diff --git a/tournaments/signals.py b/tournaments/signals.py index 5671ceb..77a7f43 100644 --- a/tournaments/signals.py +++ b/tournaments/signals.py @@ -161,7 +161,7 @@ def warn_team_walkout_status_change(sender, instance, **kwargs): try: previous_instance = TeamRegistration.objects.get(id=instance.id) except TeamRegistration.DoesNotExist: - print("TeamRegistration.DoesNotExist") + print("warn_team_walkout > TeamRegistration.DoesNotExist") return ttc = None