summaryrefslogtreecommitdiff
path: root/app/projects/views.py
blob: e9c755ffae658d81a48e9ac7eb9fbbad6a55d980 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from django.shortcuts import render_to_response,get_object_or_404
from django.template import RequestContext
from django.db.models import get_model
from django.http import HttpResponse
from django.core import serializers

from projects.shortcuts import render_to_geojson
from projects.models.base import Project
from projects.models.fiveby import FiveBy
from projects.models.natparks import NationalParks
from projects.models.gifs import AnimatedGif

projects = {'5x5':'FiveBy','6x6':'SixBy','national-parks':'NationalParks','code':'Code'}

"""
Projects by slug
"""
def detail(request,slug):
    name = projects[slug]
    model = get_model('projects', name)
    if slug == 'national-parks':
        qs = model.objects.filter(visited__exact=True).order_by("-date_visited_begin")
    else:
        qs = model.objects.filter(status__exact=1)
    context = {
        "object_list" : qs,
            }
    template = 'details/%s.html' %(slug)
    return render_to_response(template, context, context_instance = RequestContext(request))


def gif_detail(request,slug):
    obj = get_object_or_404(AnimatedGif, slug__exact=slug)
    return render_to_response('details/gifs.html', {'object': obj}, context_instance=RequestContext(request))


def data_json(request, id):
    qs = NationalParks.objects.filter(pk=id)
    return render_to_geojson(
        qs,
        included_fields=['id',],
        geom_attribute='mpoly',
        mimetype = 'application/json',
        pretty_print=True
    )