Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Extend api and add wikipedia api endpoint

  • Loading branch information...
commit c07d5367768f7af54ee0ad37396e63499a7afdaf 1 parent e4a0986
@jarus jarus authored
View
44 krprj/api/resources.py
@@ -1,3 +1,5 @@
+import json
+
from django.contrib.gis.geos import Point, Polygon
from tastypie import fields
@@ -6,19 +8,49 @@
from krprj.krunite.models import KircheUnite
from krprj.osm.models import KircheOsm
+from krprj.wikipedia.models import KircheWikipedia
class OSMPlacesResource(GeoModelResource):
class Meta:
queryset = KircheOsm.objects.all()
+ allowed_methods = ['get']
resource_name = 'osm_places'
- max_limit = 500
+ max_limit = 50
+
+ place = fields.ToOneField('krprj.api.resources.PlacesResource', 'unite',
+ null=True)
+
+ def dehydrate_addional_fields(self, bundle):
+ return json.loads(bundle.data.get('addional_fields', '{}'))
+
+
+class WikipediaArticleResource(GeoModelResource):
+
+ class Meta:
+ queryset = KircheWikipedia.objects.all()
+ allowed_methods = ['get']
+ resource_name = 'wikipedia_articles'
+ max_limit = 50
+
+ contents = fields.CharField(attribute='contents', null=True,
+ use_in='detail')
+
+ place = fields.ToOneField('krprj.api.resources.PlacesResource', 'unite',
+ null=True)
+
+ def dehydrate_infobox(self, bundle):
+ return json.loads(bundle.data['infobox'])
class PlacesResource(GeoModelResource):
- osm_places = fields.ToManyField(OSMPlacesResource, 'kircheosm_set', full=True)
+ osm_places = fields.ToManyField(OSMPlacesResource, 'kircheosm_set',
+ full=False, use_in='detail')
+ wikipedia_articles = fields.ToManyField(WikipediaArticleResource,
+ 'kirchewikipedia_set',
+ full=False, use_in='detail')
class Meta:
queryset = KircheUnite.objects.all()
@@ -28,7 +60,7 @@ class Meta:
filtering = {
"name": ('exact', 'startswith', 'contains')
}
- max_limit = 50
+ max_limit = 500
def build_filters(self, filters=None):
if filters is None:
@@ -62,12 +94,6 @@ def build_filters(self, filters=None):
return orm_filters
- def get_list(self, request, **kwargs):
- if 'without_relations' in request.GET:
- self.fields.pop("osm_places", None)
- self._meta.max_limit = 500
- return super(PlacesResource, self).get_list(request, **kwargs)
-
def alter_list_data_to_serialize(self, request, data):
if 'request_id' in request.GET:
data['meta']['request_id'] = request.GET['request_id']
View
4 krprj/api/urls.py
@@ -1,10 +1,12 @@
from django.conf.urls import patterns, include
from tastypie.api import Api
-from .resources import PlacesResource, OSMPlacesResource
+from .resources import PlacesResource, OSMPlacesResource, \
+ WikipediaArticleResource
v1_api = Api(api_name='v1')
v1_api.register(PlacesResource())
v1_api.register(OSMPlacesResource())
+v1_api.register(WikipediaArticleResource())
urlpatterns = patterns('', (r'^', include(v1_api.urls)))
View
2  krprj/worshipmap/static/lib/kirchenreich/worshipmap.js
@@ -77,7 +77,7 @@ kr.refresh_markers = function(bounds){
$("#nav_status").html('<span class="label label-warning">Loading...</span>');
kr.request_id++;
- var url = "/api/v1/places/?without_relations&limit=300&in_bbox=" + bounds.toBBoxString() + "&request_id=" + kr.request_id;
+ var url = "/api/v1/places/?limit=500&in_bbox=" + bounds.toBBoxString() + "&request_id=" + kr.request_id;
if (kr.on_mobile()){
url = url + "&limit=100";
}
Please sign in to comment.
Something went wrong with that request. Please try again.