|
@@ -1,10 +1,10 @@
|
|
|
-from django.http import JsonResponse
|
|
|
+from django.http import JsonResponse, HttpResponseForbidden
|
|
|
from django.views.generic import View
|
|
|
|
|
|
from .models import Contrib
|
|
|
|
|
|
|
|
|
-class JSONView(View):
|
|
|
+class JSONContribView(View):
|
|
|
def get(self, request):
|
|
|
return JsonResponse({
|
|
|
"id": self.ID,
|
|
@@ -12,15 +12,16 @@ class JSONView(View):
|
|
|
"features": self.get_features(),
|
|
|
})
|
|
|
|
|
|
+ PLACE_PROPERTIES = [
|
|
|
+ 'floor', 'angles', 'orientations', 'roof', 'floor', 'floor_total']
|
|
|
+
|
|
|
|
|
|
-class PublicJSON(JSONView):
|
|
|
+class PublicJSON(JSONContribView):
|
|
|
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()
|
|
@@ -41,6 +42,7 @@ class PublicJSON(JSONView):
|
|
|
"type": "Point",
|
|
|
},
|
|
|
"properties": {
|
|
|
+ "contrib_type": i.contrib_type,
|
|
|
"name": i.get_public_field('name'),
|
|
|
"place": {
|
|
|
k: i.get_public_field(k) for k in self.PLACE_PROPERTIES
|
|
@@ -49,3 +51,47 @@ class PublicJSON(JSONView):
|
|
|
}
|
|
|
})
|
|
|
return data
|
|
|
+
|
|
|
+
|
|
|
+class PrivateJSON(JSONContribView):
|
|
|
+ ID = 'private'
|
|
|
+ LICENSE = {
|
|
|
+ "type": "Copyright",
|
|
|
+ }
|
|
|
+
|
|
|
+ def dispatch(self, request, *args, **kwargs):
|
|
|
+ if hasattr(request, 'user') and request.user.is_staff:
|
|
|
+ return super().dispatch(request, *args, **kwargs)
|
|
|
+ else:
|
|
|
+ return HttpResponseForbidden('Need staff access')
|
|
|
+
|
|
|
+ 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": {
|
|
|
+ "contrib_type": i.contrib_type,
|
|
|
+ "name": i.name,
|
|
|
+ "place": {
|
|
|
+ k: getattr(i, k) for k in self.PLACE_PROPERTIES
|
|
|
+ },
|
|
|
+ "comment": i.comment,
|
|
|
+ "phone": i.phone,
|
|
|
+ "email": i.email
|
|
|
+ }
|
|
|
+ })
|
|
|
+ return data
|