Ejemplo n.º 1
0
def render_ajax_form(model, request, name):
    """Render ajax form.
    """
    try:
        result = render_tile(model, request, name)
        selector = request.environ.get("cone.app.form.selector", "#content")
        mode = request.environ.get("cone.app.form.mode", "inner")
        continuation = request.environ.get("cone.app.continuation")
        form_continue = AjaxFormContinue(result, continuation)
        rendered_form = form_continue.form
        rendered = ajax_form_template % {
            "form": rendered_form,
            "selector": selector,
            "mode": mode,
            "next": form_continue.next,
        }
        return Response(rendered)
    except Exception:
        result = "<div>Form rendering error</div>"
        selector = request.environ.get("cone.app.form.selector", "#content")
        mode = request.environ.get("cone.app.form.mode", "inner")
        tb = format_traceback()
        continuation = AjaxMessage(tb, "error", None)
        form_continue = AjaxFormContinue(result, [continuation])
        rendered = ajax_form_template % {
            "form": form_continue.form.replace(u"\n", u" "),  # XXX: replace?
            "selector": selector,
            "mode": mode,
            "next": form_continue.next,
        }
        return Response(rendered)
Ejemplo n.º 2
0
def ajax_tile(model, request):
    """bdajax ``ajaxaction`` implementation for cone.

    * Renders tile with name ``bdajax.action``.

    * Uses definitions from ``request.environ['cone.app.continuation']``
      for continuation definitions.
    """
    try:
        name = request.params["bdajax.action"]
        ActionContext(model, request, name)
        rendered = render_tile(model, request, name)
        continuation = request.environ.get("cone.app.continuation")
        if continuation:
            continuation = AjaxContinue(continuation).definitions
        else:
            continuation = False
        return {
            "mode": request.params.get("bdajax.mode"),
            "selector": request.params.get("bdajax.selector"),
            "payload": rendered,
            "continuation": continuation,
        }
    except Exception:
        logging.exception("Error within ajax tile")
        tb = format_traceback()
        continuation = AjaxContinue([AjaxMessage(tb, "error", None)]).definitions
        return {"mode": "NONE", "selector": "NONE", "payload": "", "continuation": continuation}
Ejemplo n.º 3
0
def render_ajax_form(model, request, name):
    """Render ajax form.
    """
    try:
        result = render_tile(model, request, name)
        selector = request.environ.get('cone.app.form.selector', '#content')
        mode = request.environ.get('cone.app.form.mode', 'inner')
        continuation = request.environ.get('cone.app.continuation')
        form_continue = AjaxFormContinue(result, continuation)
        rendered_form = form_continue.form
        rendered = ajax_form_template % {
            'form': rendered_form,
            'selector': selector,
            'mode': mode,
            'next': form_continue.next,
        }
        return Response(rendered)
    except Exception:
        result = '<div>Form rendering error</div>'
        selector = request.environ.get('cone.app.form.selector', '#content')
        mode = request.environ.get('cone.app.form.mode', 'inner')
        tb = format_traceback()
        continuation = AjaxMessage(tb, 'error', None)
        form_continue = AjaxFormContinue(result, [continuation])
        rendered = ajax_form_template % {
            'form': form_continue.form.replace(u'\n', u' '),  # XXX: replace?
            'selector': selector,
            'mode': mode,
            'next': form_continue.next,
        }
        return Response(rendered)
Ejemplo n.º 4
0
def settings_tab_content(model, request):
    """Used by jquerytools tabs plugin to get settings section content.
    """
    try:
        rendered = render_tile(model, request, 'content')
    except Exception, e:
        localizer = get_localizer(request)
        error = localizer.translate(_('error', default='Error'))
        rendered = '<div>%s: %s</div>' % (error, format_traceback())
Ejemplo n.º 5
0
def ajax_tile(model, request):
    """bdajax ``ajaxaction`` implementation for cone.

    * Renders tile with name ``bdajax.action``.

    * Uses definitions from ``request.environ['cone.app.continuation']``
      for continuation definitions.
    """
    try:
        name = request.params['bdajax.action']
        ActionContext(model, request, name)
        rendered = render_tile(model, request, name)
        continuation = request.environ.get('cone.app.continuation')
        if continuation:
            continuation = AjaxContinue(continuation).definitions
        else:
            continuation = False
        return {
            'mode': request.params.get('bdajax.mode'),
            'selector': request.params.get('bdajax.selector'),
            'payload': rendered,
            'continuation': continuation,
        }
    except Forbidden:
        request.response.status = 403
        return {}
    except Exception:
        logging.exception('Error within ajax tile')
        tb = format_traceback()
        continuation = AjaxContinue([AjaxMessage(tb, 'error',
                                                 None)]).definitions
        return {
            'mode': 'NONE',
            'selector': 'NONE',
            'payload': '',
            'continuation': continuation,
        }