views.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. from django.http import JsonResponse
  2. from .models import Contrib
  3. def public_json(request):
  4. contribs = Contrib.objects.all()
  5. properties = [
  6. ('name', 'privacy_name'),
  7. ('comment', 'privacy_comment'),
  8. ('place_details', 'privacy_place_details'),
  9. ('contrib_type', True),
  10. (''),
  11. ]
  12. data = []
  13. for i in contribs:
  14. if not i.is_public():
  15. continue
  16. data.append({
  17. "id": i.pk,
  18. "type": "Feature",
  19. "geometry": {
  20. "coordinates": [
  21. i.latitude,
  22. i.longitude,
  23. ],
  24. "type": "Point",
  25. },
  26. "properties": {
  27. "name": i.get_public_field('name'),
  28. "place": {
  29. "floor": i.get_public_field('floor'),
  30. "angles": i.get_public_field('angles'),
  31. "orientations": i.get_public_field('orientations'),
  32. "roof": i.get_public_field('roof'),
  33. "floor": i.get_public_field('floor'),
  34. "floor_total": i.get_public_field('floor_total'),
  35. "comment": i.get_public_field('comment'),
  36. }
  37. }
  38. })
  39. return JsonResponse({
  40. "id": "public",
  41. "license": {
  42. "type": "ODC-BY-1.0",
  43. "url": "http:\/\/opendatacommons.org\/licenses\/by\/1.0\/"
  44. },
  45. "features": data,
  46. })