def view_team(request, team_id): team_id = int(team_id) try: team = Team.objects.get(pk=team_id) stats = [] stats.append(("Wins", tab_logic.tot_wins(team))) stats.append(("Total Speaks", tab_logic.tot_speaks(team))) stats.append(("Govs", tab_logic.num_govs(team))) stats.append(("Opps", tab_logic.num_opps(team))) stats.append(("Opp Wins", tab_logic.opp_strength(team))) stats.append(("Been Pullup", tab_logic.pull_up_count(team))) stats.append(("Hit Pullup", tab_logic.hit_pull_up_count(team))) except Team.DoesNotExist: return render_to_response('error.html', { 'error_type': "View Team", 'error_name': str(team_id), 'error_info': "No such Team" }, context_instance=RequestContext(request)) if request.method == 'POST': form = TeamForm(request.POST, instance=team) if form.is_valid(): try: form.save() except ValueError: return render_to_response('error.html', { 'error_type': "Team", 'error_name': "[" + form.cleaned_data['name'] + "]", 'error_info': "Team name cannot be validated, most likely a non-existent team" }, context_instance=RequestContext( request)) return render_to_response( 'thanks.html', { 'data_type': "Team", 'data_name': "[" + form.cleaned_data['name'] + "]" }, context_instance=RequestContext(request)) else: form = TeamForm(instance=team) links = [('/team/' + str(team_id) + '/scratches/view/', 'Scratches for ' + str(team.name), False), ('/team/' + str(team_id) + '/delete/', 'Delete', True)] for deb in team.debaters.all(): links.append( ('/debater/' + str(deb.id) + '/', "View %s" % deb.name, False)) return render_to_response('data_entry.html', { 'title': "Viewing Team: %s" % (team.name), 'form': form, 'links': links, 'team_obj': team, 'team_stats': stats }, context_instance=RequestContext(request)) return render_to_response('data_entry.html', {'form': form}, context_instance=RequestContext(request))
def view_team(request, team_id): team_id = int(team_id) try: team = Team.objects.get(pk=team_id) stats = [] stats.append(("Wins", tab_logic.tot_wins(team))) stats.append(("Total Speaks", tab_logic.tot_speaks(team))) stats.append(("Govs", tab_logic.num_govs(team))) stats.append(("Opps", tab_logic.num_opps(team))) stats.append(("Opp Wins", tab_logic.opp_strength(team))) stats.append(("Been Pullup", tab_logic.pull_up_count(team))) stats.append(("Hit Pullup", tab_logic.hit_pull_up_count(team))) except Team.DoesNotExist: return render_to_response('error.html', {'error_type': "View Team", 'error_name': str(team_id), 'error_info':"No such Team"}, context_instance=RequestContext(request)) if request.method == 'POST': form = TeamForm(request.POST,instance=team) if form.is_valid(): try: form.save() except ValueError: return render_to_response('error.html', {'error_type': "Team", 'error_name': "["+form.cleaned_data['name']+"]", 'error_info':"Team name cannot be validated, most likely a non-existent team"}, context_instance=RequestContext(request)) return render_to_response('thanks.html', {'data_type': "Team", 'data_name': "["+form.cleaned_data['name']+"]"}, context_instance=RequestContext(request)) else: form = TeamForm(instance=team) links = [('/team/'+str(team_id)+'/scratches/view/','Scratches for '+str(team.name), False), ('/team/'+str(team_id)+'/delete/', 'Delete', True)] for deb in team.debaters.all(): links.append(('/debater/'+str(deb.id)+'/', "View %s" % deb.name, False)) return render_to_response('data_entry.html', {'title':"Viewing Team: %s"%(team.name), 'form': form, 'links': links, 'team_obj':team, 'team_stats':stats}, context_instance=RequestContext(request)) return render_to_response('data_entry.html', {'form': form}, context_instance=RequestContext(request))
def team(request): #create/update team object team = None if Team.objects.filter(user=request.user).exists(): team = Team.objects.get(user=request.user) if request.method == 'POST': form = TeamForm(request.POST, instance=team or None) if form.is_valid(): team = form.save(commit=False) team.user = request.user team.save() return HttpResponseRedirect('/dashboard') if team: form = TeamForm(instance=team) else: form = TeamForm() args = {} args['form'] = form args['team'] = team #args.update(csrf(request)) return render(request, 'templates/showcase/team.html', args)
def register_team(request): context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) team_form = TeamForm(request.POST, request.FILES) if user_form.is_valid(): if team_form.is_valid(): user = user_form.save() # do i need these two lines anymore? Django 1.5, i think, handles this automatically now. password = user.password user.set_password(password) user.save() t = team_form.save(commit=False) t.user = user t.save() registered = True user = authenticate(username=user.username, password=password) login(request, user) return HttpResponseRedirect('/showcase/team/'+str(t.id)+'/') else: print user_form.errors, team_form.errors else: user_form = UserForm() team_form = TeamForm() # Render the template depending on the context. return render_to_response( 'showcase/team_registration.html', {'user_form': user_form, 'team_form':team_form, 'registered': registered}, context)
def register_team(request): context = RequestContext(request) registered = False if request.method == 'POST': user_form = UserForm(data=request.POST) team_form = TeamForm(request.POST, request.FILES) if user_form.is_valid(): if team_form.is_valid(): user = user_form.save() # do i need these two lines anymore? Django 1.5, i think, handles this automatically now. password = user.password user.set_password(password) user.save() t = team_form.save(commit=False) t.user = user t.save() registered = True user = authenticate(username=user.username, password=password) login(request, user) return HttpResponseRedirect('/showcase/team/' + str(t.id) + '/') else: print user_form.errors, team_form.errors else: user_form = UserForm() team_form = TeamForm() # Render the template depending on the context. return render_to_response('showcase/team_registration.html', { 'user_form': user_form, 'team_form': team_form, 'registered': registered }, context)
def edit_team(request, id): team = get_object_or_404(Team, pk=id) subject = get_object_or_404(Subject, team_id=id) if request.method == "POST": form = TeamForm(request.POST, request.FILES, instance=team) second_form = SubjectFormDesc(request.POST, request.FILES, instance=subject) if form.is_valid() and second_form.is_valid(): team = form.save(commit=False) subject = second_form.save(commit=False) subject.name = team.name subject.team_id = team.id subject.save() team.save() messages.success(request, "the " + team.name + " was edited!") return redirect(reverse('get_team', args={team.pk})) else: messages.error(request, 'Please correct the errors below.') else: form = TeamForm(instance=team) second_form = SubjectFormDesc(instance=subject) return render( request, 'form.html', { 'form': form, 'cancelview': 'get_team', 'cancelid': team.id, 'second_form': second_form, 'heading_text': 'You are editing the ' + team.name + ' Team?', 'button_text': 'Save Changes', })
def edit_team(request, tid=None): """ Add a new Group entity or edit an existing one, and a Team entity is saved along with it. """ if not tid: tid = request.REQUEST.get('tid', None) if tid: team = get_object_or_404(Group, pk=tid) else: team = None if request.method == 'POST': form = TeamForm(request.POST, instance=team) if form.is_valid(): form.save() return HttpResponseRedirect('/') else: form = TeamForm(instance=team) return render(request, 'team_edit', {'form':form, 'team':team}, 'staff/')
def new_team(request): if request.method == "POST": team_form = TeamForm(request.POST) subject_form_desc = SubjectFormDesc(request.POST) if team_form.is_valid() and subject_form_desc.is_valid(): team = team_form.save(commit=False) subject = subject_form_desc.save(commit=False) subject.name = team.name team.save( ) # needs to be here so team.id is created before subject.team_id subject.team_id = team.id subject.save() messages.success(request, "You have added the " + team.name + " Team!") return redirect("get_team", team.id) else: messages.error(request, 'Please correct the errors below.') else: team_form = TeamForm() subject_form_desc = SubjectFormDesc() '''delete this when im sure form.html working return render(request, 'team_subject_form.html', {'team_form': team_form, 'cancelview': 'profile', 'subject_form_desc': subject_form_desc, 'heading_text': 'You are creating a new Team!', 'button_text': 'Save Team', })''' return render( request, 'form.html', { 'form': team_form, 'second_form': subject_form_desc, 'cancelview': 'profile', 'heading_text': 'You are creating a new Team!', 'button_text': 'Save Team', })
def create(request): if request.POST: form = TeamForm(request.POST) if form.is_valid(): team = form.save() user = request.user assign_perm('view_team', user, team) return HttpResponseRedirect('/team/all') else: form = TeamForm() args = {} args.update(csrf(request)) #form.fields['tournament'] = Tournament.objects.all() args['form'] = form args['form'].fields['tournament']= get_objects_for_user(request.user , 'tournament_creator.view_tournament') args['tournament'] = Tournament.objects.all() return render_to_response('create_team.html', args)