コード例 #1
0
def api_user_topics(userid):
  """
  Display a single user's topics. Requires authentication. Request params: query, tag, limit, start
  """
  try:
    userObj = User(g.db, userid)
  except InvalidUserError:
    return not_found()
  try:
    topicList = TopicList(g.db).user(userObj)
    query = request.args['query'] if 'query' in request.args else None
    if 'tag' in request.args:
      tagNames = request.args.getlist('tag')
      for name in tagNames:
        if name.startswith("-"):
          topicList.excludeTag(Tag(g.db, name[1:]))
        else:
          topicList.includeTag(Tag(g.db, name))
    if 'limit' in request.args:
      requestedLimit = int(request.args['limit'])
      topicList.limit(1000 if requestedLimit > 1000 or requestedLimit < 1 else requestedLimit)
    if 'start' in request.args:
      requestedStart = int(request.args['start'])
      topicList.start(0 if requestedStart < 0 else requestedStart)
    searchTopics = [post.dict() for post in topicList.search(query=query, includes=['user', 'tags'])]
  except InvalidTagError:
    return not_found()
  return jsonify_list(searchTopics, 'topics')
コード例 #2
0
def api_topics():
  """
  Topic listing. Request params: query, tag, start, limit
  """
  try:
    topicList = TopicList(g.db)
    query = request.args['query'] if 'query' in request.args else None
    if 'tag' in request.args:
      tagNames = request.args.getlist('tag')
      for name in tagNames:
        if name.startswith("-"):
          topicList.excludeTag(Tag(g.db, name[1:]))
        else:
          topicList.includeTag(Tag(g.db, name))
    if 'start' in request.args:
      requestedStart = int(request.args['start'])
      topicList.start(0 if requestedStart < 0 else requestedStart)
    if 'limit' in request.args:
      topicLimit = 1000 if int(request.args['limit']) > 1000 or int(request.args['limit']) < 1 else int(request.args['limit'])
      topicList.limit(topicLimit)
    searchTopics = [topic.dict() for topic in topicList.search(query=query, includes=['user', 'tags'])]
    return jsonify_list(searchTopics, 'topics')
  except InvalidTagError:
    return not_found()
コード例 #3
0
def api_user_topics(userid):
    """
  Display a single user's topics. Requires authentication. Request params: query, tag, limit, start
  """
    try:
        userObj = User(g.db, userid)
    except InvalidUserError:
        return not_found()
    try:
        topicList = TopicList(g.db).user(userObj)
        query = request.args['query'] if 'query' in request.args else None
        if 'tag' in request.args:
            tagNames = request.args.getlist('tag')
            for name in tagNames:
                if name.startswith("-"):
                    topicList.excludeTag(Tag(g.db, name[1:]))
                else:
                    topicList.includeTag(Tag(g.db, name))
        if 'limit' in request.args:
            requestedLimit = int(request.args['limit'])
            topicList.limit(1000 if requestedLimit > 1000 or requestedLimit < 1
                            else requestedLimit)
        if 'start' in request.args:
            requestedStart = int(request.args['start'])
            topicList.start(0 if requestedStart < 0 else requestedStart)
        searchTopics = [
            post.dict() for post in topicList.search(query=query,
                                                     includes=['user', 'tags'])
        ]
    except InvalidTagError:
        return not_found()
    return jsonify_list(searchTopics, 'topics')
コード例 #4
0
def api_topics():
    """
  Topic listing. Request params: query, tag, start, limit
  """
    try:
        topicList = TopicList(g.db)
        query = request.args['query'] if 'query' in request.args else None
        if 'tag' in request.args:
            tagNames = request.args.getlist('tag')
            for name in tagNames:
                if name.startswith("-"):
                    topicList.excludeTag(Tag(g.db, name[1:]))
                else:
                    topicList.includeTag(Tag(g.db, name))
        if 'start' in request.args:
            requestedStart = int(request.args['start'])
            topicList.start(0 if requestedStart < 0 else requestedStart)
        if 'limit' in request.args:
            topicLimit = 1000 if int(request.args['limit']) > 1000 or int(
                request.args['limit']) < 1 else int(request.args['limit'])
            topicList.limit(topicLimit)
        searchTopics = [
            topic.dict()
            for topic in topicList.search(query=query,
                                          includes=['user', 'tags'])
        ]
        return jsonify_list(searchTopics, 'topics')
    except InvalidTagError:
        return not_found()