diff --git a/network/base/admin.py b/network/base/admin.py index bcdbc26..80c6d86 100644 --- a/network/base/admin.py +++ b/network/base/admin.py @@ -9,7 +9,7 @@ class AntennaAdmin(admin.ModelAdmin): class StationAdmin(admin.ModelAdmin): - list_display = ('name', 'owner', 'lng', 'lat', 'location') + list_display = ('name', 'owner', 'lng', 'lat', 'qthlocator') class SatelliteAdmin(admin.ModelAdmin): diff --git a/network/base/forms.py b/network/base/forms.py index 891feed..12cbba5 100644 --- a/network/base/forms.py +++ b/network/base/forms.py @@ -7,5 +7,5 @@ class StationForm(forms.ModelForm): class Meta: model = Station fields = ['name', 'image', 'alt', - 'lat', 'lng', 'antenna', 'online'] + 'lat', 'lng', 'qthlocator', 'antenna', 'online'] image = forms.ImageField(required=False) diff --git a/network/base/migrations/0015_station_qthlocator.py b/network/base/migrations/0015_station_qthlocator.py new file mode 100644 index 0000000..0cd9ed6 --- /dev/null +++ b/network/base/migrations/0015_station_qthlocator.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0014_auto_20150209_0846'), + ] + + operations = [ + migrations.AddField( + model_name='station', + name='qthlocator', + field=models.CharField(max_length=255, null=True, blank=True), + preserve_default=True, + ), + ] diff --git a/network/base/models.py b/network/base/models.py index bb80bdd..5306425 100644 --- a/network/base/models.py +++ b/network/base/models.py @@ -37,6 +37,7 @@ class Station(models.Model): MinValueValidator(-90)]) lng = models.FloatField(validators=[MaxValueValidator(180), MinValueValidator(-180)]) + qthlocator = models.CharField(max_length=255, null=True, blank=True) location = models.CharField(max_length=255, null=True, blank=True) antenna = models.ManyToManyField(Antenna, null=True, blank=True, help_text=('If you want to add a new Antenna ' diff --git a/network/static/js/gridsquare.js b/network/static/js/gridsquare.js new file mode 100644 index 0000000..c4f1b02 --- /dev/null +++ b/network/static/js/gridsquare.js @@ -0,0 +1,45 @@ +/* This script calculates the grid locator based on the Maidenhead + * Locator System. It references the longitude and latitude fields + * in the Station Add/Edit view, calculating the grid square and adding + * that to the location field iff both lat/lon values exist and are + * valid. -cshields + */ +function gridsquare() { + var FIELD_IDENTIFIERS = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'H', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; + + // starting points, the fields from the Station form + var latitude = $('#lat').val(); + var longitude = $('#lng').val(); + + // this gets called any time one of the two lat/long fields + // have been changed. We only need to do the work if both + // fields have been entered with a proper entry, otherwise + // skip the cycles + if ((latitude !== '') && + (latitude <= 90) && + (latitude >= -90) && + (longitude !== '') && + (longitude <= 180) && + (longitude >= -180)) { + + // to figure out the individual grid identifiers we make a mess + // of the longitude and latitude + var working_lon = ((+longitude + 180) % 20); + var lon_field = FIELD_IDENTIFIERS[Math.floor((+longitude + 180) / 20)]; + var lon_square = Math.floor(working_lon / 2); + working_lon = Math.floor((working_lon % 2) * 12); + var lon_subsquare = FIELD_IDENTIFIERS[working_lon]; + + var working_lat = ((+latitude + 90) % 10); + var lat_field = FIELD_IDENTIFIERS[Math.floor((+latitude + 90) / 10)]; + var lat_square = Math.floor(working_lat); + working_lat = Math.floor((working_lat - Math.floor(working_lat)) * 24); + var lat_subsquare = FIELD_IDENTIFIERS[working_lat]; + + // write the result, like EM69uf, to qthlocator field + var qthlocator = $('#qthlocator'); + qthlocator.val('' + lon_field + lat_field + lon_square + lat_square + + lon_subsquare.toLowerCase() + lat_subsquare.toLowerCase()); + } +} diff --git a/network/templates/base/station_view.html b/network/templates/base/station_view.html index 37f8212..79bb852 100644 --- a/network/templates/base/station_view.html +++ b/network/templates/base/station_view.html @@ -27,16 +27,26 @@ Owner - {{ station.owner.get_full_name }} + {{ station.owner.displayname }} -
- Location - - {{ station.location }} - -
+ {% if station.qthlocator %} +
+ QTH Locator + + {{ station.qthlocator }} + +
+ {% endif %} + {% if station.location %} +
+ Location + + {{ station.location }} + +
+ {% endif %}
Coordinates @@ -96,4 +106,5 @@ {% block javascript %} + {% endblock javascript %} diff --git a/network/templates/base/stations.html b/network/templates/base/stations.html index 94f52a0..2c5a9bf 100644 --- a/network/templates/base/stations.html +++ b/network/templates/base/stations.html @@ -1,5 +1,6 @@ {% extends "base.html" %} {% load tags %} +{% load staticfiles %} {% block title %}Ground Stations{% endblock %} @@ -17,6 +18,9 @@ ID Name + {% if station.qthlocator %} + qthlocator + {% endif %} Location Altitude Antenna @@ -42,6 +46,11 @@ {{ station.name }} + {% if station.qthlocator %} + + {{ station.qthlocator }} + + {% endif %} {% if station.location %} {{ station.location }} @@ -70,3 +79,7 @@ {% include 'includes/station_edit.html' %} {% endblock content %} + +{% block javascript %} + +{% endblock javascript %} diff --git a/network/templates/includes/station_edit.html b/network/templates/includes/station_edit.html index 01b2b80..7b5648b 100644 --- a/network/templates/includes/station_edit.html +++ b/network/templates/includes/station_edit.html @@ -38,23 +38,24 @@
- +
- +
- +
+ name="qthlocator" + value="{{ form.qthlocator.value|default_if_none:"Geocoded gridsquare here" }}" + readonly>
@@ -73,7 +74,7 @@
@@ -87,4 +88,4 @@
- \ No newline at end of file + diff --git a/network/templates/users/user_detail.html b/network/templates/users/user_detail.html index 7844f91..d82d84d 100644 --- a/network/templates/users/user_detail.html +++ b/network/templates/users/user_detail.html @@ -163,3 +163,7 @@ {% endblock content %} + +{% block javascript %} + +{% endblock javascript %} \ No newline at end of file