示例#1
0
def ajax_hackathon_edit(request,slug):
    hackathon = get_object_or_404(Hackathon,slug=slug)
    if request.method == "POST":
        form = HackathonForm(request.POST,request.FILES,instance=hackathon)
        if form.is_valid():
            form.save()
            return HttpResponse(json.dumps({"success":True}))
    return HttpResponse(json.dumps({"success":False}))
示例#2
0
def hackathon_create(request,slug=None):
    instance = None
    if slug:
        instance = get_object_or_404(Hackathon,slug=slug)
    form = HackathonForm(instance=instance)
    if request.method == "POST":
        form = HackathonForm(request.POST,request.FILES,instance=instance)
        form.initial = request.POST
        if form.is_valid():
            form.save()
            hackathon = form.instance
            hackathon.admin.add(request.user) #add the current user to the admin
            hackathon.save()

            return HttpResponseRedirect(form.instance.get_absolute_url())
    context = {
        "form": form
    }
    if instance:
        context['hackathon'] = instance
    return render_to_response("hackathons/hackathon_create.html",context,context_instance=RequestContext(request))