Skip to content

Commit

Permalink
Remove any uses of request.REQUEST.
Browse files Browse the repository at this point in the history
One gotcha - if we've been called via deal_with_POST (for very long
URLs), then move POST into GET before handling the request.
  • Loading branch information
dracos committed Feb 11, 2015
1 parent 69ff20e commit af2d4a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions mapit/views/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ def output_areas(request, title, format, areas, **kwargs):

def query_args(request, format, type=None):
try:
generation = int(request.REQUEST.get('generation', 0))
generation = int(request.GET.get('generation', 0))
except ValueError:
raise ViewException(format, 'Bad generation specified', 400)
if not generation:
generation = Generation.objects.current().id

try:
min_generation = int(request.REQUEST.get('min_generation', 0))
min_generation = int(request.GET.get('min_generation', 0))
except ValueError:
raise ViewException(format, 'Bad min_generation specified', 400)
if not min_generation:
min_generation = generation

if type is None:
type = request.REQUEST.get('type', '')
type = request.GET.get('type', '')

args = {}
if min_generation > -1:
Expand Down Expand Up @@ -180,7 +180,7 @@ def area_intersect(query_type, title, request, area_id, format):
raise ViewException(format, 'No polygons found', 404)

generation = Generation.objects.current()
types = [_f for _f in request.REQUEST.get('type', '').split(',') if _f]
types = [_f for _f in request.GET.get('type', '').split(',') if _f]

set_timeout(format)
try:
Expand Down Expand Up @@ -330,7 +330,7 @@ def areas_by_point(request, srid, x, y, bb=False, format='json'):
method = 'box' if bb and bb != 'polygon' else 'polygon'

args = query_args(request, format)
type = request.REQUEST.get('type', '')
type = request.GET.get('type', '')

if type and method == 'polygon':
args = dict(("area__%s" % k, v) for k, v in args.items())
Expand Down Expand Up @@ -392,5 +392,6 @@ def deal_with_POST(request, call='areas'):
if not url:

This comment has been minimized.

Copy link
@mhl

mhl Feb 12, 2015

Contributor

It doesn't relate to this pull request, but just out of interest, why are POST requests handled for /areas in particular?

This comment has been minimized.

Copy link
@mhl

mhl Feb 12, 2015

Contributor

Never mind, I've just seen that the commit message says "for very long URLs"

return output_json({'error': 'No content specified'}, code=400)
view, args, kwargs = resolve('/%s/%s' % (call, url))
request.GET = request.POST
kwargs['request'] = request
return view(*args, **kwargs)
2 changes: 1 addition & 1 deletion mapit/views/postcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def postcode(request, postcode, format=None):
raise ViewException(format, "Postcode '%s' is not valid." % postcode, 400)
postcode = get_object_or_404(Postcode, format=format, postcode=postcode)
try:
generation = int(request.REQUEST['generation'])
generation = int(request.GET['generation'])
except:
generation = Generation.objects.current()
if not hasattr(countries, 'is_special_postcode') or not countries.is_special_postcode(postcode.postcode):
Expand Down

0 comments on commit af2d4a1

Please sign in to comment.