def submit(request, game_type): game = get_object_or_404(Game, slug=game_type) ParticipantFormSet = formset_factory(ParticipantForm, formset=RequiredFormSet, max_num=game.players_per_side, extra=game.players_per_side) if request.method == 'POST': form = SubmitForm(request.POST) formset = ParticipantFormSet(request.POST) if form.is_valid() and formset.is_valid(): # Get all the uids given uid_set = set([ u.id for u in chain.from_iterable([ d.cleaned_data.values() for d in [f for f in formset.forms] ]) ]) if len(uid_set) != game.players_per_side * 2: # FIXME This may not be the right way to handle this, but at least # it doesn't try to save something wrong. raise forms.ValidationError("Cannot repeat participants.") match = form.save(request, game) [f.save(match) for f in formset.forms] compute_rankings_for_match(match) return HttpResponseRedirect(game.get_absolute_url()) else: form = SubmitForm() formset = ParticipantFormSet() return render(request, 'match/submit.html', { 'form': form, 'formset': formset })
def submit(request): if request.method != 'POST': raise Http404("use POST") form = SubmitForm(request.POST, request.FILES) if not form.is_valid(): return HttpResponseBadRequest(form.errors.as_json()) data = form.cleaned_data submit_mapping(data['file']) return HttpResponse(_("import is successful").capitalize())
def submit(request): if request.method == 'POST': form = SubmitForm(request.POST) if form.is_valid(): form.save(request) return HttpResponseRedirect('/') else: form = SubmitForm() return direct_to_template(request, 'submit.html', {'form': form})
def submit(request): if request.method == 'POST': form = SubmitForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/thanks') else: form = SubmitForm(initial={'submitter': request.user.id}) return render_to_response('submit.html', {'form': form}, context_instance=RequestContext(request))
def edit(request, strike_id): strike = get_object_or_404(Strike, pk=strike_id) if request.method == 'POST': form = SubmitForm(request.POST, instance=strike) if form.is_valid(): form.save() return HttpResponseRedirect('/submissions') else: form = SubmitForm(instance=strike) return render_to_response('submit.html', {'form': form}, context_instance=RequestContext(request))
def streaming_intro(request): """Renders the home page.""" assert isinstance(request, HttpRequest) clicked = "Not Submitted" if request.method == "POST": form = SubmitForm(request.POST) if form.is_valid(): clicked = "Submitted" # post = form.save(commit=False) print clicked r = subprocess.call("python ./app/util/load_random.py", shell=True) print r # return redirect('/streaming_intro') return render(request, 'app/streaming_intro.html', { 'title': 'Streaming', 'clicked': clicked, 'form': SubmitForm })