def store_lot(lot, patch, request):
    revision = prepare_revision(lot, patch, request.authenticated_userid)
    lot.revisions.append(type(lot).revisions.model_class(revision))
    old_dateModified = lot.dateModified
    if getattr(lot, 'modified', True):
        lot.dateModified = get_now()
    try:
        lot.store(request.registry.db)
    except ModelValidationError as e:
        for i in e.message:
            request.errors.add('body', i, e.message[i])
        request.errors.status = 422
    except ResourceConflict as e:  # pragma: no cover
        request.errors.add('body', 'data', str(e))
        request.errors.status = 409
    except Exception as e:  # pragma: no cover
        request.errors.add('body', 'data', str(e))
    else:
        LOGGER.info(
            'Saved lot {lot_id}: dateModified {old_dateModified} -> {new_dateModified}'
            .format(lot_id=lot.id,
                    old_dateModified=old_dateModified
                    and old_dateModified.isoformat(),
                    new_dateModified=lot.dateModified.isoformat()),
            extra=context_unpack(request, {'MESSAGE_ID': 'save_lot'},
                                 {'RESULT': lot.rev}))
        return True
Exemplo n.º 2
0
def store_lot(lot, patch, request):
    revision = prepare_revision(lot, patch, request.authenticated_userid)
    lot.revisions.append(type(lot).revisions.model_class(revision))
    old_dateModified = lot.dateModified
    if getattr(lot, 'modified', True):
        lot.dateModified = get_now()
    try:
        lot.store(request.registry.db)
    except ModelValidationError, e:
        for i in e.message:
            request.errors.add('body', i, e.message[i])
        request.errors.status = 422
Exemplo n.º 3
0
def save_asset(request):
    asset = request.validated['asset']
    if asset.mode == u'test':
        set_modetest_titles(asset)
    patch = get_revision_changes(asset.serialize("plain"), request.validated['asset_src'])
    if patch:
        revision = prepare_revision(asset, patch, request.authenticated_userid)
        asset.revisions.append(type(asset).revisions.model_class(revision))
        old_dateModified = asset.dateModified
        if getattr(asset, 'modified', True):
            asset.dateModified = get_now()
        try:
            asset.store(request.registry.db)
        except ModelValidationError, e:
            for i in e.message:
                request.errors.add('body', i, e.message[i])
            request.errors.status = 422
        except ResourceConflict, e:  # pragma: no cover
            request.errors.add('body', 'data', str(e))
            request.errors.status = 409