def addClub(request): args = {}; # if it's a POST, add the club if request.POST: # get post data form = AddClubForm(request.user, request.POST); # check if form is valid if form.is_valid(): # add the club org = form.save(); # get club creator user = User.objects.get(id=request.user.id); # add club creator to club as admin uto = UserToOrganization(user=user, organization=org, admin=True); uto.save(); # go to directory return redirect('/clubs'); # if form is invalid, return it to the user else: return render(request, 'addClub.html', {'form': form}); # else, show a new addClub form else: args.update(csrf(request)); args['form'] = AddClubForm(request.user); return render(request, 'addClub.html', args);
def joinClub(request): if request.user.is_authenticated() and request.POST and 'join-club-button' in request.POST: organization_id = int(request.POST.get('organization_id','-1')); org = Organization.objects.get(id=organization_id); user = User.objects.get(id=request.user.id); uto = UserToOrganization(user=user, organization=org); uto.save(); return redirect("/clubs/"+str(organization_id)); elif request.user.is_authenticated() and request.POST and 'leave-club-button' in request.POST: organization_id = int(request.POST.get('organization_id','-1')); org = Organization.objects.get(id=organization_id); user = User.objects.get(id=request.user.id); uto = UserToOrganization.objects.get(user=user, organization=org); uto.delete(); return redirect("/clubs/"+str(organization_id));