Example #1
0
    def _redirect_legacy_id():
        if not request.view_args:
            return

        categ_id = request.view_args.get('categId')
        if categ_id is None or not is_legacy_id(categ_id):
            return
        if request.method != 'GET':
            raise BadRequest('Unexpected non-GET request with legacy category ID')

        mapping = LegacyCategoryMapping.find_first(legacy_category_id=categ_id)
        if mapping is None:
            raise NotFound('Legacy category {} does not exist'.format(categ_id))

        request.view_args['categId'] = unicode(mapping.category_id)
        return redirect(url_for(request.endpoint, **dict(request.args.to_dict(), **request.view_args)), 301)
Example #2
0
def compat_category(legacy_category_id, path=None):
    if not re.match(r'^\d+l\d+$', legacy_category_id):
        abort(404)
    mapping = LegacyCategoryMapping.find_first(
        legacy_category_id=legacy_category_id)
    if mapping is None:
        raise NotFound(f'Legacy category {legacy_category_id} does not exist')
    view_args = request.view_args.copy()
    view_args['legacy_category_id'] = mapping.category_id
    # To create the same URL with the proper ID we take advantage of the
    # fact that the legacy endpoint works perfectly fine with proper IDs
    # too (you can pass an int for a string argument), but due to the
    # weight of the `int` converter used for new endpoints, the URL will
    # then be handled by the proper endpoint instead of this one.
    return redirect(
        url_for(request.endpoint, **dict(request.args.to_dict(), **view_args)),
        301)
Example #3
0
    def _redirect_legacy_id():
        if not request.view_args:
            return

        categ_id = request.view_args.get('categId')
        if categ_id is None or not is_legacy_id(categ_id):
            return
        if request.method != 'GET':
            raise BadRequest(
                'Unexpected non-GET request with legacy category ID')

        mapping = LegacyCategoryMapping.find_first(legacy_category_id=categ_id)
        if mapping is None:
            raise NotFound(
                'Legacy category {} does not exist'.format(categ_id))

        request.view_args['categId'] = unicode(mapping.category_id)
        return redirect(
            url_for(request.endpoint,
                    **dict(request.args.to_dict(), **request.view_args)), 301)