コード例 #1
0
ファイル: views.py プロジェクト: knagra/farnsworth
def landing_view(request):
    """ The external landing."""
    revision = None
    can_edit = False
    edit_url = None

    if "farnswiki" in settings.INSTALLED_APPS:
        from wiki.models import Page
        from wiki.hooks import hookset

        binder = settings.WIKI_BINDERS[0]
        wiki = binder.lookup()
        try:
            if wiki:
                page = wiki.pages.get(slug="landing")
            else:
                page = Page.objects.get(slug="landing")
        except (Page.DoesNotExist, Page.MultipleObjectsReturned):
            can_edit = hookset.can_create_page(wiki, request.user, slug="landing")
            edit_url = binder.page_url(wiki, "landing")
        else:
            revision = page.revisions.latest()
            can_edit = hookset.can_edit_page(page, request.user)
            edit_url = page.get_edit_url()

    return render_to_response(
        "external.html",
        {"page_name": "Landing", "revision": revision, "can_edit": can_edit, "edit_url": edit_url},
        context_instance=RequestContext(request),
    )
コード例 #2
0
def landing_view(request):
    ''' The external landing.'''
    revision = None
    can_edit = False
    edit_url = None

    if "farnswiki" in settings.INSTALLED_APPS:
        from wiki.models import Page
        from wiki.hooks import hookset
        binder = settings.WIKI_BINDERS[0]
        wiki = binder.lookup()
        try:
            if wiki:
                page = wiki.pages.get(slug="landing")
            else:
                page = Page.objects.get(slug="landing")
        except (Page.DoesNotExist, Page.MultipleObjectsReturned):
            can_edit = hookset.can_create_page(wiki,
                                               request.user,
                                               slug="landing")
            edit_url = binder.page_url(wiki, "landing")
        else:
            revision = page.revisions.latest()
            can_edit = hookset.can_edit_page(page, request.user)
            edit_url = page.get_edit_url()

    return render_to_response('external.html', {
        "page_name": "Landing",
        "revision": revision,
        "can_edit": can_edit,
        "edit_url": edit_url,
    },
                              context_instance=RequestContext(request))
コード例 #3
0
def edit(request, slug, binder, *args, **kwargs):
    wiki = binder.lookup(*args, **kwargs)
    try:
        if wiki:
            page = wiki.pages.get(slug=slug)
        else:
            page = Page.objects.get(slug=slug)
    except Page.DoesNotExist:
        return HttpResponseRedirect(reverse("wiki_add") + "?slug=" + slug)
    else:
        if not hookset.can_edit_page(page, request.user):
            messages.add_message(
                request, messages.ERROR,
                "You do not have permission to edit this page.")
            return HttpResponseRedirect(reverse("wiki_all"))
        rev = page.revisions.latest()

    form = RevisionForm(
        request.POST if "edit" in request.POST else None,
        revision=rev,
    )
    if form.is_valid():
        revision = form.save(commit=False)
        revision.page = page
        revision.created_by = request.user
        revision.created_ip = request.META.get(
            settings.WIKI_IP_ADDRESS_META_FIELD,
            request.META.get("REMOTE_ADDR"))
        revision.parse()
        revision.save()
        return HttpResponseRedirect(binder.page_url(wiki, slug))

    form.fields["content"].help_text = ""

    can_delete = hookset.can_delete_page(page, request.user) and page.pk

    if can_delete and "delete" in request.POST:
        page.delete()
        return HttpResponseRedirect(reverse("wiki_all"))

    page_name = "Edit {0}".format(page.slug)

    return render_to_response("wiki/edit.html", {
        "page_name": page_name,
        "form": form,
        "page": page,
        "can_delete": can_delete,
    },
                              context_instance=RequestContext(request))
コード例 #4
0
ファイル: views.py プロジェクト: bsc-networks/farnsworth
def edit(request, slug, binder, *args, **kwargs):
    wiki = binder.lookup(*args, **kwargs)
    try:
        if wiki:
            page = wiki.pages.get(slug=slug)
        else:
            page = Page.objects.get(slug=slug)
        rev = page.revisions.latest()
        if not hookset.can_edit_page(page, request.user):
            return HttpResponseForbidden()
    except Page.DoesNotExist:
        return HttpResponseRedirect(reverse("wiki_add") + "?slug=" + slug)

    form = RevisionForm(
        request.POST if "edit" in request.POST else None,
        revision=rev,
    )
    if form.is_valid():
        revision = form.save(commit=False)
        revision.page = page
        revision.created_by = request.user
        revision.created_ip = request.META.get(settings.WIKI_IP_ADDRESS_META_FIELD,
                                               request.META.get("REMOTE_ADDR"))
        revision.parse()
        revision.save()
        return HttpResponseRedirect(binder.page_url(wiki, slug))

    form.fields["content"].help_text = ""

    can_delete = hookset.can_delete_page(page, request.user) and page.pk

    if can_delete and "delete" in request.POST:
        page.delete()
        return HttpResponseRedirect(reverse("wiki_all"))

    page_name = "Edit {0}".format(page.slug)

    return render_to_response("wiki/edit.html", {
        "page_name": page_name,
        "form": form,
        "page": page,
        "can_delete": can_delete,
    }, context_instance=RequestContext(request))
コード例 #5
0
ファイル: views.py プロジェクト: bsc-networks/farnsworth
def page(request, slug, binder, *args, **kwargs):
    wiki = binder.lookup(*args, **kwargs)
    try:
        if wiki:
            page = wiki.pages.get(slug=slug)
        else:
            page = Page.objects.get(slug=slug)
        if not hookset.can_view_page(page, request.user):
            raise Http404()

        try:
            rev = page.revisions.get(pk=request.GET.get("rev", "-1"))
        except Revision.DoesNotExist:
            rev = page.revisions.latest()
    except Page.DoesNotExist:
        return HttpResponseRedirect(binder.edit_url(wiki, slug))

    return render_to_response("wiki/page.html", {
        "revision": rev,
        "can_edit": hookset.can_edit_page(page, request.user),
    }, context_instance=RequestContext(request))
コード例 #6
0
def page(request, slug, binder, *args, **kwargs):
    wiki = binder.lookup(*args, **kwargs)
    try:
        if wiki:
            page = wiki.pages.get(slug=slug)
        else:
            page = Page.objects.get(slug=slug)
        if not hookset.can_view_page(page, request.user):
            raise Http404()

        try:
            rev = page.revisions.get(pk=request.GET.get("rev", "-1"))
        except Revision.DoesNotExist:
            rev = page.revisions.latest()
    except Page.DoesNotExist:
        return HttpResponseRedirect(binder.edit_url(wiki, slug))

    return render_to_response(
        "wiki/page.html", {
            "revision": rev,
            "can_edit": hookset.can_edit_page(page, request.user),
        },
        context_instance=RequestContext(request))