Esempio n. 1
0
def create_club(request, template_name="schedule_tests/clubs/new.html"):
    if request.method == 'POST':
        form = ClubForm(request.POST)
        if form.is_valid():
            club = form.save(commit=False)
            club.save()
            calendar = Calendar(name = "%s Calendar" % club.name, slug = unicode(uuid.uuid1()))
            calendar.save()
            CalendarRelation.objects.create_relation(calendar, club, distinction="default", inheritable=True)
            
            return HttpResponseRedirect(reverse('show_club', args=(club.id,)))
        # if invalid, it gets displayed below
    else:
        form = ClubForm()
 
    return render_to_response(template_name, {'form': form,},
                              context_instance=RequestContext(request))
Esempio n. 2
0
def edit_club(request, club_id,
    template_name="schedule_tests/clubs/edit.html"):
    club = get_object_or_404(Club, id = club_id)
 
    if request.method == 'POST':
        form = ClubForm(request.POST, instance = club)
        if form.is_valid():
            # create it
            club = form.save(commit=False)
            club.save()
            
            return HttpResponseRedirect(reverse('show_club', args=(club.id,)))
        # if invalid, it gets displayed below
    else:
        form = ClubForm(instance = club)
 
    return render_to_response(template_name, {
        'form': form,
        'club': club,
    }, context_instance=RequestContext(request))