def save_monitoring(request, date_modified=None, update_context_date=False):
    monitoring = request.validated['monitoring']
    patch = get_revision_changes(request.validated['monitoring_src'],
                                 monitoring.serialize('plain'))
    if patch:
        add_revision(request, monitoring, patch)

        old_date_modified = monitoring.dateModified
        now = date_modified or get_now()
        monitoring.dateModified = now
        if update_context_date and "dateModified" in request.context:
            request.context.dateModified = now
        try:
            monitoring.store(request.registry.db)
        except ModelValidationError as e:  # pragma: no cover
            for i in e.messages:
                request.errors.add('body', i, e.messages[i])
            request.errors.status = 422
        except Exception as e:  # pragma: no cover
            request.errors.add('body', 'data', str(e))
        else:
            LOGGER.info('Saved monitoring {}: dateModified {} -> {}'.format(
                monitoring.id, old_date_modified
                and old_date_modified.isoformat(),
                monitoring.dateModified.isoformat()),
                        extra=context_unpack(
                            request, {'MESSAGE_ID': 'save_monitoring'}))
            return True
Exemple #2
0
def save_inspection(request, date_modified=None):
    inspection = request.validated['inspection']
    patch = get_revision_changes(request.validated['inspection_src'],
                                 inspection.serialize("plain"))
    if patch:
        add_revision(request, inspection, patch)

        old_date_modified = inspection.dateModified
        inspection.dateModified = date_modified or get_now()
        try:
            inspection.store(request.registry.db)
        except ModelValidationError as e:  # pragma: no cover
            for i in e.messages:
                request.errors.add('body', i, e.messages[i])
            request.errors.status = 422
        except Exception as e:  # pragma: no cover
            request.errors.add('body', 'data', str(e))
        else:
            LOGGER.info('Saved inspection {}: dateModified {} -> {}'.format(
                inspection.id, old_date_modified
                and old_date_modified.isoformat(),
                inspection.dateModified.isoformat()),
                        extra=context_unpack(
                            request, {'MESSAGE_ID': 'save_inspection'}))
            return True
Exemple #3
0
def save_request(request, date_modified=None):
    obj = request.validated["request"]
    patch = get_revision_changes(
        request.validated["request_src"], obj.serialize("plain")
    )
    if patch:
        add_revision(request, obj, patch)

        old_date_modified = obj.dateModified
        obj.dateModified = date_modified or get_now()
        try:
            obj.store(request.registry.db)
        except ModelValidationError as e:  # pragma: no cover
            for i in e.messages:
                request.errors.add("body", i, e.messages[i])
            request.errors.status = 422
        except Exception as e:  # pragma: no cover
            request.errors.add("body", "data", str(e))
        else:
            LOGGER.info(
                "Saved request {}: dateModified {} -> {}".format(
                    obj.id,
                    old_date_modified and old_date_modified.isoformat(),
                    obj.dateModified.isoformat(),
                ),
                extra=context_unpack(request, {"MESSAGE_ID": "save_request"}),
            )
            return True
def save_inspection(request, date_modified=None):
    inspection = request.validated['inspection']
    patch = get_revision_changes(request.validated['inspection_src'], inspection.serialize("plain"))
    if patch:
        add_revision(request, inspection, patch)

        old_date_modified = inspection.dateModified
        inspection.dateModified = date_modified or get_now()
        try:
            inspection.store(request.registry.db)
        except ModelValidationError, e:  # pragma: no cover
            for i in e.message:
                request.errors.add('body', i, e.message[i])
            request.errors.status = 422
        except Exception, e:  # pragma: no cover
            request.errors.add('body', 'data', str(e))
Exemple #5
0
def save_monitoring(request, date_modified=None):
    monitoring = request.validated['monitoring']
    patch = get_revision_changes(request.validated['monitoring_src'],
                                 monitoring.serialize('plain'))
    if patch:
        add_revision(request, monitoring, patch)

        old_date_modified = monitoring.dateModified
        monitoring.dateModified = date_modified or get_now()
        try:
            monitoring.store(request.registry.db)
        except ModelValidationError, e:  # pragma: no cover
            for i in e.message:
                request.errors.add('body', i, e.message[i])
            request.errors.status = 422
        except Exception, e:  # pragma: no cover
            request.errors.add('body', 'data', str(e))