Exemplo n.º 1
0
def rest_read(request, callback=None):
    """Base method to handle read requests on the REST interface.
    Returns a JSON object of a specific item.

    :request: Current request
    :callback: Current function which is called after the item has been read.
    :returns: JSON object.
    """
    handle_callback(request, callback)
    return JSONResponse(True, get_item_from_request(request))
Exemplo n.º 2
0
def rest_read(request, callback=None):
    """Base method to handle read requests on the REST interface.
    Returns a JSON object of a specific item.

    :request: Current request
    :callback: Current function which is called after the item has been read.
    :returns: JSON object.
    """
    handle_callback(request, callback, mode="pre,default")
    return JSONResponse(True, get_item_from_request(request))
Exemplo n.º 3
0
def read(request, callback=None, renderers=None):
    """Base method to handle read requests. Returns a dictionary of
    values used available in the rendererd template The template to
    render is defined in the view configuration.

    :request: Current request
    :callback: Current function which is called after the item has been read.
    :returns: Dictionary.
    """
    handle_history(request)
    handle_params(request)
    handle_callback(request, callback)
    rvalues = get_return_value(request)
    values = {'_roles': [str(r.name) for r in request.user.roles]}
    form = get_item_form('read', request, renderers, values=values)
    rvalues['form'] = render_item_form(request, form, values)
    return rvalues
Exemplo n.º 4
0
def read(request, callback=None, renderers=None):
    """Base method to handle read requests. Returns a dictionary of
    values used available in the rendererd template The template to
    render is defined in the view configuration.

    :request: Current request
    :callback: Current function which is called after the item has been read.
    :returns: Dictionary.
    """
    handle_params(request)
    handle_callback(request, callback, mode="pre,default")
    rvalues = get_return_value(request)
    values = {'_roles': [str(r.name) for r in request.user.roles]}
    form = get_item_form('read', request, renderers, values=values)
    rvalues['form'] = render_item_form(request, form)
    handle_callback(request, callback, mode="post")
    return rvalues
Exemplo n.º 5
0
def _handle_delete_request(request, items, callback):
    clazz = request.context.__model__
    _ = request.translate
    if request.method == 'POST' and request.ringo.params.confirmed:
        item_label = get_item_modul(request, clazz).get_label(plural=True)
        mapping = {'item_type': item_label, 'num': len(items)}
        for item in items:
            handle_callback(request, callback, item=item, mode="pre,default")
            request.db.delete(item)
            handle_callback(request, callback, item=item, mode="post")
        # Invalidate cache
        invalidate_cache()
        try:
            request.db.flush()
        except (sa.exc.CircularDependencyError, sa.exc.IntegrityError) as e:
            mapping["error"] = e.message.decode("utf-8")
            title = _("Can not delete ${item_type} items.", mapping=mapping)
            body = _(
                "There has been an integrity error which prevents "
                "the request to be fulfilled. There are still "
                "depended items on the item to be deleted. Please "
                "remove all depended relations to this item before "
                "deleting it and try again. Hint: ${error}",
                mapping=mapping)
            request.db.rollback()
            renderer = InfoDialogRenderer(request, title, body)
            rvalue = {}
            ok_url = request.ringo.history.pop(2)
            rvalue['dialog'] = renderer.render(ok_url)
            return rvalue

        msg = _('Deleted ${num} ${item_type} successfully.', mapping=mapping)
        log_msg = u'User {user.login} deleted {item_label} {item.id}' \
            .format(item_label=item_label, item=item, user=request.user)
        log.info(log_msg)
        request.session.flash(msg, 'success')
        # Handle redirect after success.
        return _handle_redirect(request)
    else:
        renderer = ConfirmDialogRenderer(request, clazz, 'delete')
        rvalue = {}
        rvalue['dialog'] = renderer.render(items)
        rvalue['clazz'] = clazz
        rvalue['item'] = items
        return rvalue