~speakman/ppvalbok/trunk

« back to all changes in this revision

Viewing changes to stationmerge/views.py

  • Committer: Daniel Nyström
  • Date: 2009-05-24 21:35:17 UTC
  • Revision ID: daniel@nystrom.st-20090524213517-q6d1t2d235k5wugu
MAJOR VotingLocal refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Create your views here.
 
1
from django.views.generic.simple import direct_to_template
 
2
from swevote.models import VotingLocal, Municipality
 
3
from management.commands.valbokmanage import distance
 
4
from django.views.decorators.cache import cache_page
 
5
 
 
6
@cache_page(60 * 15)
 
7
def list_locals(request):
 
8
    all_locals = []
 
9
    for l in VotingLocal.objects.order_by('municipality__county', 'municipality', 'name'):
 
10
        if l.districts.count > 1:
 
11
            districts = [{
 
12
                    'name': d.name,
 
13
                    'address1': d.address1,
 
14
                    'address2': d.address2,
 
15
                    'address3': d.address3,
 
16
                    'distance': int(round(distance(d, l))),
 
17
                    'distributor': '*' if d.vsdata.distributor else '-',
 
18
                    'first_watch': '*' if d.vsdata.first_watch else '-',
 
19
                    'second_watch': '*' if d.vsdata.second_watch else '-',
 
20
                    'third_watch': '*' if d.vsdata.third_watch else '-',
 
21
                    } for d in l.districts.order_by('name')]
 
22
        else:
 
23
            districts = None
 
24
 
 
25
        all_locals.append({
 
26
                'id': l.id,
 
27
                'county': l.municipality.county,
 
28
                'municipality': l.municipality,
 
29
                'name': l.name,
 
30
                'address1': l.address1,
 
31
                'address2': l.address2,
 
32
                'address3': l.address3,
 
33
                'city': l.city,
 
34
                'districts_count': l.districts.count(),
 
35
                'districts': districts,
 
36
                'lat': l.lat,
 
37
                'lon': l.lon,
 
38
                'distributor': '*' if l.localdata.distributor else '-',
 
39
                'first_watch': '*' if l.localdata.first_watch else '-',
 
40
                'second_watch': '*' if l.localdata.second_watch else '-',
 
41
                'third_watch': '*' if l.localdata.third_watch else '-',
 
42
                })
 
43
 
 
44
    return direct_to_template(request, "list_votinglocals.html", {
 
45
            'all_locals': all_locals})
 
46