{ "cells": [ { "cell_type": "markdown", "id": "878870c6", "metadata": {}, "source": [ "# Publishing, revising, and withdrawing record lists\n", "This example shows how to connect to Granta MI and perform advanced operations on record lists,\n", "such as publishing, withdrawing, and revising a list. For more information about the concepts\n", "discussed here, see the Help in the Granta MI Favorites app." ] }, { "cell_type": "markdown", "id": "6def2345", "metadata": {}, "source": [ ".. note:: Running this notebook requires permissions to request publication of, to publish, and to\n", "revise a record list. Contact your Granta MI administrator for more information." ] }, { "cell_type": "markdown", "id": "226e73fb", "metadata": {}, "source": [ "## Connect to Granta MI and create a record list" ] }, { "cell_type": "markdown", "id": "d88c028b", "metadata": {}, "source": [ "Import the ``Connection`` class and create the connection. See the\n", "[Getting started](00_basic_usage.ipynb) example for more details." ] }, { "cell_type": "code", "execution_count": null, "id": "d27a5a63", "metadata": { "tags": [] }, "outputs": [], "source": [ "from ansys.grantami.recordlists import Connection\n", "\n", "connection = Connection(\"http://my_grantami_server/mi_servicelayer\").with_autologon()\n", "client = connection.connect()" ] }, { "cell_type": "markdown", "id": "db231a74", "metadata": {}, "source": [ "Create a record list for use in this example." ] }, { "cell_type": "code", "execution_count": null, "id": "d2d6476b", "metadata": { "tags": [] }, "outputs": [], "source": [ "example_list = client.create_list(\n", " name=\"Example list\",\n", " description=f\"Created by example 01_Advanced_usage\",\n", ")\n", "example_list" ] }, { "cell_type": "markdown", "id": "730ee8cb", "metadata": { "lines_to_next_cell": 2 }, "source": [ "Record lists include two properties describing two aspects of their status: whether they are\n", "awaiting approval to be published, and whether they are currently published.\n", "Define a function to display the status properties." ] }, { "cell_type": "code", "execution_count": null, "id": "3a3ed35c", "metadata": { "tags": [] }, "outputs": [], "source": [ "def print_status(record_list):\n", " print(f\"Awaiting approval: {record_list.awaiting_approval}\")\n", " print(f\"Published: {record_list.published}\")\n", "\n", "\n", "print_status(example_list)" ] }, { "cell_type": "markdown", "id": "5a610875", "metadata": {}, "source": [ "## Publish a record list" ] }, { "cell_type": "markdown", "id": "99bde667", "metadata": {}, "source": [ "A record list is proposed for publication by calling the ``request_list_approval`` method with the\n", "record list to be published." ] }, { "cell_type": "code", "execution_count": null, "id": "e563d3d0", "metadata": { "tags": [] }, "outputs": [], "source": [ "updated_list = client.request_list_approval(example_list)\n", "\n", "print_status(updated_list)" ] }, { "cell_type": "markdown", "id": "c6a743ab", "metadata": {}, "source": [ "Publish the record list by using the ``publish_list`` method." ] }, { "cell_type": "code", "execution_count": null, "id": "9599e30d", "metadata": { "tags": [] }, "outputs": [], "source": [ "updated_list = client.publish_list(example_list)\n", "\n", "print_status(updated_list)" ] }, { "cell_type": "markdown", "id": "72a04de6", "metadata": {}, "source": [ "## Revise a record list" ] }, { "cell_type": "markdown", "id": "2dce31ff", "metadata": {}, "source": [ "A published record list cannot be modified directly. Instead, first create a revision of the\n", "published record list using the ``revise_list`` method. This creates an editable copy of the\n", "original record list (a list revision), and leaves the original record list unchanged." ] }, { "cell_type": "code", "execution_count": null, "id": "93083e73", "metadata": { "tags": [] }, "outputs": [], "source": [ "revision_list = client.revise_list(example_list)\n", "\n", "print_status(revision_list)" ] }, { "cell_type": "markdown", "id": "bbafe61a", "metadata": {}, "source": [ "The record list revision includes a property tracking the parent record list:" ] }, { "cell_type": "code", "execution_count": null, "id": "7745f87a", "metadata": { "tags": [] }, "outputs": [], "source": [ "print(f\"Is revision: {revision_list.is_revision}\")\n", "print(f\"Parent identifier: {revision_list.parent_record_list_identifier}\")" ] }, { "cell_type": "markdown", "id": "d4b4e973", "metadata": {}, "source": [ "Modifications made to the list revision are applied to the original list when the list revision\n", "is published. Once the original list is updated, the list revision is deleted and is no longer\n", "available." ] }, { "cell_type": "code", "execution_count": null, "id": "e1794605", "metadata": { "tags": [] }, "outputs": [], "source": [ "updated_revision_list = client.update_list(revision_list, notes=\"Added during revision process\")\n", "updated_revision_list = client.request_list_approval(updated_revision_list)\n", "updated_original_list = client.publish_list(updated_revision_list)\n", "\n", "# When publishing a revision list, the returned object is the updated parent list.\n", "# Check the notes of the list to confirm the revisions were made successfully.\n", "print(f\"Notes: {updated_original_list.notes}\")\n", "print(f\"Is published: {updated_original_list.published}\")" ] }, { "cell_type": "markdown", "id": "bcb50b9f", "metadata": {}, "source": [ "## Withdraw a record list\n", "When a record list is in the published state, calling ``request_list_approval`` requests the\n", "withdrawal of that list." ] }, { "cell_type": "code", "execution_count": null, "id": "aed7dc22", "metadata": { "tags": [] }, "outputs": [], "source": [ "updated_list = client.request_list_approval(example_list)\n", "\n", "print_status(updated_list)" ] }, { "cell_type": "markdown", "id": "b9e9e7f9", "metadata": {}, "source": [ "Use the ``unpublish_list`` method to withdraw a record list." ] }, { "cell_type": "code", "execution_count": null, "id": "f0782c42", "metadata": { "tags": [] }, "outputs": [], "source": [ "updated_list = client.unpublish_list(example_list)\n", "\n", "print_status(updated_list)" ] }, { "cell_type": "code", "execution_count": null, "id": "b00cc270", "metadata": { "nbsphinx": "hidden" }, "outputs": [], "source": [ "client.delete_list(example_list)" ] } ], "metadata": { "jupytext": { "formats": "ipynb,py:light" }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }