~doctormo/+junk/ashmont-valley-website

« back to all changes in this revision

Viewing changes to community/places/models.py

  • Committer: Martin Owens
  • Date: 2014-05-03 12:23:32 UTC
  • Revision ID: doctormo@gmail.com-20140503122332-tcg7jymzfsl6ittm
Add Yahoo group link to front page

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
    postcode = CharField(max_length=22)
56
56
    location = GeopositionField(**blank)
57
57
 
58
 
    # These are svg text fields. Use later for storing interesting things.
59
58
    plot     = TextField(_('Building Plot'), **blank)
60
59
    foot     = TextField(_('Building Footprint'), **blank)
61
60
 
62
61
    class Meta:
63
62
        unique_together = (('number', 'road'),)
64
63
 
 
64
    def coords(self, c_latt, c_long):
 
65
        if self.location:
 
66
            return (
 
67
                coord(self.location.latitude, *c_latt),
 
68
                coord(self.location.longitude, *c_long),
 
69
            )
 
70
        return None
 
71
 
65
72
    def __unicode__(self, extra=''):
66
73
        return "%s %s%s\n%s\n%s" % (self.number, self.road, extra, self.road.city, self.road.city.state)
67
74
 
 
75
from decimal import Decimal
 
76
 
 
77
def coord(point, start, size):
 
78
    if isinstance(start, tuple):
 
79
        start = to_degrees(*start)
 
80
    return (abs(Decimal(start)) - abs(point)) * 60 * 60 * Decimal(size)
 
81
 
 
82
def to_degrees(degrees, minutes, seconds):
 
83
    degrees = Decimal(degrees)
 
84
    degrees += Decimal(minutes) / 60
 
85
    degrees += Decimal(seconds) / 3600
 
86
    return degrees
 
87
 
 
88
def to_minutes(degrees):
 
89
    """Convert decimal latt/long to seconds/minutes"""
 
90
    minutes = abs(degrees) % 1 * 60
 
91
    seconds = minutes % 1 * 60
 
92
    return (int(degrees), int(minutes), seconds)
 
93
 
68
94
 
69
95
class Address(Model):
70
96
    """An address is some relatable information plus a building"""