Pārlūkot izejas kodu

Closes #2118: Added latitude and longitude fields to Site

Jeremy Stretch 7 gadi atpakaļ
vecāks
revīzija
258373f1a1

+ 3 - 5
netbox/dcim/api/serializers.py

@@ -1,7 +1,5 @@
 from __future__ import unicode_literals
 
-from collections import OrderedDict
-
 from rest_framework import serializers
 from rest_framework.validators import UniqueTogetherValidator
 from taggit.models import Tag
@@ -63,9 +61,9 @@ class SiteSerializer(CustomFieldModelSerializer):
         model = Site
         fields = [
             'id', 'name', 'slug', 'status', 'region', 'tenant', 'facility', 'asn', 'time_zone', 'description',
-            'physical_address', 'shipping_address', 'contact_name', 'contact_phone', 'contact_email', 'comments',
-            'tags', 'custom_fields', 'created', 'last_updated', 'count_prefixes', 'count_vlans', 'count_racks',
-            'count_devices', 'count_circuits',
+            'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone',
+            'contact_email', 'comments', 'tags', 'custom_fields', 'created', 'last_updated', 'count_prefixes',
+            'count_vlans', 'count_racks', 'count_devices', 'count_circuits',
         ]
 
 

+ 5 - 3
netbox/dcim/forms.py

@@ -115,8 +115,8 @@ class SiteForm(BootstrapMixin, TenancyForm, CustomFieldForm):
         model = Site
         fields = [
             'name', 'slug', 'status', 'region', 'tenant_group', 'tenant', 'facility', 'asn', 'time_zone', 'description',
-            'physical_address', 'shipping_address', 'contact_name', 'contact_phone', 'contact_email', 'comments',
-            'tags',
+            'physical_address', 'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone',
+            'contact_email', 'comments', 'tags',
         ]
         widgets = {
             'physical_address': SmallTextarea(attrs={'rows': 3}),
@@ -129,7 +129,9 @@ class SiteForm(BootstrapMixin, TenancyForm, CustomFieldForm):
             'time_zone': "Local time zone",
             'description': "Short description (will appear in sites list)",
             'physical_address': "Physical location of the building (e.g. for GPS)",
-            'shipping_address': "If different from the physical address"
+            'shipping_address': "If different from the physical address",
+            'latitude': "Latitude in decimal format (xx.yyyyyy)",
+            'longitude': "Longitude in decimal format (xx.yyyyyy)"
         }
 
 

+ 25 - 0
netbox/dcim/migrations/0060_site_latitude_longitude.py

@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.12 on 2018-06-21 18:45
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('dcim', '0059_devicetype_add_created_updated_times'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='site',
+            name='latitude',
+            field=models.DecimalField(blank=True, decimal_places=6, max_digits=8, null=True),
+        ),
+        migrations.AddField(
+            model_name='site',
+            name='longitude',
+            field=models.DecimalField(blank=True, decimal_places=6, max_digits=9, null=True),
+        ),
+    ]

+ 15 - 1
netbox/dcim/models.py

@@ -135,6 +135,18 @@ class Site(CreatedUpdatedModel, CustomFieldModel):
         max_length=200,
         blank=True
     )
+    latitude = models.DecimalField(
+        max_digits=8,
+        decimal_places=6,
+        blank=True,
+        null=True
+    )
+    longitude = models.DecimalField(
+        max_digits=9,
+        decimal_places=6,
+        blank=True,
+        null=True
+    )
     contact_name = models.CharField(
         max_length=50,
         blank=True
@@ -164,7 +176,7 @@ class Site(CreatedUpdatedModel, CustomFieldModel):
 
     csv_headers = [
         'name', 'slug', 'status', 'region', 'tenant', 'facility', 'asn', 'time_zone', 'description', 'physical_address',
-        'shipping_address', 'contact_name', 'contact_phone', 'contact_email', 'comments',
+        'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email', 'comments',
     ]
 
     serializer = 'dcim.api.serializers.SiteSerializer'
@@ -191,6 +203,8 @@ class Site(CreatedUpdatedModel, CustomFieldModel):
             self.description,
             self.physical_address,
             self.shipping_address,
+            self.latitude,
+            self.longitude,
             self.contact_name,
             self.contact_phone,
             self.contact_email,

+ 10 - 0
netbox/templates/dcim/site.html

@@ -175,6 +175,16 @@
                         {% endif %}
                     </td>
                 </tr>
+                <tr>
+                    <td>GPS Coordinates</td>
+                    <td>
+                        {% if site.latitude and site.longitude %}
+                            {{ site.latitude }}, {{ site.longitude }}
+                        {% else %}
+                            <span class="text-muted">N/A</span>
+                        {% endif %}
+                    </td>
+                </tr>
                 <tr>
                     <td>Contact Name</td>
                     <td>

+ 2 - 0
netbox/templates/dcim/site_edit.html

@@ -27,6 +27,8 @@
         <div class="panel-body">
             {% render_field form.physical_address %}
             {% render_field form.shipping_address %}
+            {% render_field form.latitude %}
+            {% render_field form.longitude %}
             {% render_field form.contact_name %}
             {% render_field form.contact_phone %}
             {% render_field form.contact_email %}