Exemple #1
0
def page_add(request, page_addr=None):
    '''Добавление wiki-страницы'''
    parent = None
    if page_addr:
        parent_error = check_parent_exist(page_addr+'/blah')
        parent = get_page_by_address(page_addr)
        page_parents = make_parent_list(page_addr+'/blah')
    form = AddPageForm(request.POST or None)
    if form.is_valid():
        db = form.save(commit=False)
        if parent:
            db.parent = parent
        db.save(get_client_ip(request), force_insert=True)
        return HttpResponseRedirect(reverse('wiki_page.views.page', args=[db.address,]))
    return render(request, 'page_edit.html', {"page": page, "form": form,  "parent_error": parent_error, "page_parents": page_parents})
Exemple #2
0
def page_edit(request, page_addr):
    '''Редактирование wiki-страницы'''
    parent_error = check_parent_exist(page_addr)
    page = get_page_by_address(page_addr)
    page_parents = make_parent_list(page_addr)
    childs = None
    if page:
        childs = page.page_set.filter(caption__isnull=False, text__isnull=False)
    form = PageForm(request.POST or None, instance=page)
    if not parent_error:
        if form.is_valid():
            db = form.save(commit=False)
            db.name = get_page_name_from_address(page_addr)
            if page_parents:
                db.parent = page_parents[-1]
            db.save(get_client_ip(request))
            return HttpResponseRedirect(reverse('wiki_page.views.page', args=[page_addr,]))
    return render(request, 'page_edit.html', {"page": page, "page_addr": page_addr, "childs": childs, "parent_error": parent_error, "page_parents": page_parents, "form": form})