123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- from django.http import JsonResponse
- from django.views.generic import View
- from .models import Contrib
- class JSONView(View):
- def get(self, request):
- return JsonResponse({
- "id": self.ID,
- "license": self.LICENSE,
- "features": self.get_features(),
- })
- class PublicJSON(JSONView):
- ID = 'public'
- LICENSE = {
- "type": "ODC-BY-1.0",
- "url": "http:\/\/opendatacommons.org\/licenses\/by\/1.0\/"
- }
- PLACE_PROPERTIES = [
- 'floor', 'angles', 'orientations', 'roof', 'floor', 'floor_total']
- def get_features(self):
- contribs = Contrib.objects.all()
- data = []
- for i in contribs:
- if not i.is_public():
- continue
- data.append({
- "id": i.pk,
- "type": "Feature",
- "geometry": {
- "coordinates": [
- i.latitude,
- i.longitude,
- ],
- "type": "Point",
- },
- "properties": {
- "name": i.get_public_field('name'),
- "place": {
- k: i.get_public_field(k) for k in self.PLACE_PROPERTIES
- },
- "comment": i.get_public_field('comment'),
- }
- })
- return data
|