Example #1
0
def save_plan(request):
    """ Save plan object to database
    :param request:
    :return: True if Ok
    """
    plan = request.validated["plan"]

    patch = get_revision_changes(plan.serialize("plain"),
                                 request.validated["plan_src"])
    if patch:
        append_revision(request, plan, patch)
        old_date_modified = plan.dateModified

        if getattr(plan, "modified", True):
            now = get_now()
            plan.dateModified = now
            if any(c for c in patch if c["path"].startswith("/cancellation/")):
                plan.cancellation.date = now

        with handle_store_exceptions(request):
            plan.store(request.registry.db)
            LOGGER.info(
                "Saved plan {}: dateModified {} -> {}".format(
                    plan.id, old_date_modified
                    and old_date_modified.isoformat(),
                    plan.dateModified.isoformat()),
                extra=context_unpack(request, {"MESSAGE_ID": "save_plan"},
                                     {"PLAN_REV": plan.rev}),
            )
            return True
def save_contract(request):
    """ Save contract object to database
    :param request:
    :return: True if Ok
    """
    contract = request.validated["contract"]

    if contract.mode == "test":
        set_modetest_titles(contract)

    patch = get_revision_changes(contract.serialize("plain"),
                                 request.validated["contract_src"])
    if patch:
        append_revision(request, contract, patch)

        old_date_modified = contract.dateModified
        contract.dateModified = get_now()

        with handle_store_exceptions(request):
            contract.store(request.registry.db)
            LOGGER.info(
                "Saved contract {}: dateModified {} -> {}".format(
                    contract.id, old_date_modified
                    and old_date_modified.isoformat(),
                    contract.dateModified.isoformat()),
                extra=context_unpack(request, {"MESSAGE_ID": "save_contract"},
                                     {"CONTRACT_REV": contract.rev}),
            )
            return True
def save_agreement(request):
    """
    Save agreement object to database
    :param request:
    :return: True if Ok
    """
    agreement = request.validated["agreement"]

    if agreement.mode == u"test":
        set_modetest_titles(agreement)

    patch = get_revision_changes(agreement.serialize("plain"),
                                 request.validated["agreement_src"])
    if patch:
        append_revision(request, agreement, patch)
        old_date_modified = agreement.dateModified
        agreement.dateModified = get_now()

        with handle_store_exceptions(request):
            agreement.store(request.registry.db)
            LOGGER.info(
                "Saved agreement {}: dateModified {} -> {}".format(
                    agreement.id,
                    old_date_modified and old_date_modified.isoformat(),
                    agreement.dateModified.isoformat(),
                ),
                extra=context_unpack(request, {"MESSAGE_ID": "save_agreement"},
                                     {"AGREEMENT_REV": agreement.rev}),
            )
            return True
Example #4
0
def append_obj_revision(request, obj, patch, date):
    status_changes = [
        p for p in patch
        if all([p["path"].endswith("/status"), p["op"] == "replace"])
    ]
    changed_obj = obj
    for change in status_changes:
        changed_obj = resolve_pointer(obj,
                                      change["path"].replace("/status", ""))
        if changed_obj and hasattr(changed_obj, "date") and hasattr(
                changed_obj, "revisions"):
            date_path = change["path"].replace("/status", "/date")
            if changed_obj.date and not any(
                [p for p in patch if date_path == p["path"]]):
                patch.append({
                    "op": "replace",
                    "path": date_path,
                    "value": changed_obj.date.isoformat()
                })
            elif not changed_obj.date:
                patch.append({"op": "remove", "path": date_path})
            changed_obj.date = date
        else:
            changed_obj = obj
    return append_revision(request, changed_obj, patch)
Example #5
0
def append_framework_revision(request, framework, patch, date):
    status_changes = [p for p in patch if all([
        p["path"].endswith("/status"),
        p["op"] == "replace"
    ])]
    for change in status_changes:
        obj = resolve_pointer(framework, change["path"].replace("/status", ""))
        if obj and hasattr(obj, "date"):
            date_path = change["path"].replace("/status", "/date")
            if obj.date and not any([p for p in patch if date_path == p["path"]]):
                patch.append({"op": "replace", "path": date_path, "value": obj.date.isoformat()})
            elif not obj.date:
                patch.append({"op": "remove", "path": date_path})
            obj.date = date
    return append_revision(request, framework, patch)