Example #1
0
def edit_team(request, team_id):
    team = Team.objects.get(id=team_id)
    if not request.user.profile.can_edit_team(team):
        messages.add_message(
            request,
            messages.WARNING,
            message=_('You can not make changes to this team.'))
        return redirect('show-team', team_id=team.pk)

    if request.method == 'GET':
        form = TeamForm(instance=team)

        context = {
            'team': team,
            'team_form': form,
        }
        return render(request, 'get_together/teams/edit_team.html', context)
    elif request.method == 'POST':
        form = TeamForm(request.POST, instance=team)
        if form.is_valid:
            new_team = form.save()
            new_team.owner_profile = request.user.profile
            new_team.save()
            return redirect('show-team', team_id=new_team.pk)
        else:
            context = {
                'team': team,
                'team_form': form,
            }
            return render(request, 'get_together/teams/edit_team.html',
                          context)
    else:
        return redirect('home')
Example #2
0
def edit_team(request, team_id):
    team = get_object_or_404(Team, id=team_id)
    if not request.user.profile.can_edit_team(team):
        messages.add_message(
            request,
            messages.WARNING,
            message=_("You can not make changes to this team."),
        )
        return redirect("show-team-by-slug", team_slug=team.slug)

    if request.method == "GET":
        form = TeamForm(instance=team)

        context = {"team": team, "team_form": form}
        return render(request, "get_together/teams/edit_team.html", context)
    elif request.method == "POST":
        form = TeamForm(request.POST, request.FILES, instance=team)
        if form.is_valid():
            new_team = form.save()
            new_team.owner_profile = request.user.profile
            new_team.save()
            return redirect("show-team-by-slug", team_slug=new_team.slug)
        else:
            context = {"team": team, "team_form": form}
            return render(request, "get_together/teams/edit_team.html",
                          context)
    else:
        return redirect("home")
Example #3
0
def team_edit(request, year, event_pk, team_pk):
    fair = get_object_or_404(Fair, year=year)
    event = get_object_or_404(Event, pk=event_pk)
    team = get_object_or_404(Team, pk=team_pk)

    form = TeamForm(request.POST or None, instance=team)

    if request.POST and form.is_valid():
        form.save()
        return redirect('events:event_edit', fair.year, event.id)

    return render(request, 'events/team_edit.html', {
        'fair': fair,
        'team': team,
        'form': form
    })
Example #4
0
class TeamView(TemplateView):
    template_name = 'team.html'
    permission_classes = (IsAuthenticated, )

    def get_context_data(self, **kwargs):
        return {'form': self.form, 'title': self.title}

    def get(self, request, *args, **kwargs):
        self.user = User.objects.get(username=request.user.username)
        self.form = TeamForm()
        self.title = 'Create a team'
        if 'team' in request.GET:
            self.title = 'Edit team'
            team = Team.objects.get(nickname=request.GET['team'])
            if team and self.user in [team.first_member, team.second_member]:
                self.form = TeamForm(instance=team)
            else:
                raise Http404('Team not found!')
        return super().get(request, *args, **kwargs)

    def post(self, request, *args, **kwargs):
        self.user = User.objects.get(username=request.user.username)
        if 'team' in request.GET:
            team = Team.objects.get(nickname=request.GET['team'])
            if team and self.user in [team.first_member, team.second_member]:
                self.team = team
                self.form = TeamForm(request.POST, instance=self.team)
        else:
            self.form = TeamForm(request.POST)
        if self.form.is_valid():
            self.form.save()
        else:
            return self.render_to_response(self.form.errors)
        self.title = '%s // Team' % self.form.instance.nickname
        context = self.get_context_data(**kwargs)
        return self.render_to_response(context)
Example #5
0
def team_new(request, year, event_pk):
    fair = get_object_or_404(Fair, year=year)
    event = get_object_or_404(Event, pk=event_pk)

    form = TeamForm(request.POST or None,
                    initial={'max_capacity': event.teams_default_max_capacity})

    if request.POST and form.is_valid():
        # We want to add the event_id here before saving the team
        new_team = form.save(commit=False)
        new_team.event = event
        new_team.save()
        return redirect('events:event_edit', fair.year, event.id)

    return render(request, 'events/team_edit.html', {
        'fair': fair,
        'form': form
    })