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)
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_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_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)
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" })))