def get(self, request, code, *args, **kwargs): self.game = _GameMiddleware(code) if not self.game: return handler(request, 404) self.player = GamePlayerMiddleware(request.user.username) if not self.player.is_authorized_to_access_game(code): return handler(request, 404) self.maps = MapsMiddleware() lat_long = [] visited = self.player.locations_visited(code) for location in visited: if location[1] != "???": temp = [] latitude, longitude = self.maps.get_coordinate(location[1]) temp.append(float(latitude)) temp.append(float(longitude)) temp.append(location[1]) lat_long.append(temp) return render(request, self.template_name, context={ 'game_details': self.game.get_code_and_name(), 'visited': self.player.locations_visited(code), 'lat_long': lat_long })
def post(self, request, code, *args, **kwargs): self.game = _GameMiddleware(code) self.creator = GameCreatorMiddleware(request.user) self.maps = MapsMiddleware() if not self.creator.is_authorized_to_access_game(code): return handler(request, 404) if 'location_order' in request.POST.keys(): location = request.POST['location_order'].title().strip() return self._add_location(request, code, location) # Search for the location and return latitude and longitude to display to the user for confirmation elif 'locationSearch' in request.POST.keys(): location = request.POST['locationSearch'].title() try: latitude, longitude = self.maps.get_coordinate( request.POST['locationSearch']) latitude = float(latitude) longitude = float(longitude) except: latitude = -33.865143 longitude = 151.209900 location = location + " * Not Found - Please Try Again *" return render(request, self.template_name, context={ 'game_details': self.game.get_code_and_name(), 'lat_long': [latitude, longitude], 'location_name': location, 'code': code })
def get(self, request, game_code, location_code, *args, **kwargs): self.locations = GameCreatorMiddleware(request.user.username) self.game = _GameMiddleware(game_code) self.maps = MapsMiddleware() this_location = self.locations.get_location_by_code(location_code) this_location_copy = self.locations.get_location_by_code(location_code) for x in this_location: location_name = str(x) if not self.locations.is_authorized_to_access_game(game_code): return handler(request, 404) latitude, longitude = self.maps.get_coordinate(location_name) latitude = float(latitude) longitude = float(longitude) return render(request, self.template_name, context={ 'locations_code': this_location, 'game_details': self.game.get_code_and_name(), 'game_player_name': self.locations.get_name(), 'game_player_username': self.locations.get_username(), 'lat_long': [latitude, longitude], 'game_code': self.game.game.code, 'location_code': this_location_copy.first() })
def get(self, request, code, *args, **kwargs): self.game = _GameMiddleware(code) self.creator = GameCreatorMiddleware(request.user) if not self.creator.is_authorized_to_access_game(code): return handler(request, 404) return render(request, self.template_name, context={ 'game_details': self.game.get_code_and_name(), 'lat_long': [-33.865143, 151.209900], 'location_name': "" })
def post(self, request, *args, **kwargs): self.game = _GameMiddleware(request.POST['game_code']) if not self.game: return handler(request, 404) self.player = GamePlayerMiddleware(request.user.username) if not self.player.is_authorized_to_access_game( request.POST['game_code']): return handler(request, 404) error = "" if len(request.POST['location_code']) == 9: result = self.player.visit_location(request.POST['location_code'], request.POST['game_code']) if not result: error = "Invalid Location Code" else: error = "Invalid Location Code" self.maps = MapsMiddleware() lat_long = [] visited = self.player.locations_visited(request.POST['game_code']) for location in visited: if location[1] != "???": temp = [] latitude, longitude = self.maps.get_coordinate(location[1]) temp.append(float(latitude)) temp.append(float(longitude)) temp.append(location[1]) lat_long.append(temp) return render(request, self.template_name, context={ 'game_details': self.game.get_code_and_name(), 'visited': self.player.locations_visited( request.POST['game_code']), 'lat_long': lat_long, 'error': error })
def _update_title_post_request(self, request, *args, **kwargs): self.maps = MapsMiddleware() self.game_creator = GameCreatorMiddleware(request.user.username) self.game = _GameMiddleware(kwargs['code']) self.game.change_name(request.POST['title']) return render(request, self.template_name, context={ 'locations_code': self.game_creator.get_ordered_locations_of_game( kwargs['code']), 'game_details': self.game_creator.get_code_and_name(kwargs['code']), 'code': kwargs['code'], 'lat_long': self.maps.get_list_of_long_lat(kwargs['code']) })
def post(self, request, game_code, location_code, *args, **kwargs): self.locations = GameCreatorMiddleware(request.user.username) self.game = _GameMiddleware(game_code) self.maps = MapsMiddleware() if not self.locations.is_authorized_to_access_game( request.POST['game_code']): return handler(request, 404) if 'delete_location_code' in request.POST.keys( ) and self.locations.can_change_game(request.POST['game_code']): return self._delete_location( request, game_code, request.POST['delete_location_code'], self.locations.get_location_by_code(location_code)) if 'code' in request.POST.keys(): return self._change_clue(request, request.POST['game_code'], request.POST['code'], *args, **kwargs) return handler(request, 404)
def get(self, request, code, *args, **kwargs): # temp game self.game_creator = GameCreatorMiddleware(request.user.username) self.game_player = GamePlayerMiddleware(request.user.username) if not self.game_creator.is_authorized_to_access_game( code) and not self.game_player.is_authorized_to_access_game( code): return handler(request, 404) self.game = _GameMiddleware(code) return render(request, self.template_name, context={ 'game_details': self.game.get_code_and_name(), 'leaderboards': self.game_creator.get_leaderboard(code) })
def post(self, request, *args, **kwargs): player = GamePlayerMiddleware(request.user.username) form = self.form(request.POST) # Inputting new game code to start playing a game if 'code' in request.POST.keys() and request.POST['code'] != '': game = _GameMiddleware(request.POST['code']) if not game.game: return render(request, self.template_name, context={ 'recent_game_ranks': player.rank_in_most_recent_games(10), 'game_error': "Oops, incorrect code!" }) else: if player.can_join_game(request.POST['code']): player.join_game(request.POST['code']) return HttpResponseRedirect("/game/leaderboard/" + request.POST['code']) else: return render(request, self.template_name, context={ 'recent_game_ranks': player.rank_in_most_recent_games(10), 'game_error': "Oops, incorrect code!" }) # Inputing a game name to start creating a new game if form.is_valid(): game = form.save() game_creator = GameCreator.objects.create(game=game, creator=request.user) return redirect('create_game', game.code) return render(request, self.template_name, {'form': form})
def is_authorized_to_access_game(self, code): game = _GameMiddleware(code) if not game.game: return False return GamePlayer.objects.filter(game=_GameMiddleware(code).game, player=self.user).exists()
def get_status_of_game(self, game_code): game = _GameMiddleware(game_code) return game.get_status()