made challenge name a required field

This commit is contained in:
root 2020-01-17 01:32:28 +01:00
parent 777694378f
commit abc842092a
3 changed files with 36 additions and 6 deletions

View 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'),
),
]

View File

@ -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',

View File

@ -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