comparison bandmap/views.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 7735f8a6bd1f
children bb7e2fc24690
comparison
equal deleted inserted replaced
842:b8c401cf99ca 843:09ed84a7394c
5 5
6 from django.contrib.auth.decorators import login_required 6 from django.contrib.auth.decorators import login_required
7 from django.shortcuts import redirect, render 7 from django.shortcuts import redirect, render
8 from django.contrib import messages as django_messages 8 from django.contrib import messages as django_messages
9 from django.http import HttpResponse 9 from django.http import HttpResponse
10 from django.template.loader import render_to_string
11 from django.core.cache import cache 10 from django.core.cache import cache
12 from django.conf import settings 11 from django.conf import settings
13 12
14 from bandmap.forms import BandForm 13 from bandmap.forms import BandForm
15 from bandmap.models import BandEntry 14 from bandmap.models import BandEntry
65 elif show_param == 'inactive': 64 elif show_param == 'inactive':
66 qs = qs.filter(is_active=False) 65 qs = qs.filter(is_active=False)
67 66
68 bands = [] 67 bands = []
69 for band in qs.iterator(): 68 for band in qs.iterator():
70 note = render_to_string('bandmap/balloon.html', {'band': band})
71 note = note.strip().replace('\n', '')
72 bands.append({ 69 bands.append({
73 'name': band.name, 70 'name': band.name,
74 'lat': band.lat, 71 'lat': band.lat,
75 'lon': band.lon, 72 'lon': band.lon,
76 'is_active': band.is_active, 73 'is_active': band.is_active,
77 'note': note, 74 'note': band.html,
78 }) 75 })
79 results = json.dumps(bands) 76 results = json.dumps(bands)
80 77
81 # Store in cache 78 # Store in cache
82 cache.set(cache_key, results, 300) 79 cache.set(cache_key, results, 600)
83 80
84 return HttpResponse(results, content_type='application/json') 81 return HttpResponse(results, content_type='application/json')