def _new_version_needed_and_not_forking(event: ISheetReferenceNewVersion)\
        -> bool:
    """Check whether to autoupdate if resource is non-forkable.

    If the given resource is the last version or there's no last version yet,
    do autoupdate.

    If it's not the last version, but references the same object (namely the
    one which caused the autoupdate), don't update.

    If it's not the last version, but references a different object,
    throw an AutoUpdateNoForkAllowedError. This should only happen in batch
    requests.
    """
    last = get_last_version(event.object, event.registry)
    if last is None or last is event.object:
        return True
    value = get_sheet_field(event.object, event.isheet, event.isheet_field,
                            event.registry)
    last_value = get_sheet_field(last, event.isheet, event.isheet_field,
                                 event.registry)
    if last_value == value:
        return False
    else:
        raise AutoUpdateNoForkAllowedError(event.object, event)
Exemple #2
0
def _new_version_needed_and_not_forking(event: ISheetReferenceNewVersion)\
        -> bool:
    """Check whether to autoupdate if resource is non-forkable.

    If the given resource is the last version or there's no last version yet,
    do autoupdate.

    If it's not the last version, but references the same object (namely the
    one which caused the autoupdate), don't update.

    If it's not the last version, but references a different object,
    throw an AutoUpdateNoForkAllowedError. This should only happen in batch
    requests.
    """
    last = get_last_version(event.object, event.registry)
    if last is None or last is event.object:
        return True
    value = get_sheet_field(event.object, event.isheet, event.isheet_field,
                            event.registry)
    last_value = get_sheet_field(last, event.isheet, event.isheet_field,
                                 event.registry)
    if last_value == value:
        return False
    else:
        raise AutoUpdateNoForkAllowedError(event.object, event)
def validate_linear_history_no_fork(node: colander.SchemaNode, value: list):
    """Validate lineare history (no fork) for the follows field.

    :param:'value': list of one 'follows' resource.

    :raises colander.Invalid: if value does not reference the last version.
    """
    context = node.bindings['context']
    request = node.bindings['request']
    if is_batchmode(request):
        last_new_version = get_last_new_version(request.registry, context)
        if last_new_version is not None:
            # Store ths last new version created in this transaction
            # so :func:`adhocracy_core.rest.views.ItemPoolView.post`
            # can do an put instead of post action in batch requests.
            request.validated['_last_new_version_in_transaction'] =\
                last_new_version
            return
    last = get_last_version(context, request.registry)
    _assert_follows_eq_last_version(node, value, last)
Exemple #4
0
def validate_linear_history_no_fork(node: colander.SchemaNode, value: list):
    """Validate lineare history (no fork) for the follows field.

    :param:'value': list of one 'follows' resource.

    :raises colander.Invalid: if value does not reference the last version.
    """
    context = node.bindings['context']
    request = node.bindings['request']
    if is_batchmode(request):
        last_new_version = get_last_new_version(request.registry, context)
        if last_new_version is not None:
            # Store ths last new version created in this transaction
            # so :func:`adhocracy_core.rest.views.ItemPoolView.post`
            # can do an put instead of post action in batch requests.
            request.validated['_last_new_version_in_transaction'] =\
                last_new_version
            return
    last = get_last_version(context, request.registry)
    _assert_follows_eq_last_version(node, value, last)