def update_player(request, *args, **kwargs): uid = request.GET.get('id', None) loc_string = request.GET.get('loc_string') color = request.GET.get('color', None) death = True if request.GET.get('death', 'false') == 'true' else False if uid is None: raise InvalidParameterError('GET param `id` is required') if loc_string is None: raise InvalidParameterError('GET param `loc_string` is required') if color is None: raise InvalidParameterError('GET param `color` is required') try: player = Player.objects.get(id=uid) except Player.DoesNotExist: raise InvalidParameterError('`id` did not find a player') lat, lng, heading = parse_loc_string(loc_string) logging.info('String: {0}'.format(loc_string)) logging.info('Results: {0}, {1}, {2}'.format(lat, lng, heading)) player.color = color if death: player.death() player.add_move(lat, lng, heading) player.save() return player.get_bound_data()
def add_or_login_player(request, *args, **kwargs): name = request.GET.get('name', None) lat, lng, heading = parse_loc_string(name) if lat is not None or lng is not None or heading is not None: raise InvalidParameterError('Name should not evaluate as a location.') player, created = Player.objects.get_or_create(character_name=name) player.login_session(request) return player.get_bound_data()
def verify_place_request(request, update=False): """Verify place object from request.""" lat = request.GET.get('lat', None) lng = request.GET.get('lng', None) loc_string = request.GET.get('loc_string', None) name = request.GET.get('name', None) icon_string = request.GET.get('maki_icon', 'embassasy') color = request.GET.get('color', None) category = request.GET.get('category', 0) if loc_string is not None: lat, lng, heading = parse_loc_string(loc_string) if lat is None or lng is None or heading is None: raise InvalidParameterError('`loc_string` parse failed') else: if lat is None: raise InvalidParameterError('GET `lat` required') if lng is None: raise InvalidParameterError('GET `lng` required') if name is None: raise InvalidParameterError('GET `name` required') if icon_string is None: raise InvalidParameterError('GET `icon_string` required') if color is None: raise InvalidParameterError('GET `color` required') ctx = { 'lat': lat, 'lng': lng, 'name': name, 'icon_string': icon_string, 'color': color, 'category': category } if update: uid = request.GET.get('id', 0) if uid is None: raise InvalidParameterError('GET `id` required') ctx['id'] = uid return ctx