Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added default statuses for floorplantiles, updated app schema for new… #107

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/63.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added default statuses for floorplantile objects.
20 changes: 20 additions & 0 deletions docs/admin/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
],
}
}
```
Expand Down Expand Up @@ -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"},
],
},
```
2 changes: 1 addition & 1 deletion docs/user/app_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
17 changes: 16 additions & 1 deletion nautobot_floor_plan/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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"
Expand All @@ -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
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved
post_migrate_create__add_statuses,
)

post_migrate.connect(post_migrate_create__add_statuses, sender=self)

self.validate_config_options()


Expand Down
27 changes: 23 additions & 4 deletions nautobot_floor_plan/app-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,26 @@
"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
}
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved
}
26 changes: 26 additions & 0 deletions nautobot_floor_plan/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""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:
Status.objects.get_or_create(name=status["name"], defaults={"color": status["color"]})
ct_status = Status.objects.get(name=status["name"])
djhoward12 marked this conversation as resolved.
Show resolved Hide resolved
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()
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down