def create(request): if request.user.is_superuser: form = PageForm(request.POST or None) if form.is_valid(): form.save() messages.success(request, "Page has been created") return redirect("index") return render(request, "pages/form.html", {"form": form, "update": False}) else: messages.success(request, "You are not authorized") return redirect("index")
def edit_flatpage(request, id): if request.method == 'POST': flatpage = get_object_or_404(FlatPage, id=id) form = PageForm(request.POST, instance=flatpage) if form.is_valid(): form.save(commit=False) flatpage.save() return HttpResponseRedirect(flatpage.url) else: flatpage = get_object_or_404(FlatPage, id=id) form = PageForm(instance=flatpage) return render_to_response('pages/edit_page.html', {'form': form}, context_instance=RequestContext(request))
def edit(request, name): page = get_object_or_404(Page, name=name) if request.method == 'POST': form = PageForm(request.POST or None, instance=page) if form.is_valid(): form.save() return redirect('homepage') else: form = PageForm(instance=page) return render(request, 'pages/edit.html', locals())
def update(request, url): if request.user.is_superuser: page = get_object_or_404(Page, url=url) form = PageForm(request.POST or None, instance=page) if form.is_valid(): form.save() messages.success(request, "Page has been updated") return redirect("pages.controller", url=page.url) return render(request, "pages/form.html", {"form": form, "update": True}) else: messages.success(request, "You are not authorized") return redirect("index")
def new_flatpage(request): if request.method == 'POST': flatpage = FlatPage() form = PageForm(request.POST, instance=flatpage) if form.is_valid(): form.save(commit=False) flatpage.user = request.user flatpage.save() return HttpResponseRedirect(flatpage.url) else: flatpage = FlatPage() form = PageForm(instance=flatpage) return render_to_response('pages/new_page.html', {'form': form}, context_instance=RequestContext(request))
def create(request): if request.user.is_superuser: form = PageForm(request.POST or None) if form.is_valid(): form.save() messages.success(request, 'Page has been created') return redirect('index') return render(request, 'pages/form.html', { 'form': form, 'update': False }) else: messages.success(request, 'You are not authorized') return redirect('index')
def update(request, url): if request.user.is_superuser: page = get_object_or_404(Page, url=url) form = PageForm(request.POST or None, instance=page) if form.is_valid(): form.save() messages.success(request, 'Page has been updated') return redirect('pages.controller', url=page.url) return render(request, 'pages/form.html', { 'form': form, 'update': True }) else: messages.success(request, 'You are not authorized') return redirect('index')
def new_page(request): if request.method == "POST": validate_page = PageForm(request.POST) if validate_page.is_valid(): validate_page.save() data = {"error": False, "response": "Page created successfully"} else: data = {"error": True, "response": validate_page.errors} return HttpResponse(json.dumps(data), content_type="application/json; charset=utf-8") if request.user.is_superuser: c = {} c.update(csrf(request)) return render(request, "admin/content/page/new-page.html", {"csrf_token": c["csrf_token"]}) else: return render_to_response("admin/accessdenied.html")
def new_page(request): if request.method == 'POST': validate_page = PageForm(request.POST) if validate_page.is_valid(): validate_page.save() data = {"error": False, 'response': 'Page created successfully'} else: data = {"error": True, 'response': validate_page.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') if request.user.is_superuser: c = {} c.update(csrf(request)) return render(request, 'admin/content/page/new-page.html', {'csrf_token': c['csrf_token']}) else: return render_to_response('admin/accessdenied.html')
def new_page(request): categories = Category.objects.all() countries = Country.objects.all() if request.method == 'POST': validate_page = PageForm(request.POST) if validate_page.is_valid(): page = validate_page.save(commit=False) page.parent = None page.slug = slugify(request.POST.get('slug')) page.is_default = True if request.POST.get('country'): page.country_id = request.POST.get('country') else: country = Country.objects.get(name__iexact='US') page.country = country page.save() page.category.add(*request.POST.getlist('category')) data = {"error": False, 'response': 'Page created successfully'} else: data = {"error": True, 'response': validate_page.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') if request.user.is_superuser: c = {} c.update(csrf(request)) return render( request, 'admin/content/page/new-page.html', { 'csrf_token': c['csrf_token'], 'categories': categories, 'countries': countries }) else: return render_to_response('admin/accessdenied.html')
def new_page(request): categories = Category.objects.all() if request.method == 'POST': validate_page = PageForm(request.POST) if validate_page.is_valid(): page = validate_page.save(commit = False) page.slug = slugify(request.POST.get('slug')) page.save() page.category.add(*request.POST.getlist('category')) data = {"error": False, 'response': 'Page created successfully'} else: data = {"error": True, 'response': validate_page.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') if request.user.is_superuser: c = {} c.update(csrf(request)) return render( request, 'admin/content/page/new-page.html', { 'csrf_token': c['csrf_token'], 'categories': categories }) else: return render_to_response('admin/accessdenied.html')
def edit_page(request, pk): page = get_object_or_404(Page, pk=pk) categories = Category.objects.all() if request.method == 'POST': validate_page = PageForm(request.POST, instance=page) if validate_page.is_valid(): page = validate_page.save(commit=False) page.slug = slugify(request.POST.get('slug')) page.save() page.category.clear() page.category.add(*request.POST.getlist('category')) data = {"error": False, 'response': 'Page updated successfully'} else: data = {"error": True, 'response': validate_page.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') if request.user.is_superuser: c = {} c.update(csrf(request)) return render(request, 'admin/content/page/edit-page.html', { 'page': page, 'csrf_token': c['csrf_token'], 'categories': categories }) else: return render_to_response('admin/accessdenied.html')
def edit_page(request, pk): page = get_object_or_404(Page, pk=pk) if request.method == "POST": validate_page = PageForm(request.POST, instance=page) if validate_page.is_valid(): validate_page.save() data = {"error": False, "response": "Page updated successfully"} else: data = {"error": True, "response": validate_page.errors} return HttpResponse(json.dumps(data), content_type="application/json; charset=utf-8") if request.user.is_superuser: c = {} c.update(csrf(request)) return render(request, "admin/content/page/edit-page.html", {"page": page, "csrf_token": c["csrf_token"]}) else: return render_to_response("admin/accessdenied.html")
def edit_page(request, pk): if request.method == 'POST': page_instance = Page.objects.get(pk=pk) validate_page = PageForm(request.POST, instance=page_instance) if validate_page.is_valid(): validate_page.save() data = {"error": False, 'response': 'Page updated successfully'} else: data = {"error": True, 'response': validate_page.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') if request.user.is_superuser: c = {} c.update(csrf(request)) current_page = Page.objects.get(pk=pk) return render(request, 'admin/content/page/edit-page.html', {'page': current_page, 'csrf_token': c['csrf_token']}) else: return render_to_response('admin/accessdenied.html')
def edit_page(request, pk): page = get_object_or_404(Page, pk=pk) if request.method == 'POST': validate_page = PageForm(request.POST, instance=page) if validate_page.is_valid(): validate_page.save() data = {"error": False, 'response': 'Page updated successfully'} else: data = {"error": True, 'response': validate_page.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') if request.user.is_superuser: c = {} c.update(csrf(request)) return render(request, 'admin/content/page/edit-page.html', { 'page': page, 'csrf_token': c['csrf_token'] }) else: return render_to_response('admin/accessdenied.html')
def edit_page(request, pk): country = request.GET.get('country') if request.GET.get( 'country') else request.POST.get('country_id') page = Page.objects.filter(pk=pk, country__slug=country).first() if not page: page = Page.objects.filter(parent_id=pk, country__slug=country).first() if not page: page = '' categories = Category.objects.all() countries = Country.objects.all() if request.method == 'POST': print(request.POST) if page: print("hello") validate_page = PageForm(request.POST, instance=page) else: validate_page = PageForm(request.POST) if validate_page.is_valid(): edit_page = validate_page.save(commit=False) edit_page.slug = slugify(request.POST.get('slug')) if request.POST.get('contact_info'): edit_page.contact_info = json.loads( request.POST.get('contact_info')) if request.POST.get('is_default', '') == 'true': edit_page.is_default = True else: edit_page.is_default = False country = Country.objects.filter(slug=country).first() edit_page.country = country edit_page.save() if str(edit_page.id) != str(pk): edit_page.parent_id = pk edit_page.save() edit_page.category.clear() edit_page.category.add(*request.POST.getlist('category')) data = {"error": False, 'response': 'Page updated successfully'} else: data = {"error": True, 'response': validate_page.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') if request.user.is_superuser: c = {} c.update(csrf(request)) return render( request, 'admin/content/page/edit-page.html', { 'page': page, 'csrf_token': c['csrf_token'], 'categories': categories, 'countries': countries }) else: return render_to_response('admin/accessdenied.html')
def edit_page(request, pk): country = request.GET.get('country') if request.GET.get('country') else request.POST.get('country_id') page = Page.objects.filter(pk=pk, country__slug=country).first() if not page: page = Page.objects.filter(parent_id=pk, country__slug=country).first() if not page: page = '' categories = Category.objects.all() countries = Country.objects.all() if request.method == 'POST': print (request.POST) if page: print("hello") validate_page = PageForm(request.POST, instance=page) else: validate_page = PageForm(request.POST) if validate_page.is_valid(): edit_page = validate_page.save(commit=False) edit_page.slug = slugify(request.POST.get('slug')) if request.POST.get('contact_info'): edit_page.contact_info = json.loads(request.POST.get('contact_info')) if request.POST.get('is_default', '') == 'true': edit_page.is_default = True else: edit_page.is_default = False country = Country.objects.filter(slug=country).first() edit_page.country = country edit_page.save() if str(edit_page.id) != str(pk): edit_page.parent_id = pk edit_page.save() edit_page.category.clear() edit_page.category.add(*request.POST.getlist('category')) data = {"error": False, 'response': 'Page updated successfully'} else: data = {"error": True, 'response': validate_page.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') if request.user.is_superuser: c = {} c.update(csrf(request)) return render(request, 'admin/content/page/edit-page.html', {'page': page, 'csrf_token': c['csrf_token'], 'categories': categories, 'countries': countries}) else: return render_to_response('admin/accessdenied.html')
def add_page(request, category_name_url): context = RequestContext(request) cat_list = get_category_list() context_dict = {} context_dict['cat_list'] = cat_list category_name = decode_url(category_name_url) if request.method == 'POST': form = PageForm(request.POST) if form.is_valid(): # This time we cannot commit straight away. # Not all fields are automatically populated! page = form.save(commit=False) # Retrieve the associated Category object so we can add it. try: cat = Category.objects.get(name=category_name) page.category = cat except Category.DoesNotExist: return render_to_response( 'pages/add_page.html', context_dict, context) # Also, create a default value for the number of views. page.views = 0 # With this, we can then save our new model instance. page.save() # Now that the page is saved, display the category instead. return category(request, category_name_url) else: print form.errors else: form = PageForm() context_dict['category_name_url']= category_name_url context_dict['category_name'] = category_name context_dict['form'] = form return render_to_response( 'pages/add_page.html', context_dict, context)
def create_page(request, project_id): project = get_object_or_404(Project, pk=project_id) if request.method == 'POST': form = PageForm(request.POST) if form.is_valid(): # All validation rules pass new_page = form.save(commit=False) new_page.project = project new_page.created_by = request.user new_page.updated_by = request.user if form.is_valid(): new_page.save() return HttpResponseRedirect('/pages/%s/' % project_id) # Redirect after POST else: form = PageForm() # An unbound form return render(request, 'pages/create_page_form.html', { 'form': form, 'project_id': project_id })
def add_page(request, category_name_url): context = RequestContext(request) cat_list = get_category_list() context_dict = {} context_dict['cat_list'] = cat_list category_name = decode_url(category_name_url) if request.method == 'POST': form = PageForm(request.POST) if form.is_valid(): # This time we cannot commit straight away. # Not all fields are automatically populated! page = form.save(commit=False) # Retrieve the associated Category object so we can add it. try: cat = Category.objects.get(name=category_name) page.category = cat except Category.DoesNotExist: return render_to_response('pages/add_page.html', context_dict, context) # Also, create a default value for the number of views. page.views = 0 # With this, we can then save our new model instance. page.save() # Now that the page is saved, display the category instead. return category(request, category_name_url) else: print form.errors else: form = PageForm() context_dict['category_name_url'] = category_name_url context_dict['category_name'] = category_name context_dict['form'] = form return render_to_response('pages/add_page.html', context_dict, context)
def edit_page(request, pk): page = get_object_or_404(Page, pk=pk) categories = Category.objects.all() if request.method == 'POST': validate_page = PageForm(request.POST, instance=page) if validate_page.is_valid(): page = validate_page.save() page.category.clear() page.category.add(*request.POST.getlist('category')) data = {"error": False, 'response': 'Page updated successfully'} else: data = {"error": True, 'response': validate_page.errors} return HttpResponse(json.dumps(data), content_type='application/json; charset=utf-8') if request.user.is_superuser: c = {} c.update(csrf(request)) return render(request, 'admin/content/page/edit-page.html', {'page': page, 'csrf_token': c['csrf_token'], 'categories': categories}) else: return render_to_response('admin/accessdenied.html')