comparison bandmap/models.py @ 843:09ed84a7394c

For issue #76, store pre-rendered HTML for each band map entry.
author Brian Neal <bgneal@gmail.com>
date Mon, 13 Oct 2014 16:48:43 -0500
parents 2c4f28b1c12a
children
comparison
equal deleted inserted replaced
842:b8c401cf99ca 843:09ed84a7394c
3 """ 3 """
4 import datetime 4 import datetime
5 5
6 from django.db import models 6 from django.db import models
7 from django.contrib.auth.models import User 7 from django.contrib.auth.models import User
8 from django.template.loader import render_to_string
8 9
9 10
10 class BandEntryManager(models.Manager): 11 class BandEntryManager(models.Manager):
11 def new_entry_count(self): 12 def new_entry_count(self):
12 return self.filter(is_approved=False).count() 13 return self.filter(is_approved=False).count()
23 lat = models.FloatField() 24 lat = models.FloatField()
24 lon = models.FloatField() 25 lon = models.FloatField()
25 note = models.CharField(max_length=255, blank=True) 26 note = models.CharField(max_length=255, blank=True)
26 is_active = models.BooleanField(default=True, db_index=True) 27 is_active = models.BooleanField(default=True, db_index=True)
27 is_approved = models.BooleanField(default=False, db_index=True) 28 is_approved = models.BooleanField(default=False, db_index=True)
29 html = models.TextField(blank=True)
28 30
29 objects = BandEntryManager() 31 objects = BandEntryManager()
30 32
31 class Meta: 33 class Meta:
32 ordering = ['name'] 34 ordering = ['name']
36 return u"BandMap entry for {}".format(self.name) 38 return u"BandMap entry for {}".format(self.name)
37 39
38 def save(self, *args, **kwargs): 40 def save(self, *args, **kwargs):
39 if not self.pk and not self.date_submitted: 41 if not self.pk and not self.date_submitted:
40 self.date_submitted = datetime.datetime.now() 42 self.date_submitted = datetime.datetime.now()
43 html = render_to_string('bandmap/balloon.html', {'band': self})
44 self.html = html.strip().replace('\n', '')
41 super(BandEntry, self).save(*args, **kwargs) 45 super(BandEntry, self).save(*args, **kwargs)