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/')
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}))
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"})))
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" })))
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"})))
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" })))