Ejemplo n.º 1
0
Archivo: views.py Proyecto: Barro/PMS
def admin(request, compo):
    if not request.user.has_perm("compo.admin"):
        return HttpResponseNotFound()

    try:
        try:
            compo = Competition.objects.get(slug=compo, party=get_party(request))
            compo.entries = compo.get_entries()
            if request.GET.get("hidden", False):
                compo.show_hidden = True
        except Competition.DoesNotExist:
            return HttpResponseNotFound()

        if request.method == "POST":
            form = CompoAdminForm(request.POST, instance=compo)
            if form.is_valid():
                compo = form.save()
                messages.add_message(request, messages.SUCCESS, "Compo settings updated")
            else:
                messages.add_message(request, messages.ERROR, "Settings invalid")
        else:
            form = CompoAdminForm(instance=compo)

        return render_to_response(
            "compo_admin.html", dict(form=form, compo=compo), context_instance=RequestContext(request)
        )

    except InvalidCompetition:
        messages.add_message(request, messages.ERROR, "Invalid competition")
        return HttpResponseRedirect(reverse("compo.views.index", args=[request.party]))
Ejemplo n.º 2
0
Archivo: views.py Proyecto: Barro/PMS
def admin_create_compo(request):
    if not request.user.has_perm("compo.admin"):
        return HttpResponseNotFound()

    if request.method == "POST":
        form = CompoAdminForm(request.POST)
        if form.is_valid():
            c = form.save()
            messages.add_message(request, messages.SUCCESS, "Compo %s created" % c.name)
            form = CompoAdminForm()
    else:
        form = CompoAdminForm()

    return render_to_response("compo_admin_create.html", {"form": form}, context_instance=RequestContext(request))