made challenge name a required field
This commit is contained in:
parent
777694378f
commit
abc842092a
23
geogame/main/migrations/0005_auto_20200117_0023.py
Normal file
23
geogame/main/migrations/0005_auto_20200117_0023.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 2.2.4 on 2020-01-17 00:23
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0004_auto_20191125_2344'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='challenge',
|
||||||
|
name='average',
|
||||||
|
field=models.PositiveIntegerField(default=0),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='challenge',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(db_index=True, max_length=255, verbose_name='Challenge Name'),
|
||||||
|
),
|
||||||
|
]
|
@ -51,7 +51,7 @@ class User(AbstractUser):
|
|||||||
|
|
||||||
|
|
||||||
class Challenge(models.Model):
|
class Challenge(models.Model):
|
||||||
name = models.CharField(_('Challenge Name'), max_length=255, blank=True, db_index=True)
|
name = models.CharField(_('Challenge Name'), max_length=255, blank=False, db_index=True)
|
||||||
average = models.PositiveIntegerField(default=0)
|
average = models.PositiveIntegerField(default=0)
|
||||||
user = models.ForeignKey(User, models.PROTECT,
|
user = models.ForeignKey(User, models.PROTECT,
|
||||||
related_name='challenge_user',
|
related_name='challenge_user',
|
||||||
@ -133,4 +133,4 @@ class GameRound(models.Model):
|
|||||||
actual_coord = (self.coord.lat, self.coord.lng,)
|
actual_coord = (self.coord.lat, self.coord.lng,)
|
||||||
guess_coord = (self.guess_lat, self.guess_lng,)
|
guess_coord = (self.guess_lat, self.guess_lng,)
|
||||||
self.result = distance.distance(actual_coord, guess_coord).km * 1000
|
self.result = distance.distance(actual_coord, guess_coord).km * 1000
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
@ -198,15 +198,22 @@ class RoundView(views.UserPassesTestMixin, UpdateView):
|
|||||||
round_id = self.kwargs.get('round_pk', 0)
|
round_id = self.kwargs.get('round_pk', 0)
|
||||||
return get_object_or_404(GameRound, pk=round_id)
|
return get_object_or_404(GameRound, pk=round_id)
|
||||||
|
|
||||||
|
def get(self, *args, **kwargs):
|
||||||
|
round_id = self.kwargs.get('round_pk', 0)
|
||||||
|
round = get_object_or_404(GameRound, pk=round_id)
|
||||||
|
|
||||||
|
if round.guess_lat:
|
||||||
|
# user has already played this round, so something has gone wrong
|
||||||
|
messages.warning(self.request, 'You have already played this round, something went wrong. Hit "Continue Last Game" to try again.')
|
||||||
|
return redirect(reverse_lazy('home'))
|
||||||
|
|
||||||
|
return super().get(*args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(RoundView, self).get_context_data(**kwargs)
|
context = super(RoundView, self).get_context_data(**kwargs)
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
round_id = self.kwargs.get('round_pk', 0)
|
round_id = self.kwargs.get('round_pk', 0)
|
||||||
round = get_object_or_404(GameRound, pk=round_id)
|
round = get_object_or_404(GameRound, pk=round_id)
|
||||||
if round.guess_lat:
|
|
||||||
#user has already played this round, so something has gone wrong
|
|
||||||
messages.warning(self.request, 'You have already played this round, something went wrong. Hit "Continue Last Game" to try again.')
|
|
||||||
return redirect(reverse_lazy('home'))
|
|
||||||
|
|
||||||
context['api_key'] = user.api_key
|
context['api_key'] = user.api_key
|
||||||
context['lat'] = round.coord.lat
|
context['lat'] = round.coord.lat
|
||||||
|
Loading…
Reference in New Issue
Block a user