예제 #1
0
def edit_page(request, pk):
    if request.method == 'GET':
        page = Page.objects.get(pk=pk)
        page_list = Page.objects.all()
        return render(request, 'admin/page-edit.html', {
            'page': page,
            'page_list': page_list
        })

    p = Page.objects.get(pk=pk)
    validate_page = PageForm(request.POST, instance=p)
    errors = {}
    if validate_page.is_valid():
        page = validate_page.save()
        photos = request.FILES.getlist('photos')
        for p in photos:
            img = Gal_Image.objects.create(image=p)
            page.photos.add(img)
        page.save()
        return JsonResponse({
            'data': 'Page edited successfully',
            "error": False
        })

    for e in validate_page.errors:
        errors[e] = validate_page.errors[e][0]
    return JsonResponse(errors)
예제 #2
0
def admin_edit_page(request, page_id):
    if users.is_current_user_admin():
        page = Page.get_by_id(int(page_id))

        if request.method == 'GET':
            form = PageForm({
                'title': page.title,
                'content': page.content,
            })

        elif request.method == 'POST':
            form = PageForm(request.POST)
            if form.is_valid():
                p = form.save(commit=False)
                page.title = p.title
                page.content = p.content
                page.put()

            return HttpResponseRedirect('/admin')

        return render_to_response('admin/edit.html',
                                  dictionary={
                                      'form': form,
                                      'type': 'Edit Page',
                                  },
                                  context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/')
예제 #3
0
def admin_edit_page(request, page_id):
    if users.is_current_user_admin():
        page = Page.get_by_id(int(page_id))
        
        if request.method == 'GET':
            form = PageForm({'title':page.title, 'content':page.content, })
            
        elif request.method == 'POST':
            form = PageForm(request.POST)
            if form.is_valid():
                p = form.save(commit=False)
                page.title = p.title
                page.content = p.content
                page.put()

            return HttpResponseRedirect('/admin')
        
        return render_to_response('admin/edit.html',
                                      dictionary={'form' : form,
                                                    'type' : 'Edit Page',
                                                     },
                                      context_instance=RequestContext(request)
                                    )
    else:
        return HttpResponseRedirect('/')
예제 #4
0
def page_edit(request, page_id):
    page_obj = Page.objects.get(pk=page_id)
    if request.method == "POST":
        form = PageForm(request.POST, instance=page_obj)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.author = "TESTTEST"
            obj.save()
            return HttpResponseRedirect(reverse("page_detail", kwargs={"page_id": page_obj.id}))
    else:
        form = PageForm(instance=page_obj)

    context = {"form": form, "page_obj": page_obj}
    return render_to_response("page_edit.html", context, context_instance=RequestContext(request))
예제 #5
0
def add_page(request, category_name_slug):
    try:
        cat = Category.objects.get(slug=category_name_slug)
    except Category.DoesNotExist:
                cat = None

    if request.method == 'POST':
        form = PageForm(request.POST)
        if form.is_valid():
            if cat:
                page = form.save(commit=True)
                page.category.add(cat)
                # probably better to use a redirect here.
                return category(request, category_name_slug)
        else:
            print form.errors
    else:
        form = PageForm()

    context_dict = {'form':form, 'category': cat}
    return render(request, 'blog/add_page.html', context_dict)
예제 #6
0
def add_page(request):
    if request.method == 'GET':
        page_list = Page.objects.all()
        return render(request, 'admin/page-add.html', {'page_list': page_list})

    validate_page = PageForm(request.POST)
    errors = {}
    if validate_page.is_valid():
        new_page = validate_page.save()
        photos = request.FILES.getlist('photos')
        for p in photos:
            img = Gal_Image.objects.create(image=p)
            new_page.photos.add(img)
        new_page.save()
        return JsonResponse({
            'data': 'Page Created successfully',
            "error": False
        })

    for e in validate_page.errors:
        errors[e] = validate_page.errors[e][0]
    return JsonResponse(errors)
예제 #7
0
def admin_add_page(request):

    if users.is_current_user_admin():
        if request.method == 'GET':
            form = PageForm()

        elif request.method == 'POST':
            form = PageForm(request.POST)
            if form.is_valid():
                page = form.save(commit=False)
                page.author = users.get_current_user()
                page.content
                page.put()
                return HttpResponseRedirect('/admin')
        return render_to_response('admin/edit.html',
                                  dictionary={
                                      'form': form,
                                      'type': 'Add Page',
                                  },
                                  context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect('/')
예제 #8
0
def admin_add_page(request):

    if users.is_current_user_admin():
        if request.method == 'GET':
            form = PageForm()
            
        elif request.method == 'POST':
            form = PageForm(request.POST)
            if form.is_valid():
                page = form.save(commit=False)
                page.author = users.get_current_user()
                page.content
                page.put()
                return HttpResponseRedirect('/admin')
        return render_to_response('admin/edit.html',
                                      dictionary={ 'form':form,
                                                    'type': 'Add Page',
                                                    },
                                      context_instance=RequestContext(request)
                                    )
    else:
        return HttpResponseRedirect('/')
예제 #9
0
 def post(self, request, *args, **kwargs):
   form = PageForm(request.POST)
   if form.is_valid():
     page = form.save()
     return HttpResponseRedirect(reverse_lazy('blog-list-page')) # when the page is saved, you'll be rerouted back to the wiki list page
   return render(request, 'new_page.html', {'form': form})