def setLocation(request, user_id, player_id, player): try: address = request.POST['address'] city = request.POST['city'] state = request.POST['state'] zipcode = request.POST['zipcode'] lat, lon = geocodeLocation(address, city, state, zipcode) playerLocation, created = PlayerLocation.objects.get_or_create( player=player, defaults={ 'address': address, 'city': city, 'state': State.objects.get(name=state), 'zipcode': zipcode, 'point': Point(lon, lat) }) if not created: playerLocation.address = address playerLocation.city = city playerLocation.state = State.objects.get(name=state) playerLocation.zipcode = zipcode playerLocation.latitude = lat playerLocation.longitude = lon playerLocation.save() return HttpResponse() except LocationNotFoundError: return HttpResponseBadRequest('Bad location')
def setLocation(request, player, json_params): postal_code = json_params['postal_code'] country = json_params['country'] address = json_params.get('address', "") locality = json_params.get('locality',"") region = json_params.get('region', "") try: lat, lon = geocodeLocation(postal_code, country, address, locality, region) except LocationNotFoundError as e: return HttpResponseBadRequest('Location not found') playerLocation, created = PlayerLocation.objects.get_or_create(player=player, defaults={ 'point' : Point(lon, lat), 'address' : address, 'locality' : locality, 'region' : region, 'country' : country, 'postal_code' : postal_code } ) if not created: playerLocation.point = Point(lon, lat) playerLocation.address = address playerLocation.locality = locality playerLocation.region = region playerLocation.country = country playerLocation.postal_code = postal_code playerLocation.save() return HttpResponse()
def setPlayerLocation(location, player): address = location.get('address', "") locality = location.get('locality', "") region = location.get('region', "") postal_code = location['postal_code'] country = location['country'] lat, lon = geocodeLocation(postal_code, country, address, locality, region) playerLocation, created = PlayerLocation.objects.get_or_create( player=player, defaults={ 'point' : Point(lon, lat), 'address' : address, 'locality' : locality, 'region' : region, 'postal_code' : postal_code, 'country' : country } ) if not created: playerLocation.point = Point(lon, lat) playerLocation.address = address playerLocation.locality = locality playerLocation.region = region playerLocation.postal_code = postal_code playerLocation.country = country playerLocation.save()
def setPlayerLocation(location, player): address = location.get("address", None) locality = location.get("locality", None) region = location.get("region", None) postal_code = location["postal_code"] country = location["country"] lat, lon = geocodeLocation(postal_code, country, address, locality, region) playerLocation, created = PlayerLocation.objects.get_or_create( player=player, defaults={ "point": Point(lon, lat), "address": address, "locality": locality, "region": region, "postal_code": postal_code, "country": country, }, ) if not created: playerLocation.point = Point(lon, lat) playerLocation.address = address playerLocation.locality = locality playerLocation.region = region playerLocation.postal_code = postal_code playerLocation.country = country playerLocation.save()
def setPlayerLocation(location, player): address = location.get('address', None) locality = location.get('locality', None) region = location.get('region', None) postal_code = location['postal_code'] country = location['country'] lat, lon = geocodeLocation(postal_code, country, address, locality, region) playerLocation, created = PlayerLocation.objects.get_or_create( player=player, defaults={ 'point': Point(lon, lat), 'address': address, 'locality': locality, 'region': region, 'postal_code': postal_code, 'country': country }) if not created: playerLocation.point = Point(lon, lat) playerLocation.address = address playerLocation.locality = locality playerLocation.region = region playerLocation.postal_code = postal_code playerLocation.country = country playerLocation.save()
def setLocation(request, user_id, player_id, player): try: address = request.POST['address'] city = request.POST['city'] state = request.POST['state'] zipcode = request.POST['zipcode'] lat, lon = geocodeLocation(address, city, state, zipcode) playerLocation, created = PlayerLocation.objects.get_or_create( player=player, defaults={ 'address' : address, 'city' : city, 'state' : State.objects.get(name=state), 'zipcode' : zipcode, 'point' : Point(lon, lat) } ) if not created: playerLocation.address = address playerLocation.city = city playerLocation.state = State.objects.get(name=state) playerLocation.zipcode = zipcode playerLocation.latitude = lat playerLocation.longitude = lon playerLocation.save() return HttpResponse() except LocationNotFoundError: return HttpResponseBadRequest('Bad location')
def doLocationSet(address, city, state, zipcode, player): lat, lon = geocodeLocation(address, city, state, zipcode) PlayerLocation(player=player, address=address, city=city, state=State.objects.get(name__iexact=state), zipcode=zipcode, point=Point(lon, lat)).save()
def doLocationSet(address, city, state, zipcode, player): lat, lon = geocodeLocation(address, city, state, zipcode) PlayerLocation( player=player, address=address, city=city, state=State.objects.get(name__iexact=state), zipcode=zipcode, point=Point(lon, lat) ).save()
def setLocation(request, user_id, player_id, player): try: address = request.POST['address'] city = request.POST['city'] state = request.POST['state'] zipcode = request.POST['zipcode'] lat, lon = geocodeLocation(zipcode, "United States", address, city, state) playerLocation, created = PlayerLocation.objects.get_or_create( player=player, defaults={ 'point' : Point(lon, lat) } ) if not created: playerLocation.point = Point(lon, lat) playerLocation.save() return HttpResponse() except LocationNotFoundError: return HttpResponseBadRequest('Bad location')
def doLocationSet(address, city, state, zipcode, player): lat, lon = geocodeLocation(zipcode, "United State", address, city, state) PlayerLocation( player=player, point=Point(lon, lat) ).save()
def createPlayer(request, json_params): user = request.udjuser newPlayerName = json_params['name'] #Determine which sorting algorithm to use if 'sorting_algorithm_id' in json_params: try: sortingAlgo = SortingAlgorithm.objects.get(pk=json_params['sorting_algorithm_id']) except ObjectDoesNotExist: return HttpResponseMissingResource('sorting-algorithm') else: try: sortingAlgo = SortingAlgorithm.objects.get(function_name=DEFAULT_SORTING_ALGO) except ObjectDoesNotExist: raise ImproperlyConfigured('Default sorting algorithm is not in database') #If locaiton provided, attempted to geocode it. if 'location' in json_params: location = json_params['location'] if isValidLocation(location): try: address = location.get('address', "") locality = location.get('locality', "") region = location.get('region', "") postal_code = location['postal_code'] country = location['country'] lat, lon = geocodeLocation(postal_code, country, address, locality, region) except LocationNotFoundError as e: return HttpResponseBadRequest('Location not found. Geocoder error: ' + str(e)) else: return HttpResponseBadRequest('Bad location') #Create and save new player try: newPlayer = Player(owning_user=user, name=newPlayerName, sorting_algo=sortingAlgo) newPlayer.save() except IntegrityError: return HttpResponse('A player with that name already exists', status=409) #If password provided, create and save password if 'password' in json_params: newPlayer.setPassword(json_params['password']) #Set location if provided if 'location' in json_params: playerLocation = PlayerLocation(player=newPlayer, point=Point(lon, lat), address=address, locality=locality, region=region, postal_code=postal_code, country=country) playerLocation.save() #Create Owner Permissions Group owner_group = PlayerPermissionGroup(player=newPlayer, name="owner") owner_group.save() owner_group.add_member(user) #Add owner_group to select permissiosn set_default_player_permissions(newPlayer, owner_group) return HttpJSONResponse(json.dumps(newPlayer, cls=UDJEncoder), status=201)