annotate gpp/membermap/models.py @ 163:4f07047e0a40

Shoutbox history CSS tweaks. For some reason, the table lost the top and bottom borders.
author Brian Neal <bgneal@gmail.com>
date Tue, 22 Dec 2009 03:56:26 +0000
parents 13d052fbe4f1
children 5c889b587416
rev   line source
gremmie@1 1 """
gremmie@1 2 Models for the member map application.
gremmie@1 3 """
gremmie@1 4 from django.db import models
gremmie@1 5 from django.contrib.auth.models import User
gremmie@1 6 from django.template.loader import render_to_string
gremmie@1 7 from django.template.defaultfilters import escapejs
gremmie@1 8 import django.utils.simplejson as json
gremmie@1 9
bgneal@153 10 from core.markup import site_markup
gremmie@1 11
bgneal@153 12
gremmie@1 13 class MapEntry(models.Model):
gremmie@1 14 """Represents a user's entry on the map."""
gremmie@1 15 user = models.ForeignKey(User)
gremmie@1 16 location = models.CharField(max_length=255)
gremmie@1 17 lat = models.FloatField()
gremmie@1 18 lon = models.FloatField()
gremmie@1 19 message = models.TextField(blank=True)
gremmie@1 20 json = models.TextField(blank=True)
gremmie@1 21 date_updated = models.DateTimeField(auto_now_add=True)
gremmie@1 22
gremmie@1 23 def __unicode__(self):
gremmie@1 24 return u'Entry for %s' % self.user.username
gremmie@1 25
gremmie@1 26 class Meta:
gremmie@1 27 ordering = ('-date_updated', )
gremmie@1 28 verbose_name_plural = 'map entries'
gremmie@1 29
gremmie@1 30 def save(self, force_insert=False, force_update=False):
bgneal@153 31 msg = render_to_string('membermap/markdown.html', {
bgneal@153 32 'user': self.user,
bgneal@153 33 'msg': site_markup(self.message)}).strip()
bgneal@153 34
gremmie@1 35 self.json = json.dumps({'name': self.user.username,
gremmie@1 36 'lat': '%10.6f' % self.lat,
gremmie@1 37 'lon': '%10.6f' % self.lon,
gremmie@1 38 'message': msg,
gremmie@1 39 })
gremmie@1 40 super(MapEntry, self).save(force_insert, force_update)
gremmie@1 41