Пример #1
0
def operation_update_last_edited(user_id, block_id) -> dict:
    """
    Convenience function for constructing "last edited" operation.

    When transactions are submitted from the web UIit also
    includes an operation to update the "last edited" fields,
    so we want to send those too, for consistency.


    Arguments
    ---------
    user_id : str
        User ID

    block_id : str
        Block ID


    Returns
    -------
    dict
        Constructed dict with last edited operation included.
    """
    return {
        "args": {
            "last_edited_by": user_id,
            "last_edited_time": now()
        },
        "command": "update",
        "id": block_id,
        "path": [],
        "table": "block",
    }
Пример #2
0
def operation_update_last_edited(user_id, record_id) -> dict:
    """
    Convenience function for constructing "last edited" operation.

    When transactions are submitted from the web UIit also
    includes an operation to update the "last edited" fields,
    so we want to send those too, for consistency.


    Arguments
    ---------
    user_id : str
        User ID

    record_id : str
        ID of the object.


    Returns
    -------
    dict
        Constructed dict with last edited operation included.
    """
    return build_operations(
        record_id=record_id,
        path="",
        args={"last_edited_by": user_id, "last_edited_time": now()},
        command="update",
    )
Пример #3
0
    def create_record(self, table: str, parent: Record, **kwargs):
        """
        Create new record.


        Arguments
        ---------
        table : str
            Table value.

        parent : Record
            Parent for the newly created record.


        Returns
        -------
        str
            ID of newly created record.
        """
        # make up a new UUID; apparently we get to choose our own!
        record_id = str(uuid.uuid4())
        child_list_key = kwargs.get("child_list_key") or parent.child_list_key

        args = {
            "id": record_id,
            "version": 1,
            "alive": True,
            "created_by": self.current_user.id,
            "created_time": now(),
            "parent_id": parent.id,
            "parent_table": parent._table,
            **kwargs,
        }

        with self.as_atomic_transaction():

            # create the new record
            self.submit_transaction(
                build_operation(
                    args=args, command="set", id=record_id, path=[], table=table
                )
            )

            # add the record to the content list of the parent, if needed
            if child_list_key:
                self.submit_transaction(
                    build_operation(
                        id=parent.id,
                        path=[child_list_key],
                        args={"id": record_id},
                        command="listAfter",
                        table=parent._table,
                    )
                )

        return record_id