1
# -*- coding: utf-8 -*-
3
from django.conf import settings
4
from django.http import Http404, HttpResponse
5
from django.shortcuts import get_object_or_404
6
from django.utils import simplejson
7
from swevote.models import ZipCode, EarlyVotingStation, VotingStation
10
def markers_by_zip(request, zipcode):
12
zipcode = ZipCode.objects.get(zipcode=zipcode)
13
earlystations = EarlyVotingStation.objects.filter(
14
municipality=zipcode.municipality)
15
stations = VotingStation.objects.filter(
16
municipality=zipcode.municipality)
17
allstations = itertools.chain(earlystations,stations)
18
for station in allstations:
21
"point": {"lat": str(station.lat),
22
"lon": str(station.lon)},
25
"address": (station.address1,
29
"early": True if isinstance(station, EarlyVotingStation) else False,
31
markers.append(marker)
32
return HttpResponse(simplejson.dumps({"markers": markers},
35
mimetype='application/javascript')
37
def json_marker_response(name, lat, lon):
38
return HttpResponse(simplejson.dumps(
39
{"markers": [{"point": {"lat": str(lat),
42
}, ensure_ascii=False),
43
mimetype='application/javascript')
45
def markers_by_station_id(request, stationid):
46
station = get_object_or_404(VotingStation, pk=stationid)
47
return json_marker_response(station.name, station.lat, station.lon)
49
def markers_by_early_station_id(request, stationid):
50
station = get_object_or_404(EarlyVotingStation, pk=stationid)
51
return json_marker_response(station.name, station.lat, station.lon)