Ejemplo n.º 1
0
    def post(self):
        """Create new resource and get response data.

        For :class:`adhocracy_core.interfaces.IItemVersion`:

        If a `new version` is already created in this transaction we don't want
        to create a new one. Instead we modify the existing one.

        This is needed to make :class:`adhocray_core.rest.batchview.BatchView`
        work.
        """
        metric = self._get_post_metric_name()
        with statsd_timer(metric, rate=1, registry=self.registry):
            if is_batchmode(self.request) and self._creating_new_version():
                last = self.registry.content.get_sheet_field(self.context,
                                                             ITags,
                                                             'LAST')
                if is_created_in_current_transaction(last, self.registry):
                    self._update_version(last)
                    resource = last
                else:
                    resource = self._create()
            else:
                resource = self._create()
            cstruct = self.build_post_response(resource)
        return cstruct
Ejemplo n.º 2
0
 def validate_linear_history(node, value):
     batchmode = is_batchmode(request)
     last = registry.content.get_sheet_field(context, ITags, 'LAST')
     if batchmode and is_created_in_current_transaction(last, registry):
         # In batchmode there is only one new last version created that is
         # updated by the following versions. See
         # func:`adhocracy_core.rest.views.IItemRestView.post` and
         # func:`adhocracy_core.resource.subscriber` for more information.
         return
     _assert_follows_last_version(node, value, last)
Ejemplo n.º 3
0
 def validate_linear_history(node, value):
     batchmode = is_batchmode(request)
     last = registry.content.get_sheet_field(context, ITags, 'LAST')
     if batchmode and is_created_in_current_transaction(last, registry):
         # In batchmode there is only one new last version created that is
         # updated by the following versions. See
         # func:`adhocracy_core.rest.views.IItemRestView.post` and
         # func:`adhocracy_core.resource.subscriber` for more information.
         return
     _assert_follows_last_version(node, value, last)
Ejemplo n.º 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.
    """
    from adhocracy_core.sheets.tags import ITags  # prevent circle dependencies
    context = node.bindings['context']
    request = node.bindings['request']
    registry = node.bindings['registry']
    batchmode = is_batchmode(request)
    last = get_sheet_field(context, ITags, 'LAST', registry=registry)
    if batchmode and is_created_in_current_transaction(last, registry):
        # In batchmode there is only one new last version created that is
        # updated by the following versions. See
        # func:`adhocracy_core.rest.views.IItemRestView.post` and
        # func:`adhocracy_core.resource.subscriber` for more information.
        return
    _assert_follows_last_version(node, value, last)