smoll fix to new game logic

This commit is contained in:
root 2019-08-31 17:54:46 +02:00
parent eebd6a5ed6
commit 28e94893c5

View File

@ -39,16 +39,19 @@ class HomePageView(TemplateView):
if user.is_authenticated: if user.is_authenticated:
if user.api_key: if user.api_key:
context['has_api_key'] = True context['has_api_key'] = True
game = Game.objects.filter(user=user, active=True) try:
if game and game.exists(): game = Game.objects.filter(user=user, active=True)
game = game.first() if game and game.exists():
if not GameRound.objects.get(game=game, order=4).guess_lat: game = game.first()
context['existing_game'] = game if not GameRound.objects.get(game=game, order=4).guess_lat:
rounds = GameRound.objects.filter(game=game).order_by('order') context['existing_game'] = game
for round in rounds: rounds = GameRound.objects.filter(game=game).order_by('order')
if not round.guess_lat or not round.guess_lng: for round in rounds:
context['existing_round'] = round if not round.guess_lat or not round.guess_lng:
break context['existing_round'] = round
break
except:
pass
else: else:
context['has_api_key'] = False context['has_api_key'] = False
return context return context
@ -79,7 +82,7 @@ class ContributeView(views.LoginRequiredMixin, CreateView):
self.object = form.save(commit=False) self.object = form.save(commit=False)
self.object.user = self.request.user self.object.user = self.request.user
self.object.save() self.object.save()
messages.success(self.request, "Thank you so much for helping the site, you coordinates have been added.") messages.success(self.request, "Your coordinates have been added.")
return redirect(self.get_success_url()) return redirect(self.get_success_url())