def items_atom(request): """ handles the items.atom API endpoint """ try: items, params = build_item_query(_copy_nomulti(request.GET)) # could test for extra params aside from jsonp... return APIGETResponse(request, _items_atom(items), content_type=ATOM_CONTENT_TYPE) except QueryError as err: return HttpResponseBadRequest(err.message)
def items_atom(request): """ handles the items.atom API endpoint """ try: items, params = build_item_query(_copy_nomulti(request.GET)) # could test for extra params aside from jsonp... return APIGETResponse(request, _items_atom(items), content_type=ATOM_CONTENT_TYPE) except QueryError as err: return HttpResponse(err.message, status=400)
def items_atom(request): """ handles the items.atom API endpoint """ try: items, params = build_item_query(request) # could test for extra params aside from jsonp... items = [item for item in items if item.location is not None] return APIGETResponse(request, _items_atom(items), content_type=ATOM_CONTENT_TYPE) except QueryError as err: return HttpResponseBadRequest(err.message)
def items_json(request): """ handles the items.json API endpoint """ # TODO: support filtering by block + radius, and somehow support # adding extra info eg. popup html. Together, that would allow # this to replace ebub.db.views.newsitems_geojson. See #81 try: items, params = build_item_query(_copy_nomulti(request.GET)) # could test for extra params aside from jsonp... items = [item for item in items if item.location is not None] items_geojson_dict = {'type': 'FeatureCollection', 'features': items } return APIGETResponse(request, items_geojson_dict, content_type=JSON_CONTENT_TYPE) except QueryError as err: return HttpResponseBadRequest(err.message)
def items_json(request): """ handles the items.json API endpoint """ # TODO: support filtering by block + radius, and somehow support # adding extra info eg. popup html. Together, that would allow # this to replace ebub.db.views.newsitems_geojson. See #81 try: items, params = build_item_query(request) # could test for extra params aside from jsonp... items = [item for item in items if item.location is not None] items_geojson_dict = {'type': 'FeatureCollection', 'features': items} return APIGETResponse(request, items_geojson_dict, content_type=JSON_CONTENT_TYPE) except QueryError as err: return HttpResponseBadRequest(err.message)
def map_items_json(request): """ slightly briefer and less attribute-accessing rendition of the REST api's geojson response. includes only attributes used by the map. """ items, params = build_item_query(request) def _item_to_feature(item): geom = simplejson.loads(item.location.geojson) result = { 'type': 'Feature', 'geometry': geom, } # Uh-oh, this is not y10k compliant :-p sort_key = '%d-%d-%d-%s-%d' % (9999 - item.item_date.year, 13 - item.item_date.month, 32 - item.item_date.day, item.title, item.id) props = {'id': item.id, 'openblock_type': 'newsitem', 'icon': item.schema.get_map_icon_url(), 'color': item.schema.map_color, 'sort': sort_key } result['properties'] = props return result items = [_item_to_feature(item) for item in items if item.location is not None] items_geojson_dict = {'type': 'FeatureCollection', 'features': items } body = simplejson.dumps(items_geojson_dict) response = HttpResponse(body, content_type=JSON_CONTENT_TYPE) patch_response_headers(response, cache_timeout=3600) return response
def map_items_json(request): """ slightly briefer and less attribute-accessing rendition of the REST api's geojson response. includes only attributes used by the map. """ items, params = build_item_query(request) def _item_to_feature(item): geom = simplejson.loads(item.location.geojson) result = { 'type': 'Feature', 'geometry': geom, } # Uh-oh, this is not y10k compliant :-p sort_key = '%d-%d-%d-%s-%d' % (9999 - item.item_date.year, 13 - item.item_date.month, 32 - item.item_date.day, item.title, item.id) props = { 'id': item.id, 'openblock_type': 'newsitem', 'icon': item.schema.get_map_icon_url(), 'color': item.schema.map_color, 'sort': sort_key } result['properties'] = props return result items = [ _item_to_feature(item) for item in items if item.location is not None ] items_geojson_dict = {'type': 'FeatureCollection', 'features': items} body = simplejson.dumps(items_geojson_dict) response = HttpResponse(body, content_type=JSON_CONTENT_TYPE) patch_response_headers(response, cache_timeout=3600) return response
def map_items_json(request): """ slightly briefer and less attribute-accessing rendition of the api's geojson response. includes only attributes used by the map. """ items, params = build_item_query(_copy_nomulti(request.GET)) def _item_to_feature(item): geom = simplejson.loads(item.location.geojson) result = {"type": "Feature", "geometry": geom} sort_key = "%d-%d-%d-%s-%d" % ( 9999 - item.item_date.year, 13 - item.item_date.month, 32 - item.item_date.day, item.title, item.id, ) props = { "id": item.id, "openblock_type": "newsitem", "icon": item.schema.map_icon_url, "color": item.schema.map_color, "sort": sort_key, } result["properties"] = props return result items = [_item_to_feature(item) for item in items if item.location is not None] items_geojson_dict = {"type": "FeatureCollection", "features": items} body = simplejson.dumps(items_geojson_dict) response = HttpResponse(body, content_type=JSON_CONTENT_TYPE) patch_response_headers(response, cache_timeout=3600) return response