def _query_async(self):
     district_key = self._query_args[0]
     district = yield District.get_by_id_async(district_key)
     raise ndb.Return(district)
    def validate_request(cls, handler):
        kwargs = handler.request.route_kwargs
        error_dict = {'Errors': []}
        valid = True
        team_future = None
        event_future = None
        match_future = None
        district_future = None
        # Check key formats
        if 'team_key' in kwargs:
            team_key = kwargs['team_key']
            results = cls.team_id_validator(team_key)
            if results:
                error_dict['Errors'].append(results)
                valid = False
            else:
                team_future = Team.get_by_id_async(team_key)
        if 'event_key' in kwargs:
            event_key = kwargs['event_key']
            results = cls.event_id_validator(event_key)
            if results:
                error_dict['Errors'].append(results)
                valid = False
            else:
                event_future = Event.get_by_id_async(event_key)
        if 'match_key' in kwargs:
            match_key = kwargs['match_key']
            results = cls.match_id_validator(match_key)
            if results:
                error_dict['Errors'].append(results)
                valid = False
            else:
                match_future = Match.get_by_id_async(match_key)
        if 'district_key' in kwargs:
            district_key = kwargs['district_key']
            results = cls.district_id_validator(district_key)
            if results:
                error_dict['Errors'].append(results)
                valid = False
            else:
                district_future = District.get_by_id_async(district_key)
        if 'year' in kwargs:
            year = int(kwargs['year'])
            if year > tba_config.MAX_YEAR or year < 1992:
                error_dict['Errors'].append({
                    'year':
                    'Invalid year: {}. Must be between 1992 and {} inclusive.'.
                    format(year, tba_config.MAX_YEAR)
                })
                valid = False

        # Check if keys exist
        if team_future and team_future.get_result() is None:
            error_dict['Errors'].append(
                {'team_id': 'team id {} does not exist'.format(team_key)})
            valid = False
        if event_future and event_future.get_result() is None:
            error_dict['Errors'].append(
                {'event_id': 'event id {} does not exist'.format(event_key)})
            valid = False
        if match_future and match_future.get_result() is None:
            error_dict['Errors'].append(
                {'match_id': 'match id {} does not exist'.format(match_key)})
            valid = False
        if district_future and district_future.get_result() is None:
            error_dict['Errors'].append({
                'district_id':
                'district id {} does not exist'.format(district_key)
            })
            valid = False

        if not valid:
            return error_dict
    def validate_request(cls, handler):
        kwargs = handler.request.route_kwargs
        error_dict = {'Errors': []}
        valid = True
        team_future = None
        event_future = None
        match_future = None
        district_future = None
        # Check key formats
        if 'team_key' in kwargs:
            team_key = kwargs['team_key']
            results = cls.team_id_validator(team_key)
            if results:
                error_dict['Errors'].append(results)
                valid = False
            else:
                team_future = Team.get_by_id_async(team_key)
        if 'event_key' in kwargs:
            event_key = kwargs['event_key']
            results = cls.event_id_validator(event_key)
            if results:
                error_dict['Errors'].append(results)
                valid = False
            else:
                event_future = Event.get_by_id_async(event_key)
        if 'match_key' in kwargs:
            match_key = kwargs['match_key']
            results = cls.match_id_validator(match_key)
            if results:
                error_dict['Errors'].append(results)
                valid = False
            else:
                match_future = Match.get_by_id_async(match_key)
        if 'district_key' in kwargs:
            district_key = kwargs['district_key']
            results = cls.district_id_validator(district_key)
            if results:
                error_dict['Errors'].append(results)
                valid = False
            else:
                district_future = District.get_by_id_async(district_key)
        if 'year' in kwargs:
            year = int(kwargs['year'])
            if year > tba_config.MAX_YEAR or year < 1992:
                error_dict['Errors'].append({'year': 'Invalid year: {}. Must be between 1992 and {} inclusive.'.format(year, tba_config.MAX_YEAR)})
                valid = False

        # Check if keys exist
        if team_future and team_future.get_result() is None:
            error_dict['Errors'].append({'team_id': 'team id {} does not exist'.format(team_key)})
            valid = False
        if event_future and event_future.get_result() is None:
            error_dict['Errors'].append({'event_id': 'event id {} does not exist'.format(event_key)})
            valid = False
        if match_future and match_future.get_result() is None:
            error_dict['Errors'].append({'match_id': 'match id {} does not exist'.format(match_key)})
            valid = False
        if district_future and district_future.get_result() is None:
            error_dict['Errors'].append({'district_id': 'district id {} does not exist'.format(district_key)})
            valid = False

        if not valid:
            return error_dict