Esempio n. 1
0
def new(request):
    # If coach
    c = {}
    c.update(csrf(request))
    if request.method == 'POST': # If the form has been submitted...
        form = TeamForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data
            team = form.save()
            messages.add_message(request, messages.SUCCESS, 'Team created!')
            return HttpResponseRedirect(reverse('team_details', args=(team.id,)))
    else:
        form = TeamForm() # An unbound form

    return render_to_response("teams/new.html", {'form': form, 'c':c},
                               context_instance=RequestContext(request))
Esempio n. 2
0
def edit(request, team_id):
    team = get_object_or_404(Team, pk=team_id)
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':  # If the form has been submitted...
        if request.POST.get('delete'):
            team.delete()
            messages.add_message(request, messages.SUCCESS, 'Team Deleted!')
            return HttpResponseRedirect(reverse('teams'))
        form = TeamForm(request.POST,
                        instance=team)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            form.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Team info updated!')
            return HttpResponseRedirect(
                reverse('team_details', args=(team.id, )))
    else:
        form = TeamForm(instance=team)  # An unbound form

    # pass action with the id, probably need a cleaner way of doing this
    return render_to_response("teams/edit.html", {
        'team': team,
        'form': form,
        'c': c
    },
                              context_instance=RequestContext(request))
Esempio n. 3
0
def create_and_join(request):
    """Create a new team and join it, should happen right after user reg"""
    c = {}
    c.update(csrf(request))
    if request.method == 'POST': # If the form has been submitted...
        form = TeamForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            team = form.save()
            member = request.user.member
            member.team = team
            member.save()
            messages.add_message(request, messages.SUCCESS, 'Team info created!')
            return HttpResponseRedirect(reverse('team_details', args=(team.id,)))
    else:
        form = TeamForm() # An unbound form

    return render_to_response("teams/create_and_join.html", {'form': form, 'c':c},
                               context_instance=RequestContext(request))
Esempio n. 4
0
def edit(request, team_id):
    team = get_object_or_404(Team, pk=team_id)
    c = {}
    c.update(csrf(request))
    if request.method == 'POST': # If the form has been submitted...
        if request.POST.get('delete'):
            team.delete()
            messages.add_message(request, messages.SUCCESS, 'Team Deleted!')
            return HttpResponseRedirect(reverse('teams'))
        form = TeamForm(request.POST, instance=team) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            form.save()
            messages.add_message(request, messages.SUCCESS, 'Team info updated!')
            return HttpResponseRedirect(reverse('team_details', args=(team.id,)))
    else:
        form = TeamForm(instance=team) # An unbound form

    # pass action with the id, probably need a cleaner way of doing this
    return render_to_response("teams/edit.html", {'team': team, 'form': form, 'c':c},
                               context_instance=RequestContext(request))
Esempio n. 5
0
def new(request):
    # If coach
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':  # If the form has been submitted...
        form = TeamForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            team = form.save()
            messages.add_message(request, messages.SUCCESS, 'Team created!')
            return HttpResponseRedirect(
                reverse('team_details', args=(team.id, )))
    else:
        form = TeamForm()  # An unbound form

    return render_to_response("teams/new.html", {
        'form': form,
        'c': c
    },
                              context_instance=RequestContext(request))
Esempio n. 6
0
def create_and_join(request):
    """Create a new team and join it, should happen right after user reg"""
    c = {}
    c.update(csrf(request))
    if request.method == 'POST':  # If the form has been submitted...
        form = TeamForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            team = form.save()
            member = request.user.member
            member.team = team
            member.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Team info created!')
            return HttpResponseRedirect(
                reverse('team_details', args=(team.id, )))
    else:
        form = TeamForm()  # An unbound form

    return render_to_response("teams/create_and_join.html", {
        'form': form,
        'c': c
    },
                              context_instance=RequestContext(request))