Example #1
0
def competition(request, story_id):
    if not request.META.has_key(MXIT_HEADER):
        if not request.user.is_authenticated():
            return HttpResponseRedirect("/account/login/")
        
    story = Story.public.get(id=story_id)
    try:
        competition = Competition.visible.filter(story=story).latest("created")
    except Competition.DoesNotExist:
        raise Http404
    
    form = CompetitionForm()

#    if not request.META.has_key(MXIT_HEADER):
#        del form.fields["name"]
#        del form.fields["number"]
        
    back = None

    try:
        back = request.GET["back"]
    except:
        back = None
        
    if request.method == "POST":
        form = CompetitionForm(request.POST)

#        if not request.META.has_key(MXIT_HEADER):
#            del form.fields["name"]
#            del form.fields["number"]
        
        back = request.POST["back"]

        if form.is_valid():
            entry = CompetitionEntry(
                competition=competition,
                response=request.POST["response"]
            )

            if request.user.is_authenticated():
                entry.user = request.user

            #if request.META.has_key(MXIT_HEADER):
            entry.name = request.POST["name"]
            entry.number = request.POST["number"]
                
            entry.save()

            messages.add_message(request, messages.SUCCESS, "You entered the competition successfully.")

            return HttpResponseRedirect(request.POST["next"])

    return render_to_response("stories/competition.html", {
        "competition": competition,
        "form": form,
        "back": back,
    }, context_instance=RequestContext(request))
Example #2
0
def site_competition(request, competition_id):
    if not request.META.has_key(MXIT_HEADER):
        if not request.user.is_authenticated():
            return HttpResponseRedirect("/account/login/")
    
    try:
        competition = Competition.visible.get(pk=competition_id)
    except Competition.DoesNotExist:
        raise Http404
    
    form = CompetitionForm()
    back = request.GET.get("back")
    
    if request.method == "POST":
        form = CompetitionForm(request.POST)
        back = request.POST.get("back")
        
        if form.is_valid():
            entry = CompetitionEntry(
                competition=competition,
                response=request.POST["response"]
            )
            
            if request.user.is_authenticated():
                entry.user = request.user
            
            entry.name = request.POST["name"]
            entry.number = request.POST["number"]
            entry.save()
            
            messages.add_message(request, messages.SUCCESS, "You entered the competition successfully.")
            
            return HttpResponseRedirect(request.POST["next"])
    
    return render_to_response("stories/site_competition.html", {
        "competition": competition,
        "form": form,
        "back": back,
    }, context_instance=RequestContext(request))