Mercurial > public > sg101
comparison gpp/membermap/models.py @ 266:4532ed27bed8
Fixing #112. Rework member map to untangle user profile and avatar cache from the membermap (since it wasn't really working anyway).
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 25 Sep 2010 18:04:44 +0000 |
parents | 5c889b587416 |
children |
comparison
equal
deleted
inserted
replaced
265:1ba2c6bf6eb7 | 266:4532ed27bed8 |
---|---|
1 """ | 1 """ |
2 Models for the member map application. | 2 Models for the member map application. |
3 """ | 3 """ |
4 import datetime | |
4 from django.db import models | 5 from django.db import models |
5 from django.contrib.auth.models import User | 6 from django.contrib.auth.models import User |
6 from django.template.loader import render_to_string | |
7 from django.template.defaultfilters import escapejs | |
8 import django.utils.simplejson as json | |
9 | 7 |
10 from core.markup import site_markup | 8 from core.markup import site_markup |
11 | 9 |
12 | 10 |
13 class MapEntry(models.Model): | 11 class MapEntry(models.Model): |
15 user = models.ForeignKey(User) | 13 user = models.ForeignKey(User) |
16 location = models.CharField(max_length=255) | 14 location = models.CharField(max_length=255) |
17 lat = models.FloatField() | 15 lat = models.FloatField() |
18 lon = models.FloatField() | 16 lon = models.FloatField() |
19 message = models.TextField(blank=True) | 17 message = models.TextField(blank=True) |
20 json = models.TextField(blank=True) | 18 html = models.TextField(blank=True) |
21 date_updated = models.DateTimeField(auto_now_add=True) | 19 date_updated = models.DateTimeField() |
22 | 20 |
23 def __unicode__(self): | 21 def __unicode__(self): |
24 return u'Entry for %s' % self.user.username | 22 return u'Map entry for %s' % self.user.username |
25 | 23 |
26 class Meta: | 24 class Meta: |
27 ordering = ('-date_updated', ) | 25 ordering = ('-date_updated', ) |
28 verbose_name_plural = 'map entries' | 26 verbose_name_plural = 'map entries' |
29 | 27 |
30 def save(self, *args, **kwargs): | 28 def save(self, *args, **kwargs): |
31 msg = render_to_string('membermap/markdown.html', { | 29 self.html = site_markup(self.message) |
32 'user': self.user, | 30 self.date_updated = datetime.datetime.now() |
33 'msg': site_markup(self.message)}).strip() | |
34 | |
35 self.json = json.dumps({'name': self.user.username, | |
36 'lat': '%10.6f' % self.lat, | |
37 'lon': '%10.6f' % self.lon, | |
38 'message': msg, | |
39 }) | |
40 super(MapEntry, self).save(*args, **kwargs) | 31 super(MapEntry, self).save(*args, **kwargs) |
41 | 32 |