combo/combo/apps/maps/views.py

37 lines
1.3 KiB
Python

# combo - content management system
# Copyright (C) 2017 Entr'ouvert
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
from django.views.generic.base import View
from django.http import HttpResponse, Http404, HttpResponseForbidden
from .models import Map
class GeojsonView(View):
def get(self, request, *args, **kwargs):
try:
cell = Map.objects.get(pk=kwargs['cell_id'])
except Map.DoesNotExist:
raise Http404()
if cell.page.is_visible(request.user) and cell.is_visible(request.user):
geojson = cell.get_geojson(request)
content_type = 'application/json'
return HttpResponse(json.dumps(geojson), content_type=content_type)
return HttpResponseForbidden()