def page_edit(request, slug):
    try:
        page = Page.objects.filter(slug=slug).get()
    except __HOLE__:
        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))
dataset/ETHPy150Open kylef-archive/lithium/lithium/wiki/views.py/page_edit