Просмотр исходного кода

Closes #8593: Add link field to contact model

jeremystretch 3 лет назад
Родитель
Сommit
cdacd2a951

+ 3 - 0
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
 * [#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
 * [#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
 * [#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
 * [#8649](https://github.com/netbox-community/netbox/issues/8649) - Enable customization of configuration module using `NETBOX_CONFIGURATION` environment variable
 
 
 ### Bug Fixes (From Beta2)
 ### 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
 * ipam.VLANGroup
     * Added the `/availables-vlans/` endpoint
     * Added the `/availables-vlans/` endpoint
     * Added the `min_vid` and `max_vid` fields
     * Added the `min_vid` and `max_vid` fields
+* tenancy.Contact
+    * Added the `link` field
 * virtualization.VMInterface
 * virtualization.VMInterface
     * Added `vrf` field
     * Added `vrf` field

+ 10 - 0
netbox/templates/tenancy/contact.html

@@ -53,6 +53,16 @@
               <td>Address</td>
               <td>Address</td>
               <td>{{ object.address|linebreaksbr|placeholder }}</td>
               <td>{{ object.address|linebreaksbr|placeholder }}</td>
             </tr>
             </tr>
+            <tr>
+              <td>Link</td>
+              <td>
+                {% if object.link %}
+                  <a href="{{ object.link }}">{{ object.link }}</a>
+                {% else %}
+                  {{ ''|placeholder }}
+                {% endif %}
+              </td>
+            </tr>
             <tr>
             <tr>
               <th scope="row">Assignments</th>
               <th scope="row">Assignments</th>
               <td>{{ assignment_count }}</td>
               <td>{{ assignment_count }}</td>

+ 1 - 1
netbox/tenancy/api/serializers.py

@@ -84,7 +84,7 @@ class ContactSerializer(NetBoxModelSerializer):
     class Meta:
     class Meta:
         model = Contact
         model = Contact
         fields = [
         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',
             'custom_fields', 'created', 'last_updated',
         ]
         ]
 
 

+ 2 - 1
netbox/tenancy/filtersets.py

@@ -63,7 +63,7 @@ class ContactFilterSet(NetBoxModelFilterSet):
 
 
     class Meta:
     class Meta:
         model = Contact
         model = Contact
-        fields = ['id', 'name', 'title', 'phone', 'email', 'address']
+        fields = ['id', 'name', 'title', 'phone', 'email', 'address', 'link']
 
 
     def search(self, queryset, name, value):
     def search(self, queryset, name, value):
         if not value.strip():
         if not value.strip():
@@ -74,6 +74,7 @@ class ContactFilterSet(NetBoxModelFilterSet):
             Q(phone__icontains=value) |
             Q(phone__icontains=value) |
             Q(email__icontains=value) |
             Q(email__icontains=value) |
             Q(address__icontains=value) |
             Q(address__icontains=value) |
+            Q(link__icontains=value) |
             Q(comments__icontains=value)
             Q(comments__icontains=value)
         )
         )
 
 

+ 5 - 2
netbox/tenancy/forms/bulk_edit.py

@@ -98,9 +98,12 @@ class ContactBulkEditForm(NetBoxModelBulkEditForm):
         max_length=200,
         max_length=200,
         required=False
         required=False
     )
     )
+    link = forms.URLField(
+        required=False
+    )
 
 
     model = Contact
     model = Contact
     fieldsets = (
     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')

+ 1 - 1
netbox/tenancy/forms/bulk_import.py

@@ -79,4 +79,4 @@ class ContactCSVForm(NetBoxModelCSVForm):
 
 
     class Meta:
     class Meta:
         model = Contact
         model = Contact
-        fields = ('name', 'title', 'phone', 'email', 'address', 'group', 'comments')
+        fields = ('name', 'title', 'phone', 'email', 'address', 'link', 'group', 'comments')

+ 3 - 5
netbox/tenancy/forms/models.py

@@ -1,11 +1,9 @@
 from django import forms
 from django import forms
 
 
-from extras.models import Tag
 from netbox.forms import NetBoxModelForm
 from netbox.forms import NetBoxModelForm
 from tenancy.models import *
 from tenancy.models import *
 from utilities.forms import (
 from utilities.forms import (
-    BootstrapMixin, CommentField, DynamicModelChoiceField, DynamicModelMultipleChoiceField, SlugField, SmallTextarea,
-    StaticSelect,
+    BootstrapMixin, CommentField, DynamicModelChoiceField, SlugField, SmallTextarea, StaticSelect,
 )
 )
 
 
 __all__ = (
 __all__ = (
@@ -87,13 +85,13 @@ class ContactForm(NetBoxModelForm):
     comments = CommentField()
     comments = CommentField()
 
 
     fieldsets = (
     fieldsets = (
-        ('Contact', ('group', 'name', 'title', 'phone', 'email', 'address', 'tags')),
+        ('Contact', ('group', 'name', 'title', 'phone', 'email', 'address', 'link', 'tags')),
     )
     )
 
 
     class Meta:
     class Meta:
         model = Contact
         model = Contact
         fields = (
         fields = (
-            'group', 'name', 'title', 'phone', 'email', 'address', 'comments', 'tags',
+            'group', 'name', 'title', 'phone', 'email', 'address', 'link', 'comments', 'tags',
         )
         )
         widgets = {
         widgets = {
             'address': SmallTextarea(attrs={'rows': 3}),
             'address': SmallTextarea(attrs={'rows': 3}),

+ 17 - 0
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),
+        ),
+    ]

+ 3 - 0
netbox/tenancy/models/contacts.py

@@ -105,6 +105,9 @@ class Contact(NetBoxModel):
         max_length=200,
         max_length=200,
         blank=True
         blank=True
     )
     )
+    link = models.URLField(
+        blank=True
+    )
     comments = models.TextField(
     comments = models.TextField(
         blank=True
         blank=True
     )
     )

+ 1 - 1
netbox/tenancy/tables/contacts.py

@@ -65,7 +65,7 @@ class ContactTable(NetBoxTable):
     class Meta(NetBoxTable.Meta):
     class Meta(NetBoxTable.Meta):
         model = Contact
         model = Contact
         fields = (
         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',
             'created', 'last_updated',
         )
         )
         default_columns = ('pk', 'name', 'group', 'assignment_count', 'title', 'phone', 'email')
         default_columns = ('pk', 'name', 'group', 'assignment_count', 'title', 'phone', 'email')