def table(request, tableid=None): if request.method == 'POST': return handle_table_post(request, tableid) # Otherwise, it's a GET wwg = WordwallsGame() if tableid: # Check if the user is allowed to enter this table. permitted = wwg.allow_access(request.user, tableid) if gargoyle.is_active('disable_games', request): permitted = False if not permitted: return render(request, 'wordwalls/notPermitted.html', {'tablenum': tableid}) params = wwg.get_add_params(tableid) # Add styling params from user's profile (for styling table # tiles, backgrounds, etc) profile = request.user.aerolithprofile style = profile.customWordwallsStyle if style != "": params['style'] = style meta_info = get_create_meta_info() usermeta = get_user_meta_info(request.user) wgm = None if tableid: wgm = wwg.get_wgm(tableid, False) return render( request, 'wordwalls/table.html', { 'tablenum': tableid if tableid else 0, 'current_host': wgm.host.username if wgm else '', 'multiplayer': (json.dumps(wgm.playerType == WordwallsGameModel. MULTIPLAYER_GAME if wgm else False)), 'user': json.dumps(usermeta), 'addParams': json.dumps(params), 'avatarUrl': profile.avatarUrl, 'lexicon': wgm.lexicon.lexiconName if wgm else None, 'default_lexicon': profile.defaultLexicon.pk, 'challenge_info': json.dumps(meta_info['challenge_info']), 'available_lexica': json.dumps(meta_info['lexica']), 'intercom_app_id': settings.INTERCOM_APP_ID, # Use the webpack server if DEBUG is on. XXX This might not actually # be a good test; consider using an IS_PRODUCTION flag. 'STATIC_SRV': (settings.WEBPACK_DEV_SERVER_URL if (settings.USE_WEBPACK_DEV_SERVER and settings.DEBUG) else '') })
def table_response(tablenum): game = WordwallsGame() addl_params = game.get_add_params(tablenum) wgm = game.get_wgm(tablenum, lock=False) # Sometimes, 'tempListName' will not be in addl_params, when this # is loading an already existing saved list. Instead, get from saveName. if addl_params.get("saveName"): autosave = True list_name = addl_params["saveName"] else: autosave = False list_name = addl_params["tempListName"] return response( { "tablenum": tablenum, "list_name": list_name, "lexicon": wgm.lexicon.lexiconName, "autosave": autosave, "multiplayer": addl_params.get("multiplayer", False), } )
def table(request, id): if request.method == 'POST': action = request.POST['action'] logger.debug(u'user=%s, action=%s, table=%s', request.user, action, id) if action == "start": return start_game(request, id) elif action == "guess": logger.debug(u'guess=%s', request.POST['guess']) wwg = WordwallsGame() state = wwg.guess(request.POST['guess'].strip(), id, request.user) if state is None: return response(_('Quiz is already over.'), status=StatusCode.BAD_REQUEST) logger.debug(u'table=%s Returning %s', id, state) return response({'g': state['going'], 'C': state['alphagram'], 'w': state['word'], 'a': state['already_solved']}) elif action == "gameEnded": wwg = WordwallsGame() ret = wwg.check_game_ended(id) # 'going' is the opposite of 'game ended' return response({'g': not ret}) elif action == "giveUp": wwg = WordwallsGame() ret = wwg.give_up(request.user, id) return response({'g': not ret}) elif action == "save": wwg = WordwallsGame() ret = wwg.save(request.user, id, request.POST['listname']) return response(ret) elif action == "giveUpAndSave": wwg = WordwallsGame() ret = wwg.give_up_and_save(request.user, id, request.POST['listname']) # this shouldn't return a response, because it's not going to be # caught by the javascript logger.debug("Give up and saving returned: %s" % ret) return response(ret) elif action == "savePrefs": profile = request.user.aerolithprofile profile.customWordwallsStyle = request.POST['prefs'] profile.save() return response({'success': True}) elif action == "getDcData": wwg = WordwallsGame() dcId = wwg.get_dc_id(id) if dcId > 0: leaderboardData = getLeaderboardDataDcInstance( DailyChallenge.objects.get(pk=dcId)) return response(leaderboardData) else: return response({'success': False}, status=StatusCode.BAD_REQUEST) else: # it's a GET wwg = WordwallsGame() permitted = wwg.permit(request.user, id) if gargoyle.is_active('disable_games', request): permitted = False if not permitted: return render(request, 'wordwalls/notPermitted.html', {'tablenum': id}) params = wwg.get_add_params(id) # Add styling params from user's profile (for styling table # tiles, backgrounds, etc) profile = request.user.aerolithprofile style = profile.customWordwallsStyle if style != "": params['style'] = style return render(request, 'wordwalls/table.html', {'tablenum': id, 'username': request.user.username, 'addParams': json.dumps(params), 'avatarUrl': profile.avatarUrl, 'CURRENT_VERSION': CURRENT_VERSION, 'lexicon': wwg.get_wgm(id).lexicon })