|
@@ -1,52 +1,51 @@
|
|
|
from django.http import JsonResponse
|
|
|
+from django.views.generic import View
|
|
|
|
|
|
from .models import Contrib
|
|
|
|
|
|
|
|
|
-def public_json(request):
|
|
|
- contribs = Contrib.objects.all()
|
|
|
-
|
|
|
- properties = [
|
|
|
- ('name', 'privacy_name'),
|
|
|
- ('comment', 'privacy_comment'),
|
|
|
- ('place_details', 'privacy_place_details'),
|
|
|
- ('contrib_type', True),
|
|
|
- (''),
|
|
|
- ]
|
|
|
-
|
|
|
- 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": {
|
|
|
- "floor": i.get_public_field('floor'),
|
|
|
- "angles": i.get_public_field('angles'),
|
|
|
- "orientations": i.get_public_field('orientations'),
|
|
|
- "roof": i.get_public_field('roof'),
|
|
|
- "floor": i.get_public_field('floor'),
|
|
|
- "floor_total": i.get_public_field('floor_total'),
|
|
|
+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 JsonResponse({
|
|
|
- "id": "public",
|
|
|
- "license": {
|
|
|
- "type": "ODC-BY-1.0",
|
|
|
- "url": "http:\/\/opendatacommons.org\/licenses\/by\/1.0\/"
|
|
|
- },
|
|
|
- "features": data,
|
|
|
- })
|
|
|
+ })
|
|
|
+ return data
|