Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pyc
build

5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ To follow development, be sure to join the `Google Group`_.
``armstrong.apps.places`` is part of the `Armstrong`_ project. You're
probably looking for that.

Contributions
-------------
August 2012 - Place model contributed by `Paul Bailey`_ from `Mouth Watering Media`_

.. _Armstrong: http://www.armstrongcms.org/
.. _Bay Citizen: http://www.baycitizen.org/
.. _John S. and James L. Knight Foundation: http://www.knightfoundation.org/
.. _Texas Tribune: http://www.texastribune.org/
.. _Google Group: http://groups.google.com/group/armstrongcms
.. _Paul Bailey: https://plus.google.com/u/0/111994399408696258069/about
.. _Mouth Watering Media: http://mouthwateringmedia.com/
24 changes: 24 additions & 0 deletions armstrong/apps/places/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.contrib import admin
from django.utils.translation import ugettext as _

from armstrong.core.arm_content.admin import fieldsets
from armstrong import hatband

from .models import Place

class PlaceAdmin (admin.ModelAdmin):
fieldsets = (
(None, {
'fields': ('title', 'slug', 'summary'),
}),

(_('Location'), {
'fields': ('address1', 'address2', ('city', 'state'), ('zipcode', 'country'), 'coordinate'),
}),

fieldsets.TAXONOMY,
fieldsets.PUBLICATION,
fieldsets.AUTHORS,
)

hatband.site.register(Place, PlaceAdmin)
129 changes: 129 additions & 0 deletions armstrong/apps/places/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding model 'Place'
db.create_table('places_place', (
('content_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['content.Content'], unique=True, primary_key=True)),
('address1', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)),
('address2', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)),
('zipcode', self.gf('django.db.models.fields.CharField')(max_length=30, null=True, blank=True)),
('city', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)),
('state', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)),
('country', self.gf('django.db.models.fields.CharField')(max_length=100, null=True, blank=True)),
('coordinate', self.gf('django.contrib.gis.db.models.fields.PointField')()),
))
db.send_create_signal('places', ['Place'])

def backwards(self, orm):
# Deleting model 'Place'
db.delete_table('places_place')

models = {
'arm_access.accessobject': {
'Meta': {'object_name': 'AccessObject'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'})
},
'arm_sections.section': {
'Meta': {'object_name': 'Section'},
'full_slug': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'parent': ('mptt.fields.TreeForeignKey', [], {'to': "orm['arm_sections.Section']", 'null': 'True', 'blank': 'True'}),
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'summary': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
},
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'content.content': {
'Meta': {'object_name': 'Content'},
'access': ('armstrong.core.arm_access.fields.AccessField', [], {}),
'authors': ('armstrong.core.arm_content.fields.authors.AuthorsField', [], {'to': "orm['auth.User']", 'override_field_name': "'authors_override'", 'symmetrical': 'False', 'extra_field_name': "'authors_extra'", 'blank': 'True'}),
'authors_extra': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
'authors_override': ('django.db.models.fields.CharField', [], {'max_length': '200', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'pub_date': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True'}),
'pub_status': ('django.db.models.fields.CharField', [], {'max_length': '1'}),
'sections': ('django.db.models.fields.related.ManyToManyField', [], {'blank': 'True', 'related_name': "'content_content_alternates'", 'null': 'True', 'symmetrical': 'False', 'to': "orm['arm_sections.Section']"}),
'sites': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['sites.Site']", 'symmetrical': 'False'}),
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50'}),
'summary': ('django.db.models.fields.TextField', [], {}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '255'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'places.place': {
'Meta': {'object_name': 'Place', '_ormbases': ['content.Content']},
'address1': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'address2': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'city': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'content_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['content.Content']", 'unique': 'True', 'primary_key': 'True'}),
'coordinate': ('django.contrib.gis.db.models.fields.PointField', [], {}),
'country': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'state': ('django.db.models.fields.CharField', [], {'max_length': '100', 'null': 'True', 'blank': 'True'}),
'zipcode': ('django.db.models.fields.CharField', [], {'max_length': '30', 'null': 'True', 'blank': 'True'})
},
'sites.site': {
'Meta': {'ordering': "('domain',)", 'object_name': 'Site', 'db_table': "'django_site'"},
'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'taggit.tag': {
'Meta': {'object_name': 'Tag'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '100'})
},
'taggit.taggeditem': {
'Meta': {'object_name': 'TaggedItem'},
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_tagged_items'", 'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'object_id': ('django.db.models.fields.IntegerField', [], {'db_index': 'True'}),
'tag': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'taggit_taggeditem_items'", 'to': "orm['taggit.Tag']"})
}
}

complete_apps = ['places']
Empty file.
17 changes: 17 additions & 0 deletions armstrong/apps/places/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.contrib.gis.db import models
from django.utils.translation import ugettext as _

from armstrong.apps.content.models import Content

class Place (Content):
address1 = models.CharField(_('Address 1'), max_length=100, blank=True, null=True)
address2 = models.CharField(_('Address 2'), max_length=100, blank=True, null=True)
zipcode = models.CharField(_('Zip code'), max_length=30, blank=True, null=True)
city = models.CharField(max_length=100, blank=True, null=True)
state = models.CharField(_('State/Province'), max_length=100, blank=True, null=True)
country = models.CharField(max_length=100, blank=True, null=True)

coordinate = models.PointField()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be nullable too? It seems like the coordinate is the most important aspect, but from a practical workflow perspective, sometimes you may only have an address and you'd like to do the geolocation out-of-band, and making coordinate required limits how you can do that.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The one essential piece of info a place should have is that it is located somewhere. That is what my thought was. Also previously I've had problems with geospatial queries in Postgres when the fields are null. This may not be the case anymore, but I've always avoided nullable point fields since then especially since it is the most important field in the model.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having a required PointField on a Place is a fair requirement.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on a philosophical django tangent... we've had the idea of enforcing different levels of data validation. Like an unpublished article doesn't need a slug, but a published one does, so should the slugfield be required? As I typed that out... I think the answer is yes. before the save() hits, you should just pre-generate one, even if it's gibberish. Likewise here, we can assume the implementer has figured out how to get the latlong already, or decides to use a dummy latlong and then fills in the real one later (like how Google maps used to default to the geographic center of the continental US).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I implemented the model on the front end I have a button that the user clicks to look up an address on google maps and fills in the coordinates. Originally, I wanted to include this functionality with the Armstrong contribution by using http://mapstraction.com/. Mapstraction would allow you to switch between map providers. However, I never got it to work right and had to finish with a quick implementation of just google maps in the client's code. Now that I have sometime, I could probably revisit it if you think it is appropriate to include with the contribution.


objects = models.GeoManager()

51 changes: 51 additions & 0 deletions armstrong/apps/places/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import datetime

from django.test import TestCase
from django.core.urlresolvers import reverse, resolve

from django.contrib.gis.geos import Point
from django.contrib.gis.measure import D

from .models import Place

class PlacesTestCase (TestCase):
def setUp(self):
self.home = Place(
address1 = '1206 Halls Bridge',
address2 = None,
zipcode = '77573',
city = 'League City',
state = 'TX',
country = 'US',
coordinate = Point(-95.087372, 29.516589),

pub_date = datetime.datetime.now()
)
self.home.save()

self.work = Place(
address1 = '3657 Briarpark Drive',
address2 = 'Suite 101',
zipcode = '77042',
city = 'Houston',
state = 'TX',
country = 'US',
coordinate = Point(-95.54835, 29.72546),

pub_date = datetime.datetime.now()
)
self.work.save()

def tearDown(self):
self.home.delete()
self.work.delete()

def test_model (self):
bay_brook_mall = Point(-95.14820, 29.54211)
qs = Place.objects.filter(coordinate__distance_lte=(bay_brook_mall, D(mi=5)))
self.assertEqual(qs.count(), 1)
self.assertEqual(qs[0].id, self.home.id)

qs = Place.objects.filter(coordinate__distance_lte=(bay_brook_mall, D(mi=30)))
self.assertEqual(qs.count(), 2)