diff --git a/changes/63.added b/changes/63.added new file mode 100644 index 0000000..3be2a6d --- /dev/null +++ b/changes/63.added @@ -0,0 +1 @@ +Added default statuses for floorplantile objects. \ No newline at end of file diff --git a/docs/admin/install.md b/docs/admin/install.md index 442cdb5..8d59bef 100644 --- a/docs/admin/install.md +++ b/docs/admin/install.md @@ -39,6 +39,10 @@ PLUGINS = ["nautobot_floor_plan"] PLUGINS_CONFIG = { "nautobot_floor_plan": { "default_x_axis_labels": "letters", + "default_statuses": { + "FloorPlanTile": [ + {"name": "Active", "color": "4caf50"}, + ], } } ``` @@ -69,3 +73,19 @@ The app behavior can be controlled with the following list of settings: |--------------------|-----------|----------|------------------------------------------------------------------------------------------------------------------------------------------------| | default_x_axis_labels | "letters" | "numbers" | Label style for the floor plan grid. Can use `numbers` or `letters` in order. This setting will set the default selected value in the create form. | | default_y_axis_labels | "numbers" | "numbers" | Label style for the floor plan grid. Can use `numbers` or `letters` in order. This setting will set the default selected value in the create form. | +| default_statuses| "name": "Active", "color": "4caf50"| See Note Below | A list of name and color key value pairs for the FloorPlanTile model| + +!!! note + Defaults for statuses are as follows: + + ```python + "default_statuses": { + "FloorPlanTile": [ + {"name": "Active", "color": "4caf50"}, + {"name": "Reserved", "color": "00bcd4"}, + {"name": "Decommissioning", "color": "ffc107"}, + {"name": "Unavailable", "color": "111111"}, + {"name": "Planned", "color": "00bcd4"}, + ], + }, + ``` diff --git a/docs/user/app_overview.md b/docs/user/app_overview.md index 9854204..2fdf3b1 100644 --- a/docs/user/app_overview.md +++ b/docs/user/app_overview.md @@ -48,4 +48,4 @@ This App: ### Extras -This App does not presently auto-define any Nautobot extras/extensibility features. To use this App fully, you will need to create or update one or more Status records that permit usage with the Floor Plan Tile model. +This App presently auto-defines Nautobot extras/extensibility status features. This app automatically assigns the following default statuses for use with Floor plan Tiles. `Active, Reserved, Decommissioning, Unavailable and Planned`. \ No newline at end of file diff --git a/nautobot_floor_plan/__init__.py b/nautobot_floor_plan/__init__.py index 05bbd02..b285f91 100644 --- a/nautobot_floor_plan/__init__.py +++ b/nautobot_floor_plan/__init__.py @@ -4,10 +4,10 @@ from importlib import metadata from django.core.exceptions import ImproperlyConfigured +from django.db.models.signals import post_migrate from nautobot.apps import NautobotAppConfig from nautobot.apps.config import get_app_settings_or_config - from nautobot_floor_plan.choices import AxisLabelsChoices __version__ = metadata.version(__name__) @@ -28,6 +28,15 @@ class FloorPlanConfig(NautobotAppConfig): default_settings = { "default_x_axis_labels": AxisLabelsChoices.NUMBERS, "default_y_axis_labels": AxisLabelsChoices.NUMBERS, + "default_statuses": { + "FloorPlanTile": [ + {"name": "Active", "color": "4caf50"}, + {"name": "Reserved", "color": "00bcd4"}, + {"name": "Decommissioning", "color": "ffc107"}, + {"name": "Unavailable", "color": "111111"}, + {"name": "Planned", "color": "00bcd4"}, + ], + }, } caching_config = {} docs_view_name = "plugins:nautobot_floor_plan:docs" @@ -44,6 +53,12 @@ def validate_config_options(self): def ready(self): """Callback after app is loaded.""" super().ready() + from .signals import ( # pylint: disable=import-outside-toplevel + post_migrate_create__add_statuses, + ) + + post_migrate.connect(post_migrate_create__add_statuses, sender=self) + self.validate_config_options() diff --git a/nautobot_floor_plan/app-config-schema.json b/nautobot_floor_plan/app-config-schema.json index 01e42ee..b1791ca 100644 --- a/nautobot_floor_plan/app-config-schema.json +++ b/nautobot_floor_plan/app-config-schema.json @@ -1,17 +1,36 @@ { - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://raw.githubusercontent.com/nautobot/nautobot-app-floor-plan/develop/nautobot_floor_plan/app-config-schema.json", - "$comment": "TBD: Update $id, replace `develop` with the future release tag", - "type": "object", - "properties": { - "default_x_axis_labels": { - "type": "string", - "default": "numbers" - }, - "default_y_axis_labels": { - "type": "string", - "default": "numbers" - } + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://raw.githubusercontent.com/nautobot/nautobot-app-floor-plan/develop/nautobot_floor_plan/app-config-schema.json", + "$comment": "TBD: Update $id, replace `develop` with the future release tag", + "type": "object", + "properties": { + "default_x_axis_labels": { + "type": "string", + "default": "numbers" + }, + "default_y_axis_labels": { + "type": "string", + "default": "numbers" }, - "additionalProperties": false + "default_statuses": { + "type": "object", + "properties": { + "FloorPlanTile": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "color": { + "type": "string" + } + } + } + } + } + } + }, + "additionalProperties": false } diff --git a/nautobot_floor_plan/signals.py b/nautobot_floor_plan/signals.py new file mode 100644 index 0000000..c0383c8 --- /dev/null +++ b/nautobot_floor_plan/signals.py @@ -0,0 +1,25 @@ +"""Signals for the Floor Plan App.""" + +from django.apps import apps as global_apps +from django.conf import settings + +PLUGIN_SETTINGS = settings.PLUGINS_CONFIG["nautobot_floor_plan"] + + +def post_migrate_create__add_statuses(sender, *, apps=global_apps, **kwargs): + """Callback function for post_migrate() -- create default Statuses.""" + # pylint: disable=invalid-name + if not apps: + return + + Status = apps.get_model("extras", "Status") + ContentType = apps.get_model("contenttypes", "ContentType") + + for model_name, default_statuses in PLUGIN_SETTINGS.get("default_statuses", {}).items(): + model = sender.get_model(model_name) + for status in default_statuses: + ct_status, _ = Status.objects.get_or_create(name=status["name"], defaults={"color": status["color"]}) + ct_model = ContentType.objects.get_for_model(model) + if ct_model not in ct_status.content_types.all(): + ct_status.content_types.add(ct_model) + ct_status.save() diff --git a/tasks.py b/tasks.py index 44e9290..80e4dcc 100644 --- a/tasks.py +++ b/tasks.py @@ -48,7 +48,7 @@ def is_truthy(arg): namespace.configure( { "nautobot_floor_plan": { - "nautobot_ver": "2.0.0", + "nautobot_ver": "2.2.8", "project_name": "nautobot-floor-plan", "python_ver": "3.11", "local": False,