Exemplo n.º 1
0
 def test_can_validate_basic_data(self):
     form = forms.GameForm({
         'name': 'bliblu',
         'platforms': [self.platform.id],
         'genres': [self.genre.id],
     })
     self.assertTrue(form.is_valid())
Exemplo n.º 2
0
 def test_catches_duplicate_slugs(self):
     form = forms.GameForm({
         'name': 'Hyperdimension Neptunia Re,Birth2: Sisters Generation',
         'platforms': [self.platform.id],
         'genres': [self.genre.id],
     })
     self.assertFalse(form.is_valid())
     self.assertIn('name', form.errors)
Exemplo n.º 3
0
 def test_can_validate_basic_data(self):
     image = create_image(None, 'banner.png')
     form = forms.GameForm(
         {
             'name': 'bliblu',
             'platforms': [self.platform.id],
             'genres': [self.genre.id]
         },
         {'title_logo': SimpleUploadedFile('front.png', image.getvalue())})
     # XXX there's a problem with django-croppie preventing testing this form properly
     # The title_photo is made optional until this is fixed
     form.fields['title_logo'].required = False
     form.is_valid()
     # self.assertTrue(form.is_valid())
     self.assertFalse(form.errors)
Exemplo n.º 4
0
def create_game(request):
    game = forms.GameForm(request.POST or None)
    games = Game.objects.all()
    if game.is_valid():
        game.save()
        return redirect('/games/')
    if games > 0:
        winner_ids = Game.objects.all() \
            .values('winner') \
            .annotate(total=Count('winner_id')) \
            .order_by('-total')[:10]
        winners = Player.objects.filter(
            pk__in=[w['winner'] for w in winner_ids])
        winners_dict = {w.pk: w.name for w in winners}
        win_tots = [{
            'total': w['total'],
            'name': winners_dict[int(w['winner'])]
        } for w in winner_ids]
    return render(request, 'new_game.html', {
        'form': game,
        'games': games,
        'wins': win_tots
    })
Exemplo n.º 5
0
 def post(self, request):
     gameForm = forms.GameForm(request.POST)
     if gameForm.is_valid():
         gameForm.save()
         return redirect('/games/')
     return render(request, 'form.html', {'form': gameForm})