pops_views.py 843 Bytes
Newer Older
Stauros Kroustouris's avatar
Stauros Kroustouris committed
1 2 3 4 5 6
from django.shortcuts import render
from django.http import Http404
from django.core.urlresolvers import reverse, NoReverseMatch


# view should be the name of the url from the rest api
Stauros Kroustouris's avatar
Stauros Kroustouris committed
7
def map_view(request, view='pops', city=None, location=None):
Stauros Kroustouris's avatar
Stauros Kroustouris committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
    if view:
        try:
            if city:
                if location:
                    url = reverse('api:' + view, args=(city, location,))
                else:
                    url = reverse('api:' + view, args=(city,))
            else:
                url = reverse('api:' + view)
        except NoReverseMatch:
            raise Http404
    if request.GET.get('tag'):
        return render(request, 'pops/map.html', {'view': '%s?tag=%s' % (url, request.GET.get('tag')), 'filter': request.GET.get('tag')})
    else:
        return render(request, 'pops/map.html', {'view': url})