def tournament_registration(request, tournament_id): """ csrf validation didn't work on the mobile safari, not sure why. Let's disable it for now, because it is not really important action """ tournament = get_object_or_404(Tournament, id=tournament_id) if tournament.is_online(): form = OnlineTournamentRegistrationForm( request.POST, initial={"tournament": tournament}) else: form = TournamentRegistrationForm(request.POST, initial={"tournament": tournament}) if form.is_valid(): if tournament.is_online(): tenhou_nickname = form.cleaned_data.get("tenhou_nickname") exists = OnlineTournamentRegistration.objects.filter( tournament=tournament, tenhou_nickname=tenhou_nickname).exists() if exists: messages.success( request, _("You already registered to the tournament!")) return redirect(tournament.get_url()) instance = form.save(commit=False) instance.tournament = tournament # it supports auto load objects only for Russian tournaments right now try: instance.player = Player.objects.get( first_name_ru=instance.first_name.title(), last_name_ru=instance.last_name.title()) except (Player.DoesNotExist, Player.MultipleObjectsReturned): # TODO if multiple players are here, let's try to filter by city pass try: instance.city_object = City.objects.get(name_ru=instance.city) except City.DoesNotExist: pass if tournament.registrations_pre_moderation: instance.is_approved = False message = _( "Your registration was accepted! It will be visible on the page after administrator approvement." ) else: instance.is_approved = True message = _("Your registration was accepted!") instance.save() messages.success(request, message) else: messages.success(request, _("Please, allow to store personal data")) return redirect(tournament.get_url())
def tournament_announcement(request, slug): tournament = get_object_or_404(Tournament, slug=slug) initial = {'tournament': tournament} if tournament.city and tournament.fill_city_in_registration: initial['city'] = tournament.city.name_ru if tournament.is_online(): form = OnlineTournamentRegistrationForm() else: form = TournamentRegistrationForm(initial=initial) if tournament.is_online(): registration_results = (OnlineTournamentRegistration.objects.filter( tournament=tournament).filter( is_approved=True).prefetch_related('player').prefetch_related( 'city_object').order_by('created_on')) else: registration_results = (TournamentRegistration.objects.filter( tournament=tournament).filter( is_approved=True).prefetch_related('player').prefetch_related( 'city_object').order_by('created_on')) return render( request, 'tournament/announcement.html', { 'tournament': tournament, 'page': 'tournament', 'form': form, 'registration_results': registration_results })
def tournament_announcement(request, slug): tournament = get_object_or_404(Tournament, slug=slug) initial = {"tournament": tournament} if tournament.city and tournament.fill_city_in_registration: initial["city"] = tournament.city.name_ru if tournament.is_online(): form = OnlineTournamentRegistrationForm(initial=initial) else: form = TournamentRegistrationForm(initial=initial) if tournament.is_online(): registration_results = (OnlineTournamentRegistration.objects.filter( tournament=tournament).filter( is_approved=True).prefetch_related("player").prefetch_related( "city_object").order_by("created_on")) if tournament.display_notes: registration_results = registration_results.order_by( "notes", "created_on") else: registration_results = (TournamentRegistration.objects.filter( tournament=tournament).filter( is_approved=True).prefetch_related("player").prefetch_related( "city_object").order_by("created_on")) if tournament.display_notes: registration_results = registration_results.order_by( "notes", "created_on") return render( request, "tournament/announcement.html", { "tournament": tournament, "page": "tournament", "form": form, "registration_results": registration_results }, )