def update(request, gameid): game = get_object_or_404(Game, id=gameid) if game.is_locked(): return HttpResponse(simplejson.dumps({ 'success': False, 'message': 'Someone else is updating that game right now. Please wait.' }), mimetype='application/json') else: game.lock() try: p = PageParser() newGame = p.Update(game) if newGame: return HttpResponse(simplejson.dumps({ 'success': True, 'curPage': newGame.currentPage, 'maxPages': newGame.maxPages }), mimetype='application/json') else: game.save() return HttpResponse(simplejson.dumps({ 'success': False, 'message': 'There was a problem either downloading or parsing the forum page. Please try again later.' }), mimetype='application/json') except: game.save() raise
def check_update_game(game): if game.is_locked(): return game else: game.lock() try: p = PageParser() newGame = p.Update(game) if newGame: return newGame else: game.save() return game except: return game