set position to default value if POST request don't have position argument

TNL-922
This commit is contained in:
zubair-arbi
2014-12-10 14:44:30 +05:00
parent 8a685ceca0
commit 1d6d2f2a7f
2 changed files with 46 additions and 1 deletions

View File

@@ -88,7 +88,13 @@ class SequenceModule(SequenceFields, XModule):
def handle_ajax(self, dispatch, data): # TODO: bounds checking
''' get = request.POST instance '''
if dispatch == 'goto_position':
self.position = int(data['position'])
# set position to default value if either 'position' argument not
# found in request or it is a non-positive integer
position = data.get('position', u'1')
if position.isdigit() and int(position) > 0:
self.position = int(position)
else:
self.position = 1
return json.dumps({'success': True})
raise NotFoundError('Unexpected dispatch type')