Permalink
Browse files

Merge branch 'master' of https://github.com/JeffHeard/ga_resources

  • Loading branch information...
2 parents 7245e2c + 41de5a9 commit 82d5ff49f2aff6f499320189fe0124e7014a46f9 @jeffersonheard committed Mar 5, 2014
Showing with 26 additions and 15 deletions.
  1. +7 −4 utils.py
  2. +1 −2 views/ows.py
  3. +18 −9 views/rest_data.py
View
@@ -32,9 +32,9 @@ def json_or_jsonp(r, i, code=200):
i = json.dumps(i)
if 'callback' in r.REQUEST:
- return HttpResponse('{c}({i})'.format(c=r.REQUEST['callback'], i=i), mimetype='text/javascript')
+ return HttpResponse('{c}({i});'.format(c=r.REQUEST['callback'], i=i), mimetype='text/javascript')
elif 'jsonp' in r.REQUEST:
- return HttpResponse('{c}({i})'.format(c=r.REQUEST['jsonp'], i=i), mimetype='text/javascript')
+ return HttpResponse('{c}({i});'.format(c=r.REQUEST['jsonp'], i=i), mimetype='text/javascript')
else:
return HttpResponse(i, mimetype='application/json', status=code)
@@ -70,15 +70,18 @@ def authorize(request, page=None, edit=False, add=False, delete=False, view=Fals
if auth and page is not None:
request.user = user
+ if getattr(page, 'owner') and user == page.owner:
+ return user
if edit:
auth = page.can_change(request)
if add:
auth = auth and page.can_add(request)
if delete:
auth = auth and page.can_delete(request)
elif view:
- auth = auth and (not hasattr(page, 'can_view')) or \
- (auth and hasattr(page, 'can_view') and page.can_view(request))
+ auth = auth and ((not hasattr(page, 'public')) or page.public) \
+ and ((not hasattr(page, 'can_view')) or \
+ (auth and hasattr(page, 'can_view') and page.can_view(request)))
if do_raise and not auth:
raise PermissionDenied(json.dumps({
View
@@ -245,8 +245,7 @@ def tms(request, layer, z, x, y, **kwargs):
layer_slug = layer
layer_instance = RenderedLayer.objects.get(slug=layer_slug)
- user = authorize(request, page=layer, view=True)
- dispatch.api_accessed.send(RenderedLayer, instance=layer_instance, user=user)
+ # dispatch.api_accessed.send(RenderedLayer, instance=layer_instance, user=user)
style = request.GET.get('style', layer_instance.default_style.slug)
tms = CacheManager.get().get_tile_cache([layer], [style])
return HttpResponse(tms.fetch_tile(z, x, y), mimetype='image/png')
View
@@ -27,6 +27,15 @@ def get_user(request):
return request.user
+def geojson_transform(request, data):
+ if request.REQUEST.get('format','wkt') == 'geojsonreal':
+ if isinstance(data, list):
+ return { 'type' : 'FeatureCollection', 'features' : [{ 'type' : 'Feature', 'geometry' : feature['GEOMETRY'], 'properties' : feature } for feature in data] }
+ else:
+ return { 'type' : 'Feature', 'properties' : data, 'geometry' : data['GEOMETRY'] }
+ else:
+ return data
+
def create_dataset(request):
@@ -230,13 +239,13 @@ def get_row(request, slug=None, ogc_fid=None, *args, **kwargs):
format = request.REQUEST.get('format', 'wkt')
try:
- row = ds.driver_instance.get_row(int(ogc_fid), geometry_format=format)
+ row = ds.driver_instance.get_row(int(ogc_fid), geometry_format=format if format != 'geojsonreal' else 'geojson')
except:
row = None
dispatch.api_accessed.send(sender=DataResource, instance=ds, user=user)
dispatch.features_retrieved.send(sender=DataResource, instance=ds, user=user, count=1, fid=ogc_fid)
- return json_or_jsonp(request, row)
+ return json_or_jsonp(request, geojson_transform(request, row))
def get_rows(request, slug=None, ogc_fid_start=None, ogc_fid_end=None, limit=None, *args, **kwargs):
@@ -246,15 +255,15 @@ def get_rows(request, slug=None, ogc_fid_start=None, ogc_fid_end=None, limit=Non
format = request.REQUEST.get('format', 'wkt')
if ogc_fid_end:
- rows = ds.driver_instance.get_rows(int(ogc_fid_start), int(ogc_fid_end), geometry_format=format)
+ rows = ds.driver_instance.get_rows(int(ogc_fid_start), int(ogc_fid_end), geometry_format=format if format != 'geojsonreal' else 'geojson')
elif limit:
- rows = ds.driver_instance.get_rows(int(ogc_fid_start), limit=int(limit), geometry_format=format)
+ rows = ds.driver_instance.get_rows(int(ogc_fid_start), limit=int(limit), geometry_format=format if format != 'geojsonreal' else 'geojson')
else:
- rows = ds.driver_instance.get_rows(int(ogc_fid_start), geometry_format=format)
+ rows = ds.driver_instance.get_rows(int(ogc_fid_start), geometry_format=format if format != 'geojsonreal' else 'geojson')
dispatch.api_accessed.send(sender=DataResource, instance=ds, user=user)
dispatch.features_retrieved.send(sender=DataResource, instance=ds, user=user, count=len(rows))
- return json_or_jsonp(request, rows)
+ return json_or_jsonp(request, geojson_transform(request, rows))
def query(request, slug=None, **kwargs):
@@ -277,12 +286,12 @@ def query(request, slug=None, **kwargs):
only = only.split(',')
rest = {k: v for k, v in request.REQUEST.items() if
- k not in {'limit', 'start', 'end', 'only', 'g', 'op', 'format'}}
+ k not in {'limit', 'start', 'end', 'only', 'g', 'op', 'format', 'api_key','callback','jsonp', '_'}}
rows = ds.driver_instance.query(
query_mbr=geometry_mbr,
query_geometry=geometry,
- geometry_format=geometry_format,
+ geometry_format=geometry_format if geometry_format != 'geojsonreal' else 'geojson',
geometry_operator=geometry_operator,
query_geometry_srid=srid,
limit=limit,
@@ -294,7 +303,7 @@ def query(request, slug=None, **kwargs):
dispatch.api_accessed.send(sender=DataResource, instance=ds, user=user)
dispatch.features_retrieved.send(sender=DataResource, instance=ds, user=user, count=len(rows))
- return json_or_jsonp(request, rows)
+ return json_or_jsonp(request, geojson_transform(request, rows))
class CRUDView(View):

0 comments on commit 82d5ff4

Please sign in to comment.