def __init__(self, request, context, queryset, *args, **kwargs): NewsitemFilter.__init__(self, request, context, queryset, *args, **kwargs) self.location_object = None args = list(args) if 'block' not in kwargs: # We do this first so we consume the right number of args # before getting to block_radius. try: if get_metro()['multiple_cities']: self.city_slug = args.pop(0) else: self.city_slug = '' self.street_slug = args.pop(0) self.block_range = args.pop(0) except IndexError: raise FilterError( "not enough args, need a street and a block range") try: block_radius = args.pop(0) self.block_radius = radius_from_slug(block_radius) except (TypeError, ValueError): raise FilterError('bad radius %r' % block_radius) except IndexError: self.block_radius = context.get('block_radius') if self.block_radius is None: # Redirect to a URL that includes some radius, either # from a cookie, or the default radius. # TODO: Filters are used in various contexts, but the # redirect URL is tailored only for the schema_filter # view. xy_radius, block_radius, cookies_to_set = block_radius_value( request) radius_param = urllib.quote(',' + radius_slug(block_radius)) radius_url = request.get_full_path() + radius_param raise FilterError('missing radius', url=radius_url) if 'block' in kwargs: # needs block_radius to already be there. self._update_block(kwargs['block']) if self.location_object is not None: block = self.location_object else: m = re.search('^%s$' % constants.BLOCK_URL_REGEX, self.block_range) if not m: raise FilterError('Invalid block URL: %r' % self.block_range) url_to_block_args = m.groups() block = url_to_block(self.city_slug, self.street_slug, *url_to_block_args) self._update_block(block) self._got_args = True
def __init__(self, request, context, queryset, *args, **kwargs): NewsitemFilter.__init__(self, request, context, queryset, *args, **kwargs) self.location_object = None args = list(args) if 'block' not in kwargs: # We do this first so we consume the right number of args # before getting to block_radius. try: if get_metro()['multiple_cities']: self.city_slug = args.pop(0) else: self.city_slug = '' self.street_slug = args.pop(0) self.block_range = args.pop(0) except IndexError: raise FilterError("not enough args") try: block_radius = args.pop(0) self.block_radius = radius_from_slug(block_radius) except (TypeError, ValueError): raise FilterError('bad radius %r' % block_radius) except IndexError: self.block_radius = context.get('block_radius') if self.block_radius is None: # Redirect to a URL that includes some radius, either # from a cookie, or the default radius. # TODO: Filters are used in various contexts, but the # redirect URL is tailored only for the schema_filter # view. xy_radius, block_radius, cookies_to_set = block_radius_value(request) radius_url = u'%s,%s/' % (request.path.rstrip('/'), radius_slug(block_radius)) raise FilterError('missing radius', url=radius_url) if 'block' in kwargs: # needs block_radius to already be there. self._update_block(kwargs['block']) m = re.search('^%s$' % constants.BLOCK_URL_REGEX, self.block_range) if not m: raise FilterError('Invalid block URL: %r' % self.block_range) self.url_to_block_args = m.groups() self._got_args = True if self.location_object is not None: block = self.location_object else: block = url_to_block(self.city_slug, self.street_slug, *self.url_to_block_args) self._update_block(block)
def __init__(self, request, context, queryset, *args, **kwargs): NewsitemFilter.__init__(self, request, context, queryset, *args, **kwargs) self.location_object = None args = list(args) if "block" not in kwargs: # We do this first so we consume the right number of args # before getting to block_radius. try: if get_metro()["multiple_cities"]: self.city_slug = args.pop(0) else: self.city_slug = "" self.street_slug = args.pop(0) self.block_range = args.pop(0) except IndexError: raise FilterError("not enough args, need a street and a block range") try: block_radius = args.pop(0) self.block_radius = radius_from_slug(block_radius) except (TypeError, ValueError): raise FilterError("bad radius %r" % block_radius) except IndexError: self.block_radius = context.get("block_radius") if self.block_radius is None: # Redirect to a URL that includes some radius, either # from a cookie, or the default radius. # TODO: Filters are used in various contexts, but the # redirect URL is tailored only for the schema_filter # view. xy_radius, block_radius, cookies_to_set = block_radius_value(request) radius_param = urllib.quote("," + radius_slug(block_radius)) radius_url = request.get_full_path() + radius_param raise FilterError("missing radius", url=radius_url) if "block" in kwargs: # needs block_radius to already be there. self._update_block(kwargs["block"]) if self.location_object is not None: block = self.location_object else: m = re.search("^%s$" % constants.BLOCK_URL_REGEX, self.block_range) if not m: raise FilterError("Invalid block URL: %r" % self.block_range) url_to_block_args = m.groups() block = url_to_block(self.city_slug, self.street_slug, *url_to_block_args) self._update_block(block) self._got_args = True
def get_object(self, request, city_slug, street_slug, from_num, to_num, predir, postdir): self.request = request return url_to_block(city_slug, street_slug, from_num, to_num, predir, postdir)