From 46ecb0ac03556cc930aef8218ca8134da4a25fcb Mon Sep 17 00:00:00 2001 From: Daniel Sheppard Date: Wed, 2 Jun 2021 22:45:17 -0500 Subject: [PATCH 01/10] Fixes: #6432 - Properly mark nat_outside as read-only and not-required. --- netbox/ipam/api/serializers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/netbox/ipam/api/serializers.py b/netbox/ipam/api/serializers.py index afd3fb4fe..ac1b68ab5 100644 --- a/netbox/ipam/api/serializers.py +++ b/netbox/ipam/api/serializers.py @@ -274,7 +274,7 @@ class IPAddressSerializer(PrimaryModelSerializer): ) assigned_object = serializers.SerializerMethodField(read_only=True) nat_inside = NestedIPAddressSerializer(required=False, allow_null=True) - nat_outside = NestedIPAddressSerializer(read_only=True) + nat_outside = NestedIPAddressSerializer(required=False, read_only=True) class Meta: model = IPAddress @@ -283,7 +283,7 @@ class IPAddressSerializer(PrimaryModelSerializer): 'assigned_object_id', 'assigned_object', 'nat_inside', 'nat_outside', 'dns_name', 'description', 'tags', 'custom_fields', 'created', 'last_updated', ] - read_only_fields = ['family'] + read_only_fields = ['family', 'nat_outside'] @swagger_serializer_method(serializer_or_field=serializers.DictField) def get_assigned_object(self, obj): From e61b2b1fc5069ddf2f1c04cb76c3cb2454e775e7 Mon Sep 17 00:00:00 2001 From: maxime-gerges-external Date: Thu, 3 Jun 2021 14:48:18 +0200 Subject: [PATCH 02/10] feat: markdown support in report's description * markdown support in report list and report result pages * Add notes in the documentation regarding markdown --- docs/additional-features/reports.md | 6 ++++++ netbox/templates/extras/report.html | 2 +- netbox/templates/extras/report_list.html | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/docs/additional-features/reports.md b/docs/additional-features/reports.md index bac1003fd..3df1ff900 100644 --- a/docs/additional-features/reports.md +++ b/docs/additional-features/reports.md @@ -85,6 +85,9 @@ As you can see, reports are completely customizable. Validation logic can be as !!! warning Reports should never alter data: If you find yourself using the `create()`, `save()`, `update()`, or `delete()` methods on objects within reports, stop and re-evaluate what you're trying to accomplish. Note that there are no safeguards against the accidental alteration or destruction of data. +!!! note + The `description`attribute support markdown syntax. You can use markdown to print fency description in the report list page. + The following methods are available to log results within a report: * log(message) @@ -95,6 +98,9 @@ The following methods are available to log results within a report: The recording of one or more failure messages will automatically flag a report as failed. It is advised to log a success for each object that is evaluated so that the results will reflect how many objects are being reported on. (The inclusion of a log message is optional for successes.) Messages recorded with `log()` will appear in a report's results but are not associated with a particular object or status. +!!! note + Every `log_`methods support markdown syntax. Thus you can use markdown in the message and it will be printed as such in the report result. + To perform additional tasks, such as sending an email or calling a webhook, after a report has been run, extend the `post_run()` method. The status of the report is available as `self.failed` and the results object is `self.result`. Once you have created a report, it will appear in the reports list. Initially, reports will have no results associated with them. To generate results, run the report. diff --git a/netbox/templates/extras/report.html b/netbox/templates/extras/report.html index f2c5edf23..82c3f3042 100644 --- a/netbox/templates/extras/report.html +++ b/netbox/templates/extras/report.html @@ -29,7 +29,7 @@ {% endif %}

{{ report.name }}

{% if report.description %} -

{{ report.description }}

+

{{ report.description|render_markdown }}

{% endif %} {% endblock %} diff --git a/netbox/templates/extras/report_list.html b/netbox/templates/extras/report_list.html index 7685cdacf..525a40d12 100644 --- a/netbox/templates/extras/report_list.html +++ b/netbox/templates/extras/report_list.html @@ -29,7 +29,7 @@ {% include 'extras/inc/job_label.html' with result=report.result %} - {{ report.description|placeholder }} + {{ report.description|render_markdown|placeholder }} {% if report.result %} {{ report.result.created }} From 10c9954ebcdc9633bd0e09ad9464712826647960 Mon Sep 17 00:00:00 2001 From: maximumG Date: Thu, 3 Jun 2021 20:36:52 +0200 Subject: [PATCH 03/10] fix: remove call-outs regarding markdown support --- docs/additional-features/reports.md | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/docs/additional-features/reports.md b/docs/additional-features/reports.md index 3df1ff900..0d75abd21 100644 --- a/docs/additional-features/reports.md +++ b/docs/additional-features/reports.md @@ -80,14 +80,11 @@ class DeviceConnectionsReport(Report): self.log_success(device) ``` -As you can see, reports are completely customizable. Validation logic can be as simple or as complex as needed. +As you can see, reports are completely customizable. Validation logic can be as simple or as complex as needed. Also note that the `description` attribute support markdown syntax. It will be rendered in the report list page. !!! warning Reports should never alter data: If you find yourself using the `create()`, `save()`, `update()`, or `delete()` methods on objects within reports, stop and re-evaluate what you're trying to accomplish. Note that there are no safeguards against the accidental alteration or destruction of data. -!!! note - The `description`attribute support markdown syntax. You can use markdown to print fency description in the report list page. - The following methods are available to log results within a report: * log(message) @@ -96,10 +93,7 @@ The following methods are available to log results within a report: * log_warning(object, message) * log_failure(object, message) -The recording of one or more failure messages will automatically flag a report as failed. It is advised to log a success for each object that is evaluated so that the results will reflect how many objects are being reported on. (The inclusion of a log message is optional for successes.) Messages recorded with `log()` will appear in a report's results but are not associated with a particular object or status. - -!!! note - Every `log_`methods support markdown syntax. Thus you can use markdown in the message and it will be printed as such in the report result. +The recording of one or more failure messages will automatically flag a report as failed. It is advised to log a success for each object that is evaluated so that the results will reflect how many objects are being reported on. (The inclusion of a log message is optional for successes.) Messages recorded with `log()` will appear in a report's results but are not associated with a particular object or status. Log messages also support using markdown syntax and will be rendered on the report result page. To perform additional tasks, such as sending an email or calling a webhook, after a report has been run, extend the `post_run()` method. The status of the report is available as `self.failed` and the results object is `self.result`. From d74dbb722a0a77f092709f4a7fd8207051983910 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Jun 2021 17:20:24 -0400 Subject: [PATCH 04/10] Changelog for #6527 --- docs/release-notes/version-2.11.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index 43ea4d5f6..efc68c1a9 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -7,6 +7,7 @@ * [#6087](https://github.com/netbox-community/netbox/issues/6087) - Improved prefix hierarchy rendering * [#6487](https://github.com/netbox-community/netbox/issues/6487) - Add location filter to cable connection form * [#6501](https://github.com/netbox-community/netbox/issues/6501) - Expose prefix depth and children on REST API serializer +* [#6527](https://github.com/netbox-community/netbox/issues/6527) - Support Markdown for report descriptions ### Bug Fixes From 04c1619eb48155a0e2f96c3609407b25a7053e30 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Jun 2021 20:27:24 -0400 Subject: [PATCH 05/10] Remove unused function --- .../migrations/0048_prefix_populate_depth_children.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/netbox/ipam/migrations/0048_prefix_populate_depth_children.py b/netbox/ipam/migrations/0048_prefix_populate_depth_children.py index b1c2136b8..279f899f6 100644 --- a/netbox/ipam/migrations/0048_prefix_populate_depth_children.py +++ b/netbox/ipam/migrations/0048_prefix_populate_depth_children.py @@ -4,17 +4,6 @@ from django.db import migrations from ipam.utils import rebuild_prefixes -def push_to_stack(stack, prefix): - # Increment child count on parent nodes - for n in stack: - n['children'] += 1 - stack.append({ - 'pk': prefix['pk'], - 'prefix': prefix['prefix'], - 'children': 0, - }) - - def populate_prefix_hierarchy(apps, schema_editor): """ Populate _depth and _children attrs for all Prefixes. From 5c263fac8d25296940f9d84a781b81569c3c1513 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Jun 2021 20:31:09 -0400 Subject: [PATCH 06/10] Closes #6540: Add a 'flat' column to the prefix table --- docs/release-notes/version-2.11.md | 1 + netbox/ipam/tables.py | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/release-notes/version-2.11.md b/docs/release-notes/version-2.11.md index efc68c1a9..75f8662cd 100644 --- a/docs/release-notes/version-2.11.md +++ b/docs/release-notes/version-2.11.md @@ -8,6 +8,7 @@ * [#6487](https://github.com/netbox-community/netbox/issues/6487) - Add location filter to cable connection form * [#6501](https://github.com/netbox-community/netbox/issues/6501) - Expose prefix depth and children on REST API serializer * [#6527](https://github.com/netbox-community/netbox/issues/6527) - Support Markdown for report descriptions +* [#6540](https://github.com/netbox-community/netbox/issues/6540) - Add a "flat" column to the prefix table ### Bug Fixes diff --git a/netbox/ipam/tables.py b/netbox/ipam/tables.py index 740441b42..c564985f7 100644 --- a/netbox/ipam/tables.py +++ b/netbox/ipam/tables.py @@ -262,6 +262,11 @@ class PrefixTable(BaseTable): template_code=PREFIX_LINK, attrs={'td': {'class': 'text-nowrap'}} ) + prefix_flat = tables.Column( + accessor=Accessor('prefix'), + linkify=True, + verbose_name='Prefix (Flat)' + ) depth = tables.Column( accessor=Accessor('_depth'), verbose_name='Depth' @@ -300,8 +305,8 @@ class PrefixTable(BaseTable): class Meta(BaseTable.Meta): model = Prefix fields = ( - 'pk', 'prefix', 'status', 'depth', 'children', 'vrf', 'tenant', 'site', 'vlan', 'role', 'is_pool', - 'description', + 'pk', 'prefix', 'prefix_flat', 'status', 'depth', 'children', 'vrf', 'tenant', 'site', 'vlan', 'role', + 'is_pool', 'description', ) default_columns = ('pk', 'prefix', 'status', 'vrf', 'tenant', 'site', 'vlan', 'role', 'description') row_attrs = { @@ -314,15 +319,14 @@ class PrefixDetailTable(PrefixTable): accessor='get_utilization', orderable=False ) - tenant = TenantColumn() tags = TagColumn( url_name='ipam:prefix_list' ) class Meta(PrefixTable.Meta): fields = ( - 'pk', 'prefix', 'status', 'children', 'vrf', 'utilization', 'tenant', 'site', 'vlan', 'role', 'is_pool', - 'description', 'tags', + 'pk', 'prefix', 'prefix_flat', 'status', 'children', 'vrf', 'utilization', 'tenant', 'site', 'vlan', 'role', + 'is_pool', 'description', 'tags', ) default_columns = ( 'pk', 'prefix', 'status', 'children', 'vrf', 'utilization', 'tenant', 'site', 'vlan', 'role', 'description', From b725a9bceafba33ad8b1fa9cae9a3e1a96b4fac0 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Jun 2021 20:35:53 -0400 Subject: [PATCH 07/10] Closes #6495: Replace 'help' link in footer with 'community' --- netbox/templates/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netbox/templates/base.html b/netbox/templates/base.html index 155c0d9b2..3a169d965 100644 --- a/netbox/templates/base.html +++ b/netbox/templates/base.html @@ -74,7 +74,7 @@ Docs · API · Code · - Help + Community

From b3a14e9a7b86b6721922722d9f4b54e15a975a7d Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 3 Jun 2021 21:11:45 -0400 Subject: [PATCH 08/10] Improve performance when fetching objects for bulk edit --- netbox/netbox/views/generic.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/netbox/netbox/views/generic.py b/netbox/netbox/views/generic.py index 8f713fa63..8a2bae4fa 100644 --- a/netbox/netbox/views/generic.py +++ b/netbox/netbox/views/generic.py @@ -774,9 +774,7 @@ class BulkEditView(GetReturnURLMixin, ObjectPermissionRequiredMixin, View): # If we are editing *all* objects in the queryset, replace the PK list with all matched objects. if request.POST.get('_all') and self.filterset is not None: - pk_list = [ - obj.pk for obj in self.filterset(request.GET, self.queryset.only('pk')).qs - ] + pk_list = self.filterset(request.GET, self.queryset.values_list('pk', flat=True)).qs else: pk_list = request.POST.getlist('pk') From 4e1e5bd8c45e1b988ae95c685957349186ee0f35 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 4 Jun 2021 09:01:58 -0400 Subject: [PATCH 09/10] Fix "select all" box (again) --- netbox/templates/generic/object_list.html | 92 +++++++++++------------ 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/netbox/templates/generic/object_list.html b/netbox/templates/generic/object_list.html index e37676286..5138f4639 100644 --- a/netbox/templates/generic/object_list.html +++ b/netbox/templates/generic/object_list.html @@ -29,58 +29,58 @@ {% block sidebar %}{% endblock %} {% endif %} - {% with bulk_edit_url=content_type.model_class|validated_viewname:"bulk_edit" bulk_delete_url=content_type.model_class|validated_viewname:"bulk_delete" %} - {% if permissions.change or permissions.delete %} -
- {% csrf_token %} - - {% if table.paginator.num_pages > 1 %} -