Ejemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     form = self.form_class(request.POST,
                            request.FILES,
                            pk=self.context['team'].id)
     self.context['form'] = form
     print(form.is_valid())
     if form.is_valid():
         print(form.cleaned_data)
         print(form.cleaned_data['players'])
         team = self.context['team']
         team.logoUri = form.cleaned_data.get('logoUri', '') or team.logoUri
         team.name = form.cleaned_data.get('name')
         team.club_state = form.cleaned_data.get('club_state')
         team.players.clear()
         player_ids = form.cleaned_data['players']
         players = [
             player for player in Player.objects.filter(pk__in=player_ids)
         ]
         team.players.add(*players)
         team.save()
         messages.success(self.request,
                          'Team has been updated successfully.')
         return HttpResponseRedirect(reverse('team-list'))
     else:
         error = Util.form_validation_error(request, form)
         print(error)
         self.context['error'] = error
     return render(request, self.template_name, self.context)
Ejemplo n.º 2
0
 def post(self, request, *args, **kwargs):
     self.context.clear()
     form = self.form_class(request.POST)
     self.context['form'] = form
     if form.is_valid():
         user = authenticate(request=request,
                             email=request.POST['email'],
                             password=request.POST['password'])
         if user:
             login(request, user)
             return redirect('dashboard')
         else:
             messages.error(request, 'Incorrect Email or Password')
     else:
         error = Util.form_validation_error(request, form)
         self.context['error'] = error
     return render(request, self.template_name, self.context)
Ejemplo n.º 3
0
 def post(self, request, *args, **kwargs):
     self.context.clear()
     form = self.form_class(request.POST, request.FILES)
     self.context['form'] = form
     if form.is_valid():
         print(form.cleaned_data)
         self.reset_fixture()
         fixture, isCreated = Fixture.objects.get_or_create(
             name=form.cleaned_data.get('name', ''))
         teams = Team.objects.filter(pk__in=form.cleaned_data['teams'])
         self.create_fixture(isCreated, fixture, teams)
         self.create_player_history(fixture)
         messages.success(self.request,
                          'Fixture has been created successfully.')
         return HttpResponseRedirect(reverse('fixture-list'))
     else:
         error = Util.form_validation_error(request, form)
         self.context['error'] = error
     return render(request, self.template_name, self.context)
Ejemplo n.º 4
0
 def post(self, request, *args, **kwargs):
     self.context.clear()
     form = self.form_class(request.POST, request.FILES)
     self.context['form'] = form
     if form.is_valid():
         print(form.cleaned_data)
         Player.objects.create(
             first_name=form.cleaned_data.get('first_name', ''),
             last_name=form.cleaned_data.get('last_name', ''),
             image_uri=form.cleaned_data.get('image_uri', ''),
             jersey_number=form.cleaned_data.get('jersey_number', 0),
             country=form.cleaned_data.get('country'))
         messages.success(self.request,
                          'Player has been created successfully.')
         return HttpResponseRedirect(reverse('player-list'))
     else:
         error = Util.form_validation_error(request, form)
         self.context['error'] = error
     return render(request, self.template_name, self.context)
Ejemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     form = self.form_class(request.POST,
                            request.FILES,
                            pk=self.context['player_history'].id)
     self.context['form'] = form
     print(form.is_valid())
     if form.is_valid():
         player_history = self.context['player_history']
         player_history.run = form.cleaned_data.get('run')
         player_history.save()
         messages.success(self.request,
                          'Player run has been updated successfully.')
         return HttpResponseRedirect(
             reverse('fixture-edit', kwargs={'pk':
                                             player_history.match.id}))
     else:
         error = Util.form_validation_error(request, form)
         print(error)
         self.context['error'] = error
     return render(request, self.template_name, self.context)
Ejemplo n.º 6
0
 def post(self, request, *args, **kwargs):
     form = self.form_class(request.POST,
                            request.FILES,
                            pk=self.context['player'].id)
     self.context['form'] = form
     if form.is_valid():
         print(form.cleaned_data)
         player = self.context['player']
         player.image_uri = form.cleaned_data.get('image_uri',
                                                  '') or player.image_uri
         player.first_name = form.cleaned_data.get('first_name')
         player.last_name = form.cleaned_data.get('last_name')
         player.jersey_number = form.cleaned_data.get('jersey_number')
         player.country = form.cleaned_data.get('country')
         player.save()
         messages.success(self.request,
                          'Player has been updated successfully.')
         return HttpResponseRedirect(reverse('player-list'))
     else:
         error = Util.form_validation_error(request, form)
         self.context['error'] = error
     return render(request, self.template_name, self.context)
Ejemplo n.º 7
0
 def post(self, request, *args, **kwargs):
     form = self.form_class(request.POST,
                            request.FILES,
                            pk=self.context['match'].id)
     self.context['form'] = form
     print(form.is_valid())
     if form.is_valid():
         match = self.context['match']
         match.winner = Team.objects.get(pk=form.cleaned_data.get('winner'))
         match.save()
         point_team1 = self.context['point_team1']
         point_team2 = self.context['point_team2']
         point_team1.score = form.cleaned_data.get('score_team1')
         point_team2.score = form.cleaned_data.get('score_team2')
         point_team1.save()
         point_team2.save()
         messages.success(self.request,
                          'Match has been updated successfully.')
         return HttpResponseRedirect(reverse('fixture-list'))
     else:
         error = Util.form_validation_error(request, form)
         print(error)
         self.context['error'] = error
     return render(request, self.template_name, self.context)