def add_scratches(request, judge_id, number_scratches): try: judge_id, number_scratches = int(judge_id), int(number_scratches) except ValueError: return render_to_response('error.html', { 'error_type': "Scratch", 'error_name': "Data Entry", 'error_info': "Value must be an integer!" }, context_instance=RequestContext(request)) try: judge = Judge.objects.get(pk=judge_id) except Judge.DoesNotExist: return render_to_response('error.html', { 'error_type': "Add Scratches for Judge", 'error_name': str(judge_id), 'error_info': "No such Judge" }, context_instance=RequestContext(request)) if request.method == 'POST': forms = [ ScratchForm(request.POST, prefix=str(i)) for i in range(1, number_scratches + 1) ] all_good = True for form in forms: all_good = all_good and form.is_valid() if all_good: for form in forms: form.save() return render_to_response('thanks.html', { 'data_type': "Scratches for Judge", 'data_name': "[" + str(judge_id) + "]", 'data_modification': "CREATED" }, context_instance=RequestContext(request)) else: forms = [ ScratchForm(prefix=str(i), initial={ 'judge': judge_id, 'scratch_type': 0 }) for i in range(1, number_scratches + 1) ] return render_to_response( 'data_entry_multiple.html', { 'forms': zip(forms, [None] * len(forms)), 'data_type': 'Scratch', 'title': "Adding Scratch(es) for %s" % (judge.name) }, context_instance=RequestContext(request))
def view_scratches(request, judge_id): try: judge_id = int(judge_id) except ValueError: return render_to_response('error.html', { 'error_type': "Scratch", 'error_name': "Delete", 'error_info': "Value must be an integer!" }, context_instance=RequestContext(request)) scratches = Scratch.objects.filter(judge=judge_id) judge = Judge.objects.get(pk=judge_id) number_scratches = len(scratches) if request.method == 'POST': forms = [ ScratchForm(request.POST, prefix=str(i), instance=scratches[i - 1]) for i in range(1, number_scratches + 1) ] all_good = True for form in forms: all_good = all_good and form.is_valid() if all_good: for form in forms: form.save() return render_to_response('thanks.html', { 'data_type': "Scratches for judge", 'data_name': "[" + str(judge_id) + "]", 'data_modification': "EDITED" }, context_instance=RequestContext(request)) else: forms = [ ScratchForm(prefix=str(i), instance=scratches[i - 1]) for i in range(1, len(scratches) + 1) ] delete_links = [ "/judge/" + str(judge_id) + "/scratches/delete/" + str(scratches[i].id) for i in range(len(scratches)) ] links = [('/judge/' + str(judge_id) + '/scratches/add/1/', 'Add Scratch', False)] return render_to_response( 'data_entry_multiple.html', { 'forms': zip(forms, delete_links), 'data_type': 'Scratch', 'links': links, 'title': "Viewing Scratch Information for %s" % (judge.name) }, context_instance=RequestContext(request))
def add_scratch(request): if request.method == 'POST': form = ScratchForm(request.POST) if (form.is_valid()): form.save() judge = form.cleaned_data['judge'].name team = form.cleaned_data['team'].name return render_to_response('thanks.html', {'data_type': "Scratch", 'data_name': " from {0} on {1}".format(team,judge), 'data_modification': "CREATED", 'enter_again': True}, context_instance=RequestContext(request)) else: form = ScratchForm(initial={'scratch_type':0}) return render_to_response('data_entry.html', {'title':"Adding Scratch", 'form': form}, context_instance=RequestContext(request))
def add_scratch(request): if request.method == 'POST': form = ScratchForm(request.POST) if (form.is_valid()): form.save() judge = form.cleaned_data['judge'].name team = form.cleaned_data['team'].name return render_to_response( 'thanks.html', { 'data_type': "Scratch", 'data_name': " from {0} on {1}".format(team, judge), 'data_modification': "CREATED", 'enter_again': True }, context_instance=RequestContext(request)) else: form = ScratchForm(initial={'scratch_type': 0}) return render_to_response('data_entry.html', { 'title': "Adding Scratch", 'form': form }, context_instance=RequestContext(request))