Exemple #1
0
    def render(self):
        context = {
            "a_rel_info": self.breadcrumbs[-1]["name"],
            "rel_path": self.rel_path,
            "dir_info": self.dir_info,
            "picture_info": self.picture_info,
            "breadcrumbs": self.breadcrumbs,
        }

        # ajax and non ajax response
        return render_pylucid_response(self.request, self.config.template, context,
            context_instance=RequestContext(self.request)
        )
Exemple #2
0
    def render(self):
        context = {
            "a_rel_info": self.breadcrumbs[-1]["name"],
            "rel_path": self.rel_path,
            "dir_info": self.dir_info,
            "picture_info": self.picture_info,
            "breadcrumbs": self.breadcrumbs,
        }

        # ajax and non ajax response
        return render_pylucid_response(self.request,
                                       self.config.template,
                                       context,
                                       context_instance=RequestContext(
                                           self.request))
Exemple #3
0
def _login_view(request):
    if DEBUG:
        print("auth debug mode is on!")

    if request.method != 'GET':
        debug_msg = "request method %r wrong, only GET allowed" % request.method
        return bad_request(debug_msg) # Return HttpResponseBadRequest

    next_url = request.GET.get("next_url", request.path)

    if "://" in next_url: # FIXME: How to validate this better?
        # Don't redirect to other pages.
        debug_msg = "next url %r seems to be wrong!" % next_url
        return bad_request(debug_msg) # Return HttpResponseBadRequest

    form = ShaLoginForm()

    # create a new challenge and add it to session
    challenge = _get_challenge(request)

    context = {
        "is_ajax": request.is_ajax(),
        "challenge": challenge,
        "salt_len": crypt.SALT_LEN,
        "hash_len": crypt.HASH_LEN,
        "get_salt_url": request.path + "?auth=get_salt",
        "sha_auth_url": request.path + "?auth=sha_auth",
        "next_url": next_url,
        "form": form,
        "pass_reset_link": "#TODO",
    }

    # IMPORTANT: We must do the following, so that the
    # CsrfViewMiddleware.process_response() would set the CSRF_COOKIE
    # see also # https://github.com/jedie/PyLucid/issues/61
    # XXX in Django => 1.4 we can use @ensure_csrf_cookie
    # https://docs.djangoproject.com/en/dev/ref/contrib/csrf/#django.views.decorators.csrf.ensure_csrf_cookie
    request.META["CSRF_COOKIE_USED"] = True

    # return a string for replacing the normal cms page content
    return render_pylucid_response(request, 'auth/sha_form.html', context, context_instance=RequestContext(request))
Exemple #4
0
def _edit_page(request, form_url):
    pagetree = request.PYLUCID.pagetree
    if pagetree.page_type != PageTree.PAGE_TYPE:
        messages.info(request, "Current page is not a content page.")
        return

    pagemeta, pagecontent = _get_pageobjects(request)
    preview_html = ""

    if request.method == 'POST':
        edit_page_form = EditPageForm(request.POST)
        if edit_page_form.is_valid():
            if "preview" in request.POST:
                raw_content = edit_page_form.cleaned_data["content"]
                preview_html = apply_markup(raw_content,
                                            pagecontent.markup,
                                            request,
                                            escape_django_tags=True)
            else:
                new_content = edit_page_form.cleaned_data["content"]
                pagecontent.content = new_content
                pagecontent.save()
                messages.success(request, _("Page content updated."))
                return HttpResponseRedirect(request.path)
    else:
        edit_page_form = EditPageForm(initial={"content": pagecontent.content})

    context = {
        "form_url": form_url,
        "abort_url": request.path,
        "preview_url": "%s?page_admin=preview" % request.path,
        "preview_html": preview_html,
        "edit_page_form": edit_page_form,
        "pagecontent": pagecontent,
        "pagemeta": pagemeta,
    }
    return render_pylucid_response(request,
                                   'page_admin/edit_inline_form.html',
                                   context,
                                   context_instance=RequestContext(request))
Exemple #5
0
def _edit_page(request, form_url):
    pagetree = request.PYLUCID.pagetree
    if pagetree.page_type != PageTree.PAGE_TYPE:
        messages.info(request, "Current page is not a content page.")
        return

    pagemeta, pagecontent = _get_pageobjects(request)
    preview_html = ""

    if request.method == 'POST':
        edit_page_form = EditPageForm(request.POST)
        if edit_page_form.is_valid():
            if "preview" in request.POST:
                raw_content = edit_page_form.cleaned_data["content"]
                preview_html = apply_markup(
                    raw_content, pagecontent.markup, request, escape_django_tags=True
                )
            else:
                new_content = edit_page_form.cleaned_data["content"]
                pagecontent.content = new_content
                pagecontent.save()
                messages.success(request, _("Page content updated."))
                return HttpResponseRedirect(request.path)
    else:
        edit_page_form = EditPageForm(initial={"content":pagecontent.content})

    context = {
        "form_url": form_url,
        "abort_url": request.path,
        "preview_url": "%s?page_admin=preview" % request.path,

        "preview_html": preview_html,

        "edit_page_form": edit_page_form,
        "pagecontent": pagecontent,
        "pagemeta": pagemeta,
    }
    return render_pylucid_response(request, 'page_admin/edit_inline_form.html', context,
        context_instance=RequestContext(request)
    )