コード例 #1
0
ファイル: views.py プロジェクト: noobiept-other/forum
def edit_category(request, categorySlug):

    try:
        category = Category.objects.get(slug=categorySlug)

    except Category.DoesNotExist:
        raise Http404("Category doesn't exist.")

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():
            categoryName = form.cleaned_data['category']

            category.name = categoryName
            utilities.unique_slugify(category, categoryName)
            category.save()

            return HttpResponseRedirect(reverse('index'))

    else:
        form = CategoryForm(initial={'category': category.name})

    context = {'form': form, 'category': category}

    return render(request, 'edit/edit_category.html', context)
コード例 #2
0
ファイル: viewsAdmin.py プロジェクト: milenafarf/forum
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
ファイル: viewsAdmin.py プロジェクト: milenafarf/forum
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 プロジェクト: 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"})))
コード例 #7
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/')
コード例 #8
0
ファイル: views.py プロジェクト: noobiept-other/forum
def new_category(request):

    if request.method == 'POST':
        form = CategoryForm(request.POST)

        if form.is_valid():

            categoryName = form.cleaned_data['category']
            category = Category(name=categoryName, slug='')
            utilities.unique_slugify(category, categoryName)
            category.save()

            return HttpResponseRedirect(reverse('index'))

    else:
        form = CategoryForm()

    context = {'form': form}

    return render(request, 'new/new_category.html', context)
コード例 #9
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"
        })))
コード例 #10
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"
        })))