예제 #1
0
def categories(request):
    if 'admin' in request.session:
        try:
            categories = Category.objects.all()
        except Category.DoesNotExist:
            return HttpResponseRedirect('/error/1/')
        if request.method == 'POST':
            # create a form instance and populate it with data from the request:
            form = CategoryForm(request.POST)
            # check whether it's valid:
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/categoriesAdmin/')
        # if a GET (or any other method) we'll create a blank form
        else:
            form = CategoryForm()
        return render(request, 'categoriesAdmin.html', {'form': form})

        # template = loader.get_template('categoriesAdmin.html')
        # context = RequestContext(request, {
        #     'form': form,
        #     'categories': categories,
        # })
        # return HttpResponse(template.render(context))
    else:
        return HttpResponseRedirect('/error/2/')
예제 #2
0
def categories(request):
    if 'admin' in request.session:
        try:
            categories = Category.objects.all()
        except Category.DoesNotExist:
            return HttpResponseRedirect('/error/1/')
        if request.method == 'POST':
            # create a form instance and populate it with data from the request:
            form = CategoryForm(request.POST)
            # check whether it's valid:
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/categoriesAdmin/')
        # if a GET (or any other method) we'll create a blank form
        else:
            form = CategoryForm()
        return render(request, 'categoriesAdmin.html', {'form': form})

        # template = loader.get_template('categoriesAdmin.html')
        # context = RequestContext(request, {
        #     'form': form,
        #     'categories': categories,
        # })
        # return HttpResponse(template.render(context))
    else:
        return HttpResponseRedirect('/error/2/')
예제 #3
0
def editCategory(request, id):
    if 'admin' in request.session:
        cat = Category.objects.get(id=id)
    else:
        return HttpResponseRedirect('/error/2/')
    form = CategoryForm(request.POST or None, instance=cat)
    if form.is_valid():
        form.save()
        return redirect('/categoriesAdmin/')
    else:
        return render_to_response('categoriesAdmin.html', RequestContext(request, {'form': form}))
예제 #4
0
파일: views.py 프로젝트: chinspp/42
def new_cat(request):
    if (request.method == "POST"):
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/forum')
        else:
            error = True
    else:
        form = CategoryForm()
    return (render_to_response("form.html", RequestContext(request, {'form':form, 'title':"Create new category"})))
예제 #5
0
def editCategory(request, id):
    if 'admin' in request.session:
        cat = Category.objects.get(id=id)
    else:
        return HttpResponseRedirect('/error/2/')
    form = CategoryForm(request.POST or None, instance=cat)
    if form.is_valid():
        form.save()
        return redirect('/categoriesAdmin/')
    else:
        return render_to_response('categoriesAdmin.html',
                                  RequestContext(request, {'form': form}))
예제 #6
0
파일: views.py 프로젝트: ryanrdk/42
def new_cat(request):
    if (request.method == "POST"):
        form = CategoryForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/forum')
        else:
            error = True
    else:
        form = CategoryForm()
    return (render_to_response(
        "form.html",
        RequestContext(request, {
            'form': form,
            'title': "Create new category"
        })))
예제 #7
0
파일: views.py 프로젝트: chinspp/42
def new_sub_cat(request, cat):
    if (request.method == "POST"):
        form = CategoryForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.parent = Category.objects.get(title=cat)
            obj.save()
            return HttpResponseRedirect('/forum/cat-'+cat)
        else:
            error = True
    else:
        form = CategoryForm()
    return (render_to_response("form.html", RequestContext(request, {'form':form, 'title':"Create new category"})))
예제 #8
0
파일: views.py 프로젝트: ryanrdk/42
def new_sub_cat(request, cat):
    if (request.method == "POST"):
        form = CategoryForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.parent = Category.objects.get(title=cat)
            obj.save()
            return HttpResponseRedirect('/forum/cat-' + cat)
        else:
            error = True
    else:
        form = CategoryForm()
    return (render_to_response(
        "form.html",
        RequestContext(request, {
            'form': form,
            'title': "Create new category"
        })))