-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implements view for design model
- Loading branch information
1 parent
24a473a
commit 02e78c4
Showing
17 changed files
with
1,173 additions
and
843 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Nested serializers for design builder.""" | ||
from nautobot.core.api import BaseModelSerializer | ||
from rest_framework.relations import HyperlinkedIdentityField | ||
|
||
from design_builder.models import Design | ||
|
||
|
||
class NestedDesignSerializer(BaseModelSerializer): | ||
"""Nested serializer for the design model.""" | ||
|
||
url = HyperlinkedIdentityField(view_name="plugins-api:design_builder-api:design-detail") | ||
|
||
class Meta: | ||
"""Nested serializer options for the design model.""" | ||
|
||
model = Design | ||
fields = ["id", "url", "name"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"""Serializers for design builder.""" | ||
from nautobot.apps.api import NautobotModelSerializer, TaggedModelSerializerMixin | ||
from rest_framework.relations import HyperlinkedIdentityField | ||
|
||
from design_builder.models import Design | ||
|
||
# We need to import the nested serializers, so they can be auto-discovered as the serializer for the ?brief | ||
# URL parameter variant. | ||
from design_builder.api.nested_serializers import ( # pylint: disable=unused-import # noqa: F401 | ||
NestedDesignSerializer, | ||
) | ||
|
||
|
||
class DesignSerializer(NautobotModelSerializer, TaggedModelSerializerMixin): | ||
"""Serializer for the design model.""" | ||
|
||
url = HyperlinkedIdentityField(view_name="plugins-api:design_builder-api:design-detail") | ||
|
||
class Meta: | ||
"""Serializer options for the design model.""" | ||
|
||
model = Design | ||
fields = [ | ||
"id", | ||
"url", | ||
"name", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""API URLs for design builder.""" | ||
from nautobot.core.api import OrderedDefaultRouter | ||
from design_builder.api.views import DesignViewSet | ||
|
||
router = OrderedDefaultRouter() | ||
|
||
router.register("designs", DesignViewSet) | ||
|
||
urlpatterns = router.urls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""UI Views for design builder.""" | ||
from nautobot.extras.api.views import NautobotModelViewSet | ||
|
||
from design_builder.api.serializers import DesignSerializer | ||
from design_builder.filters import DesignFilterSet | ||
from design_builder.models import Design | ||
|
||
|
||
class DesignViewSet(NautobotModelViewSet): | ||
"""API views for the design model.""" | ||
|
||
queryset = Design.objects.all() | ||
serializer_class = DesignSerializer | ||
filterset_class = DesignFilterSet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from nautobot.apps.filters import NautobotFilterSet, NaturalKeyOrPKMultipleChoiceFilter | ||
from nautobot.extras.models import Job | ||
|
||
from design_builder.models import Design | ||
|
||
|
||
class DesignFilterSet(NautobotFilterSet): | ||
"""Filter set for the design model.""" | ||
|
||
job = NaturalKeyOrPKMultipleChoiceFilter( | ||
queryset=Job.objects.all(), | ||
label="Job (ID or slug)", | ||
) | ||
|
||
class Meta: | ||
"""Meta attributes for filter.""" | ||
|
||
model = Design | ||
fields = ["id", "job"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from nautobot.extras.forms import NautobotFilterForm, NautobotModelForm | ||
from nautobot.extras.models import Job | ||
from nautobot.utilities.forms import TagFilterField, DynamicModelChoiceField | ||
|
||
from design_builder.models import Design | ||
|
||
|
||
class DesignFilterForm(NautobotFilterForm): | ||
model = Design | ||
|
||
job = DynamicModelChoiceField(queryset=Job.objects.all()) | ||
tag = TagFilterField(model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from nautobot.apps.ui import ( | ||
NavMenuGroup, | ||
NavMenuItem, | ||
NavMenuTab, | ||
) | ||
|
||
|
||
menu_items = ( | ||
NavMenuTab( | ||
name="Jobs", | ||
weight=150, | ||
groups=( | ||
NavMenuGroup( | ||
name="Designs", | ||
weight=100, | ||
items=( | ||
NavMenuItem( | ||
link="plugins:design_builder:design_list", | ||
name="Designs", | ||
permissions=["design_builder.view_designs"], | ||
buttons=(), | ||
), | ||
), | ||
), | ||
), | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
"""Tables for design builder.""" | ||
from django_tables2 import Column | ||
from django_tables2.utils import Accessor | ||
from nautobot.apps.tables import StatusTableMixin, BaseTable | ||
from nautobot.utilities.tables import ToggleColumn | ||
|
||
from design_builder.models import Design | ||
|
||
|
||
class DesignTable(StatusTableMixin, BaseTable): | ||
"""Table for list view.""" | ||
|
||
pk = ToggleColumn() | ||
job = Column(linkify=True) | ||
name = Column(linkify=True) | ||
|
||
class Meta(BaseTable.Meta): | ||
"""Meta attributes.""" | ||
|
||
model = Design | ||
fields = ("pk", "name", "job", "status") |
22 changes: 22 additions & 0 deletions
22
design_builder/templates/design_builder/design_retrieve.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends 'generic/object_retrieve.html' %} | ||
{% load helpers %} | ||
|
||
{% block content_left_page %} | ||
<div class="panel panel-default"> | ||
<div class="panel-heading"> | ||
<strong>Design</strong> | ||
</div> | ||
<table class="table table-hover panel-body attr-table"> | ||
<tr> | ||
<td>Status</td> | ||
<td> | ||
<span class="label" style="color: {{ object.status.color|fgcolor }}; background-color: #{{ object.status.color }}">{{ object.get_status_display }}</span> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>Job</td> | ||
<td>{{ object.job|hyperlinked_object }}</td> | ||
</tr> | ||
</table> | ||
</div> | ||
{% endblock content_left_page %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import unittest | ||
|
||
from nautobot.extras.models import Job | ||
from nautobot.utilities.testing import APIViewTestCases | ||
|
||
from design_builder.models import Design | ||
|
||
|
||
class DesignTest( | ||
APIViewTestCases.GetObjectViewTestCase, | ||
APIViewTestCases.ListObjectsViewTestCase, | ||
APIViewTestCases.NotesURLViewTestCase, | ||
): | ||
model = Design | ||
brief_fields = ["display", "id", "name", "url"] | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
job_1 = Job.objects.create(name="Fake Design Job 1") | ||
job_2 = Job.objects.create(name="Fake Design Job 2") | ||
job_3 = Job.objects.create(name="Fake Design Job 3") | ||
Design.objects.create(job=job_1) | ||
Design.objects.create(job=job_2) | ||
Design.objects.create(job=job_3) | ||
|
||
@unittest.skip | ||
def test_list_objects_unknown_filter_no_strict_filtering(self): | ||
"""Currently broken, don't know why.""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import unittest | ||
|
||
from django.test.utils import override_settings | ||
from nautobot.extras.models import Job | ||
from nautobot.utilities.testing import ViewTestCases | ||
|
||
from design_builder.models import Design | ||
|
||
|
||
class DesignTestCase( | ||
ViewTestCases.GetObjectViewTestCase, | ||
ViewTestCases.GetObjectChangelogViewTestCase, | ||
ViewTestCases.GetObjectNotesViewTestCase, | ||
ViewTestCases.ListObjectsViewTestCase, | ||
): | ||
model = Design | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
job_1 = Job.objects.create(name="Fake Design Job 1") | ||
job_2 = Job.objects.create(name="Fake Design Job 2") | ||
Design.objects.create(job=job_1) | ||
Design.objects.create(job=job_2) | ||
|
||
@unittest.skip | ||
def test_list_objects_unknown_filter_no_strict_filtering(self): | ||
"""Broken, don't know why.""" | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"""UI URLs for design builder.""" | ||
from nautobot.core.views.routers import NautobotUIViewSetRouter | ||
|
||
from design_builder.views import DesignUIViewSet | ||
|
||
router = NautobotUIViewSetRouter() | ||
router.register("designs", DesignUIViewSet) | ||
|
||
urlpatterns = router.urls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""UI Views for design builder.""" | ||
from nautobot.core.views.mixins import ( | ||
ObjectDetailViewMixin, | ||
ObjectListViewMixin, | ||
ObjectChangeLogViewMixin, | ||
ObjectNotesViewMixin, | ||
) | ||
|
||
from design_builder.api.serializers import DesignSerializer | ||
from design_builder.filters import DesignFilterSet | ||
from design_builder.forms import DesignFilterForm | ||
from design_builder.models import Design | ||
from design_builder.tables import DesignTable | ||
|
||
|
||
class DesignUIViewSet( | ||
ObjectDetailViewMixin, | ||
ObjectListViewMixin, | ||
ObjectChangeLogViewMixin, | ||
ObjectNotesViewMixin, | ||
): | ||
"""UI views for the design model.""" | ||
|
||
filterset_class = DesignFilterSet | ||
filterset_form_class = DesignFilterForm | ||
queryset = Design.objects.all() | ||
serializer_class = DesignSerializer | ||
table_class = DesignTable | ||
action_buttons = () | ||
lookup_field = "pk" |
Oops, something went wrong.