Fix sync for online registrations

sync
Laurent 8 months ago
parent 21ce64d941
commit 9c95e0d4c9
  1. 5
      sync/signals.py
  2. 2
      sync/views.py
  3. 2
      tournaments/services/tournament_registration.py
  4. 3
      tournaments/signals.py
  5. 5
      tournaments/utils/extensions.py
  6. 2
      tournaments/views.py

@ -126,7 +126,9 @@ def save_model_log(users, model_operation, model_name, model_id, store_id):
with transaction.atomic(): with transaction.atomic():
for user in users: for user in users:
if user.should_synchronize: print(f'>>> create log for {user.username} : {model_operation} {model_name}')
# if user.should_synchronize:
model_log = ModelLog() model_log = ModelLog()
model_log.user = user model_log.user = user
model_log.operation = model_operation model_log.operation = model_operation
@ -249,6 +251,7 @@ def related_users(instance):
# look in hierarchy # look in hierarchy
related_instances = instance.related_instances() related_instances = instance.related_instances()
print(f'related_instances = {related_instances}')
related_users = [ri.related_user for ri in related_instances if isinstance(ri, BaseModel)] related_users = [ri.related_user for ri in related_instances if isinstance(ri, BaseModel)]
users.update(related_users) users.update(related_users)

@ -106,7 +106,7 @@ class SynchronizationApi(HierarchyApiView):
data = op.get('data') data = op.get('data')
data_id = data.get('id') data_id = data.get('id')
device_registry.register(data_id, device_id) device_registry.register(data_id, device_id)
print(f'*** 1count = {device_registry.count()}') # print(f'*** 1count = {device_registry.count()}')
try: try:
print(f'{model_operation} : {model_name}, id = {data['id']}') print(f'{model_operation} : {model_name}, id = {data['id']}')

@ -6,6 +6,7 @@ from django.contrib import messages
from ..utils.licence_validator import LicenseValidator from ..utils.licence_validator import LicenseValidator
from ..utils.player_search import get_player_name_from_csv from ..utils.player_search import get_player_name_from_csv
from tournaments.models import PlayerRegistration from tournaments.models import PlayerRegistration
from ..utils.extensions import is_not_sqlite_backend
class TournamentRegistrationService: class TournamentRegistrationService:
def __init__(self, request, tournament): def __init__(self, request, tournament):
@ -99,6 +100,7 @@ class TournamentRegistrationService:
self.context['team_form'].cleaned_data self.context['team_form'].cleaned_data
) )
if is_not_sqlite_backend():
self.email_service.send_registration_confirmation( self.email_service.send_registration_confirmation(
self.request, self.request,
self.tournament, self.tournament,

@ -15,6 +15,8 @@ from tournaments.models import PlayerDataSource
from shared.discord import send_discord_log_message, send_discord_failed_calls_message from shared.discord import send_discord_log_message, send_discord_failed_calls_message
from datetime import datetime from datetime import datetime
from .utils.extensions import is_not_sqlite_backend
def generate_unique_code(): def generate_unique_code():
characters = string.ascii_lowercase + string.digits characters = string.ascii_lowercase + string.digits
while True: while True:
@ -64,6 +66,7 @@ def notify_team(team, tournament, message_type):
if tournament.supposedly_in_progress(): if tournament.supposedly_in_progress():
return return
if is_not_sqlite_backend():
TournamentEmailService.notify_team(team, tournament, message_type) TournamentEmailService.notify_team(team, tournament, message_type)
@receiver(pre_delete, sender=TeamRegistration) @receiver(pre_delete, sender=TeamRegistration)

@ -1,4 +1,5 @@
import uuid import uuid
from django.conf import settings
def format_seconds(seconds): def format_seconds(seconds):
hours = int(seconds / 3600) hours = int(seconds / 3600)
@ -14,3 +15,7 @@ def plural_format(label, count):
def create_random_filename(base_name, extension): def create_random_filename(base_name, extension):
random_string = str(uuid.uuid4()) random_string = str(uuid.uuid4())
return f"{base_name}_{random_string}.{extension}" return f"{base_name}_{random_string}.{extension}"
def is_not_sqlite_backend():
default_db_engine = settings.DATABASES['default']['ENGINE']
return default_db_engine != 'django.db.backends.sqlite3'

@ -833,7 +833,7 @@ def my_tournaments(request):
def filter_user_tournaments(tournaments): def filter_user_tournaments(tournaments):
return [t for t in tournaments if t.team_registrations.filter( return [t for t in tournaments if t.team_registrations.filter(
playerregistration__licence_id__icontains=stripped_license, player_registrations__licence_id__icontains=stripped_license,
walk_out=False walk_out=False
).exists()] ).exists()]

Loading…
Cancel
Save