diff options
author | luxagraf <sng@luxagraf.net> | 2017-12-14 19:58:07 -0800 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2017-12-14 19:58:07 -0800 |
commit | c903be495237125906e95e2d5fcb9f17df09327c (patch) | |
tree | 27173dad151e2c09105bd1c1b64f9d04210f8d8e /app/locations | |
parent | 83b7318a4672d32ed77cd3f906f43f5ad1cce854 (diff) |
cleaned up notes, archived old apps, moved checkins to locations app
where it should have been from the beginning
Diffstat (limited to 'app/locations')
-rw-r--r-- | app/locations/admin.py | 8 | ||||
-rw-r--r-- | app/locations/migrations/0001_initial.py | 104 | ||||
-rw-r--r-- | app/locations/migrations/0002_checkin.py | 31 | ||||
-rw-r--r-- | app/locations/migrations/__init__.py | 0 | ||||
-rw-r--r-- | app/locations/models.py | 32 |
5 files changed, 174 insertions, 1 deletions
diff --git a/app/locations/admin.py b/app/locations/admin.py index 1938336..c3419b1 100644 --- a/app/locations/admin.py +++ b/app/locations/admin.py @@ -1,6 +1,7 @@ from django.contrib import admin from django.contrib.gis.admin import OSMGeoAdmin -from locations.models import Region, Country, Location, State, Route +from locations.models import Region, Country, Location, State, Route, CheckIn +from utils.widgets import OLAdminBase class RegionAdmin(OSMGeoAdmin): @@ -232,3 +233,8 @@ class RouteAdmin(OSMGeoAdmin): openlayers_url = '/static/admin/js/OpenLayers.js' admin.site.register(Route, RouteAdmin) + + +@admin.register(CheckIn) +class CheckInAdmin(OLAdminBase): + list_display = ('date', 'location') diff --git a/app/locations/migrations/0001_initial.py b/app/locations/migrations/0001_initial.py new file mode 100644 index 0000000..1854dbf --- /dev/null +++ b/app/locations/migrations/0001_initial.py @@ -0,0 +1,104 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-12-14 22:25 +from __future__ import unicode_literals + +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Country', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50)), + ('area', models.IntegerField(help_text='Area of Country in SQ meters')), + ('pop2005', models.IntegerField(verbose_name='Population 2005')), + ('fips', models.CharField(help_text='<a href="http://www.census.gov/geo/www/fips/fips.html">Federal Information Processing Standard Code</a>', max_length=2, verbose_name='FIPS Code')), + ('iso2', models.CharField(help_text='<a href="http://www.iso.org/">International Organization for Standardization</a>', max_length=2, verbose_name='2 Digit ISO')), + ('iso3', models.CharField(help_text='<a href="http://www.iso.org/">International Organization for Standardization</a>', max_length=3, verbose_name='3 Digit ISO')), + ('un', models.IntegerField(verbose_name='United Nations Code')), + ('region', models.IntegerField(choices=[(0, 'MISC'), (2, 'Africa'), (9, 'Oceania'), (19, 'Americas'), (142, 'Asia'), (150, 'Europe')], verbose_name='Region Code')), + ('subregion', models.IntegerField(choices=[(0, 'MISC'), (5, 'South America'), (11, 'Western Africa'), (13, 'Central America'), (14, 'Eastern Africa'), (15, 'Northern Africa'), (17, 'Middle Africa'), (18, 'Southern Africa'), (21, 'North America'), (29, 'Caribbean'), (30, 'Eastern Asia'), (34, 'Southern Asia'), (35, 'Southeast Asia'), (39, 'Southern Europe'), (53, 'Australia and New Zealand'), (54, 'Melanesia'), (57, 'Micronesia'), (61, 'Polynesia'), (143, 'Central Asia'), (145, 'Western Asia'), (151, 'Eastern Europe'), (154, 'Northern Europe'), (155, 'Western Europe')], verbose_name='Sub-Region Code')), + ('lon', models.FloatField(help_text='Longitude of centerpoint', verbose_name='Longitude')), + ('lat', models.FloatField(help_text='Latitude of centerpoint', verbose_name='Latitude')), + ('zoom_level', models.CharField(max_length=2, null=True)), + ('slug', models.SlugField(null=True)), + ('visited', models.BooleanField(default=False)), + ('pub_date', models.DateTimeField(null=True, verbose_name='Date published')), + ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326, verbose_name='Country Border')), + ], + options={ + 'verbose_name_plural': 'Countries', + 'ordering': ['name'], + }, + ), + migrations.CreateModel( + name='Location', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50)), + ('slug', models.SlugField()), + ('pub_date', models.DateTimeField(null=True, verbose_name='Date published')), + ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(srid=4326)), + ], + ), + migrations.CreateModel( + name='Region', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=50)), + ('slug', models.SlugField()), + ('pub_date', models.DateTimeField(null=True, verbose_name='Date published')), + ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326)), + ('lon', models.FloatField(help_text='Longitude of centerpoint', null=True, verbose_name='Longitude')), + ('lat', models.FloatField(help_text='Latitude of centerpoint', null=True, verbose_name='Latitude')), + ('zoom_level', models.CharField(max_length=2, null=True)), + ], + ), + migrations.CreateModel( + name='Route', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('slug', models.SlugField()), + ('zoom', models.CharField(max_length=2, null=True)), + ('template_var_name', models.CharField(max_length=10, null=True)), + ('pub_date', models.DateTimeField(null=True, verbose_name='Date published')), + ('geometry', django.contrib.gis.db.models.fields.MultiPointField(srid=4326)), + ], + ), + migrations.CreateModel( + name='State', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(blank=True, max_length=250, null=True)), + ('slug', models.SlugField()), + ('code', models.CharField(blank=True, max_length=2, null=True)), + ('pub_date', models.DateTimeField(null=True, verbose_name='Date published')), + ('geometry', django.contrib.gis.db.models.fields.MultiPolygonField(null=True, srid=4326)), + ('country', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='locations.Country')), + ], + options={ + 'ordering': ['name'], + }, + ), + migrations.AddField( + model_name='location', + name='state', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='locations.State'), + ), + migrations.AddField( + model_name='country', + name='lux_region', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Region'), + ), + ] diff --git a/app/locations/migrations/0002_checkin.py b/app/locations/migrations/0002_checkin.py new file mode 100644 index 0000000..f479d8b --- /dev/null +++ b/app/locations/migrations/0002_checkin.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.5 on 2017-12-14 22:32 +from __future__ import unicode_literals + +import django.contrib.gis.db.models.fields +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('locations', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='CheckIn', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('point', django.contrib.gis.db.models.fields.PointField(blank=True, srid=4326)), + ('date', models.DateField(default=django.utils.timezone.now)), + ('location', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='locations.Location')), + ], + options={ + 'ordering': ('-date',), + 'get_latest_by': 'date', + }, + ), + ] diff --git a/app/locations/migrations/__init__.py b/app/locations/migrations/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/app/locations/migrations/__init__.py diff --git a/app/locations/models.py b/app/locations/models.py index b4ee2af..1baa964 100644 --- a/app/locations/models.py +++ b/app/locations/models.py @@ -4,6 +4,8 @@ from django.contrib.gis.geos import GEOSGeometry, fromstr, MultiPolygon from django.contrib.gis.db import models from django.contrib.sitemaps import Sitemap from django.utils.safestring import mark_safe +from django.utils import timezone + "http://staticmap.openstreetmap.de/staticmap.php?center=object.location.geometry.centroid.y,object.location.geometry.centroid.x&zoom=14&size=1140x300&maptype=osmarenderer&markers=40.702147,-74.015794,lightblue1" @@ -158,6 +160,36 @@ class Route(models.Model): return self.name +class CheckIn(models.Model): + point = models.PointField(blank=True) + location = models.ForeignKey(Location, blank=True, null=True) + date = models.DateField(default=timezone.now) + + class Meta: + ordering = ('-date',) + get_latest_by = 'date' + + def __str__(self): + return str(self.date) + + @property + def lon(self): + '''Get the site's longitude.''' + return self.point.x + + @property + def lat(self): + '''Get the site's latitude.''' + return self.point.y + + def save(self): + try: + self.location = Location.objects.filter(geometry__contains=self.point).get() + except Location.DoesNotExist: + raise forms.ValidationError("There is no location associated with that point, add it: %sadmin/locations/location/add/" % (settings.BASE_URL)) + super(CheckIn, self).save() + + class WritingbyCountrySitemap(Sitemap): changefreq = "weekly" priority = 0.6 |