Beispiel #1
0
 def export_categ(self, aw):
     expInt = CategoryEventFetcher(aw, self)
     id_list = set(self._idList)
     if self._wantFavorites and aw.getUser():
         id_list.update(str(c.id) for c in aw.getUser().user.favorite_categories)
     legacy_id_map = {m.legacy_category_id: m.category_id
                      for m in LegacyCategoryMapping.find(LegacyCategoryMapping.legacy_category_id.in_(id_list))}
     id_list = {str(legacy_id_map.get(id_, id_)) for id_ in id_list}
     return expInt.category(id_list, self._format)
Beispiel #2
0
 def export_categ(self, user):
     expInt = CategoryEventFetcher(user, self)
     id_list = set(self._idList)
     if self._wantFavorites and user:
         id_list.update(str(c.id) for c in user.favorite_categories)
     legacy_id_map = {m.legacy_category_id: m.category_id
                      for m in LegacyCategoryMapping.find(LegacyCategoryMapping.legacy_category_id.in_(id_list))}
     id_list = {str(legacy_id_map.get(id_, id_)) for id_ in id_list}
     return expInt.category(id_list, self._format)
Beispiel #3
0
 def export_categ(self, aw):
     expInt = CategoryEventFetcher(aw, self)
     id_list = set(self._idList)
     if self._wantFavorites and aw.getUser():
         id_list.update(c.getId() for c in aw.getUser().user.favorite_categories)
     legacy_id_map = {m.legacy_category_id: m.category_id
                      for m in LegacyCategoryMapping.find(LegacyCategoryMapping.legacy_category_id.in_(id_list))}
     id_list = {str(legacy_id_map.get(id_, id_)) for id_ in id_list}
     return expInt.category(id_list)
Beispiel #4
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('Legacy category {} does not exist'.format(legacy_category_id))
    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)
Beispiel #5
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('Legacy category {} does not exist'.format(legacy_category_id))
    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)