Exemplo n.º 1
0
def wiki_page_edit(request, page_path, _page_obj=None):
    page = _page_obj or WikiPage.get_object_by_path(page_path)

    preview_action = request.POST and 'preview' in request.POST

    if request.POST:
        form = WikiPageForm(data=request.POST, initial={'author':request.user}, instance=page)
        if form.is_valid():
            page = form.save(commit=False)
            if not preview_action:
                pages = WikiPage.make_path(page_path, kwargs={'author':request.user})
                if pages:
                    page.parent_page = pages[-1]
                page.title = WikiPage.get_title_from_path(page_path)
                print page_path
                print page.title
                page.author = request.user
                page.save()
                return redirect('wiki_page', page_path=page_path)
    else:
        form = WikiPageForm(initial={'author':request.user}, instance=page)
    context = {}
    context['page'] = page
    context['page_path'] = page_path
    context['form'] = form
    context['preview_action'] = preview_action
    return context
Exemplo n.º 2
0
def wiki_page(request, page_path):
    page = WikiPage.get_object_by_path(page_path)
    edit_action = 'edit' in request.GET
    if edit_action:
        return wiki_page_edit(request, page_path, page)

    context = {}
    context['page'] = page
    return context
Exemplo n.º 3
0
    def test_get_page(self):
        page = mommy.make_one(WikiPage, title='p1')
        page2 = mommy.make_one(WikiPage, title='p2', parent_page=page)

        assert WikiPage.get_object_by_path('/'.join([page.title])) != None
        assert WikiPage.get_object_by_path('/'.join([page.title, page2.title])) != None