From cdacd2a95158be9c7451dfeacbb37b01ee078f35 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 30 Mar 2022 16:19:12 -0400 Subject: [PATCH] Closes #8593: Add link field to contact model --- docs/release-notes/version-3.2.md | 3 +++ netbox/templates/tenancy/contact.html | 10 ++++++++++ netbox/tenancy/api/serializers.py | 2 +- netbox/tenancy/filtersets.py | 3 ++- netbox/tenancy/forms/bulk_edit.py | 7 +++++-- netbox/tenancy/forms/bulk_import.py | 2 +- netbox/tenancy/forms/models.py | 8 +++----- netbox/tenancy/migrations/0007_contact_link.py | 17 +++++++++++++++++ netbox/tenancy/models/contacts.py | 3 +++ netbox/tenancy/tables/contacts.py | 2 +- 10 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 netbox/tenancy/migrations/0007_contact_link.py diff --git a/docs/release-notes/version-3.2.md b/docs/release-notes/version-3.2.md index 2b85e6eda..c120ce931 100644 --- a/docs/release-notes/version-3.2.md +++ b/docs/release-notes/version-3.2.md @@ -143,6 +143,7 @@ Where it is desired to limit the range of available VLANs within a group, users * [#8307](https://github.com/netbox-community/netbox/issues/8307) - Add `data_type` indicator to REST API serializer for custom fields * [#8463](https://github.com/netbox-community/netbox/issues/8463) - Change the `created` field on all change-logged models from date to datetime * [#8572](https://github.com/netbox-community/netbox/issues/8572) - Add a `pre_run()` method for reports +* [#8593](https://github.com/netbox-community/netbox/issues/8593) - Add a `link` field for contacts * [#8649](https://github.com/netbox-community/netbox/issues/8649) - Enable customization of configuration module using `NETBOX_CONFIGURATION` environment variable ### Bug Fixes (From Beta2) @@ -205,5 +206,7 @@ Where it is desired to limit the range of available VLANs within a group, users * ipam.VLANGroup * Added the `/availables-vlans/` endpoint * Added the `min_vid` and `max_vid` fields +* tenancy.Contact + * Added the `link` field * virtualization.VMInterface * Added `vrf` field diff --git a/netbox/templates/tenancy/contact.html b/netbox/templates/tenancy/contact.html index 3b97a5a20..f55e87895 100644 --- a/netbox/templates/tenancy/contact.html +++ b/netbox/templates/tenancy/contact.html @@ -53,6 +53,16 @@ Address {{ object.address|linebreaksbr|placeholder }} + + Link + + {% if object.link %} + {{ object.link }} + {% else %} + {{ ''|placeholder }} + {% endif %} + + Assignments {{ assignment_count }} diff --git a/netbox/tenancy/api/serializers.py b/netbox/tenancy/api/serializers.py index 21a75a6bf..8749dc63f 100644 --- a/netbox/tenancy/api/serializers.py +++ b/netbox/tenancy/api/serializers.py @@ -84,7 +84,7 @@ class ContactSerializer(NetBoxModelSerializer): class Meta: model = Contact fields = [ - 'id', 'url', 'display', 'group', 'name', 'title', 'phone', 'email', 'address', 'comments', 'tags', + 'id', 'url', 'display', 'group', 'name', 'title', 'phone', 'email', 'address', 'link', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', ] diff --git a/netbox/tenancy/filtersets.py b/netbox/tenancy/filtersets.py index 03f3fdf6d..8ca4ae29c 100644 --- a/netbox/tenancy/filtersets.py +++ b/netbox/tenancy/filtersets.py @@ -63,7 +63,7 @@ class ContactFilterSet(NetBoxModelFilterSet): class Meta: model = Contact - fields = ['id', 'name', 'title', 'phone', 'email', 'address'] + fields = ['id', 'name', 'title', 'phone', 'email', 'address', 'link'] def search(self, queryset, name, value): if not value.strip(): @@ -74,6 +74,7 @@ class ContactFilterSet(NetBoxModelFilterSet): Q(phone__icontains=value) | Q(email__icontains=value) | Q(address__icontains=value) | + Q(link__icontains=value) | Q(comments__icontains=value) ) diff --git a/netbox/tenancy/forms/bulk_edit.py b/netbox/tenancy/forms/bulk_edit.py index 270e2b4a5..4c1f03757 100644 --- a/netbox/tenancy/forms/bulk_edit.py +++ b/netbox/tenancy/forms/bulk_edit.py @@ -98,9 +98,12 @@ class ContactBulkEditForm(NetBoxModelBulkEditForm): max_length=200, required=False ) + link = forms.URLField( + required=False + ) model = Contact fieldsets = ( - (None, ('group', 'title', 'phone', 'email', 'address')), + (None, ('group', 'title', 'phone', 'email', 'address', 'link')), ) - nullable_fields = ('group', 'title', 'phone', 'email', 'address', 'comments') + nullable_fields = ('group', 'title', 'phone', 'email', 'address', 'link', 'comments') diff --git a/netbox/tenancy/forms/bulk_import.py b/netbox/tenancy/forms/bulk_import.py index 409590c28..d617a27b5 100644 --- a/netbox/tenancy/forms/bulk_import.py +++ b/netbox/tenancy/forms/bulk_import.py @@ -79,4 +79,4 @@ class ContactCSVForm(NetBoxModelCSVForm): class Meta: model = Contact - fields = ('name', 'title', 'phone', 'email', 'address', 'group', 'comments') + fields = ('name', 'title', 'phone', 'email', 'address', 'link', 'group', 'comments') diff --git a/netbox/tenancy/forms/models.py b/netbox/tenancy/forms/models.py index 35b631d43..021e36a5b 100644 --- a/netbox/tenancy/forms/models.py +++ b/netbox/tenancy/forms/models.py @@ -1,11 +1,9 @@ from django import forms -from extras.models import Tag from netbox.forms import NetBoxModelForm from tenancy.models import * from utilities.forms import ( - BootstrapMixin, CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField, SmallTextarea, - StaticSelect, + BootstrapMixin, CommentField, DynamicModelChoiceField, SlugField, SmallTextarea, StaticSelect, ) __all__ = ( @@ -87,13 +85,13 @@ class ContactForm(NetBoxModelForm): comments = CommentField() fieldsets = ( - ('Contact', ('group', 'name', 'title', 'phone', 'email', 'address', 'tags')), + ('Contact', ('group', 'name', 'title', 'phone', 'email', 'address', 'link', 'tags')), ) class Meta: model = Contact fields = ( - 'group', 'name', 'title', 'phone', 'email', 'address', 'comments', 'tags', + 'group', 'name', 'title', 'phone', 'email', 'address', 'link', 'comments', 'tags', ) widgets = { 'address': SmallTextarea(attrs={'rows': 3}), diff --git a/netbox/tenancy/migrations/0007_contact_link.py b/netbox/tenancy/migrations/0007_contact_link.py new file mode 100644 index 000000000..43b7495e5 --- /dev/null +++ b/netbox/tenancy/migrations/0007_contact_link.py @@ -0,0 +1,17 @@ +from django.db import migrations, models +import utilities.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('tenancy', '0006_created_datetimefield'), + ] + + operations = [ + migrations.AddField( + model_name='contact', + name='link', + field=models.URLField(blank=True), + ), + ] diff --git a/netbox/tenancy/models/contacts.py b/netbox/tenancy/models/contacts.py index 50b75ada7..75ec9f69c 100644 --- a/netbox/tenancy/models/contacts.py +++ b/netbox/tenancy/models/contacts.py @@ -105,6 +105,9 @@ class Contact(NetBoxModel): max_length=200, blank=True ) + link = models.URLField( + blank=True + ) comments = models.TextField( blank=True ) diff --git a/netbox/tenancy/tables/contacts.py b/netbox/tenancy/tables/contacts.py index cc37efd44..17abc5a5b 100644 --- a/netbox/tenancy/tables/contacts.py +++ b/netbox/tenancy/tables/contacts.py @@ -65,7 +65,7 @@ class ContactTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = Contact fields = ( - 'pk', 'name', 'group', 'title', 'phone', 'email', 'address', 'comments', 'assignment_count', 'tags', + 'pk', 'name', 'group', 'title', 'phone', 'email', 'address', 'link', 'comments', 'assignment_count', 'tags', 'created', 'last_updated', ) default_columns = ('pk', 'name', 'group', 'assignment_count', 'title', 'phone', 'email')