Ejemplo n.º 1
0
def new_wikipage(request, prefix=None, pagename=None):
    url_params = request.GET.copy()
    http_status = 200
    absolute_pagename = None
    # handle implicit page creation (when a url does not exist)
    if pagename:
        check_create_permission(request, prefix, pagename)
        http_status = 404
        absolute_pagename = join_pagename(prefix, pagename)
        url_params.update({'target': absolute_pagename})

    # merge all url parameters into a string for each template
    creation_templates = _get_creation_templates()
    for template in creation_templates:
        params = url_params.copy()
        if 'template_name' in template:
            params['template'] = template['template_name']
        template['params'] = params.urlencode()

    c = RequestContext(request, {
        'absolute_pagename': absolute_pagename,
        'creation_templates': creation_templates,
        'creation_views': _get_creation_views(),
        'url_params': url_params.urlencode(),
        'params_list': url_params.lists(),
    })
    t = loader.get_template('wiki/new_wikipage.html')
    return HttpResponse(t.render(c), status=http_status)
Ejemplo n.º 2
0
    def page_exists(self, pagename):
        from ductus.wiki.models import WikiPage
        name = join_pagename(self.prefix, pagename)
        try:
            latest = WikiPage.objects.get(name=name).get_latest_revision()
            if latest and latest.urn:
                return True
        except WikiPage.DoesNotExist:
            pass

        return False
Ejemplo n.º 3
0
def _fully_handle_blueprint_post(request, prefix, pagename):
    if not is_legal_wiki_pagename(prefix, pagename):
        raise Http404
    check_edit_permission(request, prefix, pagename)

    response = handle_blueprint_post(request)

    if isinstance(response, SuccessfulEditRedirect):
        page, page_created = WikiPage.objects.get_or_create(name=join_pagename(prefix, pagename))
        return _handle_successful_wikiedit(request, response, page)

    return response
Ejemplo n.º 4
0
def creation_view(request, page_type):
    try:
        view_func = registered_creation_views[page_type]
    except KeyError:
        raise Http404

    response = view_func(request)
    if "target" in request.GET:
        try:
            target = split_pagename(request.GET["target"])
        except WikiPrefixNotProvided:
            raise Http404
        if not is_legal_wiki_pagename(*target):
            raise Http404
        check_edit_permission(request, *target)
    if "target" in request.GET and isinstance(response, SuccessfulEditRedirect):
        page, page_created = WikiPage.objects.get_or_create(name=join_pagename(*target))
        return _handle_successful_wikiedit(request, response, page)
    return response
Ejemplo n.º 5
0
def view_wikipage(request, prefix, pagename):
    """Used for pages represented by a WikiPage"""

    if not is_legal_wiki_pagename(prefix, pagename):
        raise Http404

    if request.method == 'POST' and not request.GET.get('view', None):
        return _fully_handle_blueprint_post(request, prefix, pagename)

    name = join_pagename(prefix, pagename)
    try:
        page = WikiPage.objects.get(name=name)
    except WikiPage.DoesNotExist:
        page = None

    if page:
        if "oldid" in request.GET:
            try:
                revision = WikiRevision.objects.get(id=request.GET["oldid"], page=page)
            except (ValueError, WikiRevision.DoesNotExist):
                return query_string_not_found(request)
            if not revision.urn:
                return query_string_not_found(request)
        else:
            revision = page.get_latest_revision()
    else:
        revision = None

    if revision is None and getattr(settings, "DUCTUS_WIKI_REMOTE", None):
        # See if DUCTUS_WIKI_REMOTE has the page
        try:
            remote_url = "%s%s?view=urn" % (settings.DUCTUS_WIKI_REMOTE, iri_to_uri(urlquote(u'%s/%s' % (prefix, pagename))))
            remote_urn = json.loads(urlopen(remote_url).read(1000))["urn"]
            # we never actually save this WikiPage or WikiRevision to the database
            if page is None:
                page, page_created = WikiPage.objects.get_or_create(name=name)
            revision = WikiRevision(page=page, urn=remote_urn[4:])
        except urllib2_HTTPError:
            pass

    if revision and revision.urn:
        urn = 'urn:' + revision.urn
    else:
        urn = None

    if request.GET.get('view', None) == 'urn':
        if revision:
            return render_json_response({"urn": urn})

    response = None

    if urn:
        response = main_document_view(request, urn, page, revision)
        if isinstance(response, SuccessfulEditRedirect):
            return _handle_successful_wikiedit(request, response, page)
        response["X-Ductus-URN"] = urn
    else:
        requested_view = request.GET.get("view", None)
        request.ductus = DuctusRequestInfo(None, requested_view, page, revision)
        if requested_view:
            f = registered_views[None].get(requested_view, None)
            if f and f.meets_requirements(request.ductus):
                response = f(request)

    if response is None:
        response = new_wikipage(request, prefix, pagename)

    # wikipage urls expire immediately since they can frequently be edited
    patch_response_headers(response, cache_timeout=0)
    patch_cache_control(response, must_revalidate=True)

    return response