gremmie@1: """ gremmie@1: Models for the member map application. gremmie@1: """ gremmie@1: from django.db import models gremmie@1: from django.contrib.auth.models import User gremmie@1: from django.template.loader import render_to_string gremmie@1: from django.template.defaultfilters import escapejs gremmie@1: import django.utils.simplejson as json gremmie@1: bgneal@153: from core.markup import site_markup gremmie@1: bgneal@153: gremmie@1: class MapEntry(models.Model): gremmie@1: """Represents a user's entry on the map.""" gremmie@1: user = models.ForeignKey(User) gremmie@1: location = models.CharField(max_length=255) gremmie@1: lat = models.FloatField() gremmie@1: lon = models.FloatField() gremmie@1: message = models.TextField(blank=True) gremmie@1: json = models.TextField(blank=True) gremmie@1: date_updated = models.DateTimeField(auto_now_add=True) gremmie@1: gremmie@1: def __unicode__(self): gremmie@1: return u'Entry for %s' % self.user.username gremmie@1: gremmie@1: class Meta: gremmie@1: ordering = ('-date_updated', ) gremmie@1: verbose_name_plural = 'map entries' gremmie@1: bgneal@182: def save(self, *args, **kwargs): bgneal@153: msg = render_to_string('membermap/markdown.html', { bgneal@153: 'user': self.user, bgneal@153: 'msg': site_markup(self.message)}).strip() bgneal@153: gremmie@1: self.json = json.dumps({'name': self.user.username, gremmie@1: 'lat': '%10.6f' % self.lat, gremmie@1: 'lon': '%10.6f' % self.lon, gremmie@1: 'message': msg, gremmie@1: }) bgneal@182: super(MapEntry, self).save(*args, **kwargs) gremmie@1: