Exemplo n.º 1
0
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
    })
Exemplo n.º 2
0
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())
Exemplo n.º 3
0
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})
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
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))
Exemplo n.º 6
0
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
    })