Beispiel #1
0
def page_edit(request, slug):
    try:
        page = Page.objects.filter(slug=slug).get()
    except ObjectDoesNotExist:
        page = Page(title=title(slug), slug=slug)
    
    if not page.user_can_edit(request.user):
        if request.user.is_anonymous():
            return HttpResponseRedirect('%s?%s=%s' % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, urlquote(request.get_full_path())))
        else:
            return render_to_response('wiki/permission_denied.html', context_instance=RequestContext(request))
    
    if request.method == 'POST':
        form = EditForm(request, page, request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(form.instance.get_absolute_url())
    else:
        if page.content:
            form = EditForm(request, page, {'text': page.content})
        else:
            form = EditForm(request, page)
    
    template_context = {
        'page': page,
        'form': form,
    }
    
    return render_to_response('wiki/page_edit.html', template_context, RequestContext(request))
Beispiel #2
0
def page_detail(request, slug, template_name='wiki/page_detail.html'):
    try:
        page = Page.objects.filter(slug=slug).get()
    except ObjectDoesNotExist:
        page = Page(title=title(slug), slug=slug)

    if not page.has_read_permission(request.user):
        if request.user.is_anonymous():
            return HttpResponseRedirect('%s?%s=%s' % (settings.LOGIN_URL, REDIRECT_FIELD_NAME, urlquote(request.get_full_path())))
        else:
            return render_to_response('wiki/permission_denied.html', context_instance=RequestContext(request))

    return render_to_response(template_name,
        {'page':page, 'page_exists': bool(page.pk)}, RequestContext(request))