Skip to content

Commit

Permalink
Merge pull request #112 from nautobot/release/v2.3.0
Browse files Browse the repository at this point in the history
Release v2.3.0
  • Loading branch information
gsnider2195 authored Aug 7, 2024
2 parents 1f982d1 + 968c23e commit ba8af55
Show file tree
Hide file tree
Showing 22 changed files with 407 additions and 54 deletions.
1 change: 0 additions & 1 deletion changes/104.housekeeping

This file was deleted.

5 changes: 4 additions & 1 deletion docs/admin/compatibility_matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ Because this App depends on Nautobot's `Location` data model, which was introduc
| Nautobot Floor Plan Version | Nautobot First Support Version | Nautobot Last Support Version |
| --------------------------- | ------------------------------ | ----------------------------- |
| 1.0.X | 1.4.0 | 1.99.99 |
| 2.0.X | 2.0.0 | 2.99.99 |
| 2.0.X | 2.0.0 | 2.2.99 |
| 2.1.X | 2.0.0 | 2.2.99 |
| 2.2.X | 2.0.0 | 2.2.99 |
| 2.3.X | 2.0.0 | 2.99.99 |
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"},
],
},
```
20 changes: 20 additions & 0 deletions docs/admin/release_notes/version_2.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# v2.3 Release Notes

This document describes all new features and changes in the release `2.3`. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Release Overview

This release introduces the ability to use a custom seed to use as the starting point for the x and y grid coordinates in a floor plan. It also adds support for Nautobot v2.3.0.

<!-- towncrier release notes start -->
## [v2.3.0 (2024-08-07)](https://github.com/nautobot/nautobot-app-floor-plan/releases/tag/v2.3.0)

### Added

- [#8](https://github.com/nautobot/nautobot-app-floor-plan/issues/8) - Added grid seed option to FloorPlan.
- [#63](https://github.com/nautobot/nautobot-app-floor-plan/issues/63) - Added default statuses for floorplantile objects.
- [#109](https://github.com/nautobot/nautobot-app-floor-plan/issues/109) - Added Django 4 support.

### Housekeeping

- [#111](https://github.com/nautobot/nautobot-app-floor-plan/issues/111) - Fixed conflicting migration files caused by parallel PRs.
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`.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ nav:
- v2.0: "admin/release_notes/version_2.0.md"
- v2.1: "admin/release_notes/version_2.1.md"
- v2.2: "admin/release_notes/version_2.2.md"
- v2.3: "admin/release_notes/version_2.3.md"
- Developer Guide:
- Extending the App: "dev/extending.md"
- Contributing to the App: "dev/contributing.md"
Expand Down
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
post_migrate_create__add_statuses,
)

post_migrate.connect(post_migrate_create__add_statuses, sender=self)

self.validate_config_options()


Expand Down
47 changes: 33 additions & 14 deletions nautobot_floor_plan/app-config-schema.json
Original file line number Diff line number Diff line change
@@ -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
}
54 changes: 54 additions & 0 deletions nautobot_floor_plan/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ class FloorPlanForm(NautobotModelForm):

location = DynamicModelChoiceField(queryset=Location.objects.all())

x_origin_seed = forms.CharField(
label="X Axis Seed",
help_text="The first value to begin X Axis at.",
required=False,
)
y_origin_seed = forms.CharField(
label="Y Axis Seed",
help_text="The first value to begin Y Axis at.",
required=False,
)

class Meta:
"""Meta attributes."""

Expand All @@ -38,16 +49,59 @@ class Meta:
"tile_width",
"tile_depth",
"x_axis_labels",
"x_origin_seed",
"y_axis_labels",
"y_origin_seed",
"tags",
]

def __init__(self, *args, **kwargs):
"""Overwrite the constructor to set initial values for select widget."""
super().__init__(*args, **kwargs)

if not self.instance.created:
self.initial["x_axis_labels"] = get_app_settings_or_config("nautobot_floor_plan", "default_x_axis_labels")
self.initial["y_axis_labels"] = get_app_settings_or_config("nautobot_floor_plan", "default_y_axis_labels")
self.x_letters = self.initial["x_axis_labels"] == choices.AxisLabelsChoices.LETTERS
self.y_letters = self.initial["y_axis_labels"] == choices.AxisLabelsChoices.LETTERS
self.initial["x_origin_seed"] = "A" if self.x_letters else "1"
self.initial["y_origin_seed"] = "A" if self.y_letters else "1"
else:
self.x_letters = self.instance.x_axis_labels == choices.AxisLabelsChoices.LETTERS
self.y_letters = self.instance.y_axis_labels == choices.AxisLabelsChoices.LETTERS

if self.x_letters and str(self.initial["y_origin_seed"]).isdigit():
self.initial["x_origin_seed"] = utils.grid_number_to_letter(self.instance.x_origin_seed)
if self.y_letters and str(self.initial["y_origin_seed"]).isdigit():
self.initial["y_origin_seed"] = utils.grid_number_to_letter(self.instance.y_origin_seed)

def _clean_origin_seed(self, field_name, axis):
"""Common clean method for origin_seed fields."""
value = self.cleaned_data.get(field_name)
if not value:
return 1

self.x_letters = self.cleaned_data.get("x_axis_labels") == choices.AxisLabelsChoices.LETTERS
self.y_letters = self.cleaned_data.get("y_axis_labels") == choices.AxisLabelsChoices.LETTERS

if self.x_letters and field_name == "x_origin_seed" or self.y_letters and field_name == "y_origin_seed":
if not str(value).isupper():
self.add_error(field_name, f"{axis} origin start should use capital letters.")
return 0
return utils.grid_letter_to_number(value)

if not str(value).isdigit():
self.add_error(field_name, f"{axis} origin start should use numbers.")
return 0
return int(value)

def clean_x_origin_seed(self):
"""Validate input and convert y_origin to an integer."""
return self._clean_origin_seed("x_origin_seed", "X")

def clean_y_origin_seed(self):
"""Validate input and convert y_origin to an integer."""
return self._clean_origin_seed("y_origin_seed", "Y")


class FloorPlanBulkEditForm(TagsBulkEditFormMixin, NautobotBulkEditForm):
Expand Down
22 changes: 22 additions & 0 deletions nautobot_floor_plan/migrations/0006_alter_floorplantile_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.14 on 2024-08-07 15:39

from django.db import migrations
import django.db.models.deletion
import nautobot.extras.models.statuses


class Migration(migrations.Migration):

dependencies = [
("nautobot_floor_plan", "0005_add_rackgroup"),
]

operations = [
migrations.AlterField(
model_name="floorplantile",
name="status",
field=nautobot.extras.models.statuses.StatusField(
on_delete=django.db.models.deletion.PROTECT, to="extras.status"
),
),
]
34 changes: 34 additions & 0 deletions nautobot_floor_plan/migrations/0007_add_axis_origin_seed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 3.2.25 on 2024-07-23 21:59

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("nautobot_floor_plan", "0006_alter_floorplantile_status"),
]

operations = [
migrations.AddField(
model_name="floorplan",
name="x_origin_seed",
field=models.PositiveSmallIntegerField(default=1, validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AddField(
model_name="floorplan",
name="y_origin_seed",
field=models.PositiveSmallIntegerField(default=1, validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name="floorplantile",
name="x_origin",
field=models.PositiveSmallIntegerField(validators=[django.core.validators.MinValueValidator(0)]),
),
migrations.AlterField(
model_name="floorplantile",
name="y_origin",
field=models.PositiveSmallIntegerField(validators=[django.core.validators.MinValueValidator(0)]),
),
]
Loading

0 comments on commit ba8af55

Please sign in to comment.