Ejemplo n.º 1
0
def user_attentions():
    login_user_id = get_login_user_id(request)
    args = request.args
    key = http_util.check_params(args, 'attention_status')
    if key:
        return http_util.return_param_not_found(key)

    user_id = http_util.get_param(args, 'user_id')

    attention_status = http_util.get_param_int(args, 'attention_status')
    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)

    detail_id = None
    if user_id:
        detail_id = user_id
    else:
        detail_id = login_user_id

    if not detail_id:
        return return_no_authorization()

    try:
        res = get_user_attentions(
            user_id=detail_id,
            attention_status=attention_status,
            page=page,
            per_page=per_page,
            login_user_id=login_user_id
        )
        return http_util.return_model(res)
    except BaseException as e:
        app.logger.error(e)
        return http_util.return_internal_server_error()
Ejemplo n.º 2
0
def list():
    '''首页列表'''
    args = request.args
    type = http_util.get_param_int(args, 'type',
                                   BaseConfig.TYPE_HOME_PAGE_LIST)
    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)

    paginate = HomePage.query_home_page_paginate(type=type,
                                                 page=page,
                                                 per_page=per_page)

    details = []
    for item in paginate.items:
        detail = item.to_json()
        res_type = detail['res_type']
        res_id = detail['res_id']
        res_detail = Resource.get_resource_detail(res_id=res_id,
                                                  res_type=res_type)
        detail['res_detail'] = res_detail
        details.append(detail)

    res = http_util.make_page_response(details, paginate.total, page, per_page)

    return return_model(data=res)
Ejemplo n.º 3
0
def timeline():
    login_user_id = get_login_user_id(request)
    args = request.args
    start = http_util.get_param_int(args, 'start', BaseConfig.MAX_START)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)
    user_id = args.get('user_id', None)
    detail_id = None
    if user_id:
        detail_id = user_id
    else:
        detail_id = login_user_id

    if not detail_id:
        return http_util.return_404('not found user')

    res = Action.query_actions(
        user_id=detail_id,
        type=BaseConfig.TYPE_ACTION_UPLOAD,
    )

    items = []
    for item in res:
        res_type = item.res_type
        res_id = item.res_id

        item = Resource.get_resource_detail(
            res_id=res_id,
            res_type=res_type,
            login_user_id=login_user_id
        )
        if item:
            items.append(item)

    return http_util.return_model(items)
Ejemplo n.º 4
0
def list():
    '''文章列表'''

    args = request.args

    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)

    paginate = Video.query_video_paginate(
        user_id="",
        is_del=0,
        page=page,
        per_page=per_page
    )

    videos = []
    for item in paginate.items:
        detail = item.to_json()
        # detail['id'] = "{}".format(detail['id'])
        videos.append(detail)

    res = http_util.make_page_response(videos, paginate.total, page,
                                       per_page)

    return return_model(
        data=res
    )
Ejemplo n.º 5
0
def home_page(type):
    '''
    :param type: 83:首页  87:热门内容
    :return:
    '''
    args = request.args
    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)
    login_user_id = g.user_id
    res = None
    if type == BaseConfig.TYPE_HOME_PAGE:
        # 首页列表
        paginate = Resource.get_home_page_paginate(
            type=BaseConfig.TYPE_HOME_PAGE_LIST,
            page=page,
            per_page=per_page
        )
        res = http_util.make_page_response(paginate.items, paginate.total, page,
                                           per_page)
        # 轮播图
        paginate = Resource.get_home_page_paginate(
            type=BaseConfig.TYPE_HOME_PAGE_CAROUSEL,
            page=page,
            per_page=per_page
        )
        carousels = paginate.items
        res['carousels'] = carousels
        # 静态地址
        res['url'] = ""
        hp_url = HomePage.query_home_page(
            type=BaseConfig.TYPE_HOME_PAGE_URL
        )
        if hp_url:
            res['url'] = hp_url.url
        # 弹窗
        res['show_resource'] = Resource.get_show_resource(login_user_id)
        # 推荐
        paginate = Resource.get_home_page_paginate(
            type=BaseConfig.TYPE_HOME_PAGE_RECOMMEND,
            page=page,
            per_page=per_page
        )
        res['recommends'] = paginate.items

    elif type == BaseConfig.TYPE_HOME_PAGE_HOT:
        res = get_hot_res()
        if page >1:
            res['items'] = []

    return http_util.return_model(
        data=res
    )
Ejemplo n.º 6
0
def comments():
    '''评论列表'''
    args = request.args
    key = check_params(args, 'res_id')
    if key:
        return return_not_found(key)

    start = http_util.get_param_int(args, 'start', BaseConfig.MAX_START)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_NO_PAGINATE_PER_PAGE)

    res = get_comments(res_id=args['res_id'], start=start, per_page=per_page)

    return http_util.return_model(res)
Ejemplo n.º 7
0
def resource_delete():
    """资源详情"""
    args = request.json
    key = http_util.check_params(args, 'res_id', 'res_type')
    if key:
        return http_util.return_param_not_found(key)

    login_user_id = http_util.get_login_user_id(request)

    if not login_user_id:
        return http_util.return_no_authorization()

    res_id = http_util.get_param(args, 'res_id')
    res_type = http_util.get_param_int(args, 'res_type')

    try:
        is_del = Resource.delete_resource(res_id, res_type)

        if not is_del:
            return http_util.return_internal_server_error("删除失败")

        # 记录用户行为
        Action.create_action(
            user_id=login_user_id,
            type=BaseConfig.TYPE_ACTION_DELETE,
            res_id=res_id,
            res_type=res_type
        )

        return http_util.return_model()
    except BaseException as e:
        app.logger.error(e)
        return http_util.return_internal_server_error()
Ejemplo n.º 8
0
def get_article_list_json():
    '''获取文章内容'''
    args = request.args
    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)

    paginate = Article.query_article_paginate(page=page, per_page=per_page)
    details = []
    for item in paginate.items:
        detail = item.to_json()
        del detail['content']
        details.append(detail)

    res = http_util.make_page_response(details, paginate.total, page, per_page)

    return return_model(data=res)
Ejemplo n.º 9
0
def resource_list():
    '''首页列表'''
    args = request.args
    res_type = http_util.get_param_int(args, 'res_type', 7)

    res = Resource.get_resource_list(res_type)

    return return_model(data=res)
Ejemplo n.º 10
0
def push_list():
    args = request.args
    page = http_util.get_param_int(args, "page", BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, "per_page",
                                       BaseConfig.DEFAULT_PER_PAGE)

    print(page, per_page)

    paginate = Push.query_paginate(page, per_page)

    details = []
    for item in paginate.items:
        detail = item.to_json()
        details.append(detail)

    res = http_util.make_page_response(details, paginate.total, page, per_page)

    return http_util.return_model(data=res)
Ejemplo n.º 11
0
def near():
    '''附近坐标'''
    login_user_id = http_util.get_login_user_id(request)
    if not login_user_id:
        return http_util.return_no_authorization()
    args = request.args
    page_size = http_util.get_param_int(args, 'per_page', 50)
    key = http_util.check_params(args, 'radius', 'lat', 'lng')
    if key:
        return http_util.return_param_not_found(key)

    lat = http_util.get_param(args, 'lat')
    lng = http_util.get_param(args, 'lng')
    radius = http_util.get_param_int(args, 'radius', 1000)
    items, total = search_near(
        geo_id=env_config.GEOTABLE_ID,
        lat=lat,
        lng=lng,
        radius=radius,
        page_size=50
    )

    users = []
    for item in items:
        user_id = item['user_id']
        location = item['location']
        lat = location[1]
        lng = location[0]
        user = get_user_detail(id=user_id)

        if not user:
            continue
        user['ext']['lat'] = lat
        user['ext']['lng'] = lng
        if login_user_id != user_id:
            users.append(user)

    res = http_util.make_page_response(users, total, 1, page_size)

    return http_util.return_model(
        data=res
    )
Ejemplo n.º 12
0
def list():
    '''文章列表'''

    args = request.args

    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)

    paginate = SensitiveWord.query_paginate(page=page, per_page=per_page)

    items = []
    for item in paginate.items:
        detail = item.to_json()
        # detail['id'] = "{}".format(detail['id'])
        items.append(detail)

    res = http_util.make_page_response(items, paginate.total, page, per_page)

    return return_model(data=res)
Ejemplo n.º 13
0
def sync_index():
    '''刷新索引'''
    args = request.args

    type = http_util.get_param_int(args, 'type', -1)

    if type == -1:
        sync_index_all()
    else:
        sync_index_by_type(type)
    return return_model()
Ejemplo n.º 14
0
def list():
    '''文章列表'''

    args = request.args
    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)

    paginate = Audio.query_audio_paginate(page=page,
                                          per_page=per_page,
                                          is_del=0)

    videos = []
    for item in paginate.items:
        detail = item.to_json()
        videos.append(detail)

    res = http_util.make_page_response(videos, paginate.total, page, per_page)

    return return_model(data=res)
Ejemplo n.º 15
0
def list():
    '''首页列表'''
    args = request.args
    type = http_util.get_param_int(args, 'type',
                                   BaseConfig.TYPE_HOME_PAGE_LIST)
    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)

    paginate = User.query_paginate(page=page,
                                   status=BaseConfig.TYPE_USER_NORMAL,
                                   per_page=per_page)

    details = []
    for item in paginate.items:
        detail = item.to_json()
        details.append(detail)

    res = http_util.make_page_response(details, paginate.total, page, per_page)

    return return_model(data=res)
Ejemplo n.º 16
0
def search():
    '''搜索'''
    args = request.args
    user_id = g.user_id
    q = args.get('q')
    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)
    q = 'name:{}'.format(q)

    doc_type = "{},{},{},{},{}".format(BaseConfig.ES_TYPE_USER,
                                       BaseConfig.ES_TYPE_ARTICLE,
                                       BaseConfig.ES_TYPE_COLLECTION,
                                       BaseConfig.ES_TYPE_VIDEO,
                                       BaseConfig.ES_TYPE_AUDIO)

    res, total = es.search(index=BaseConfig.ES_INDEX,
                           doc_type=doc_type,
                           q=q,
                           sort='{}:desc'.format(BaseConfig.ES_PARAMS_WEIGHT),
                           _source_include=[
                               'res_id', 'res_type', 'name', 'portrait',
                               'poster', 'posters', 'age'
                           ])

    for item in res:
        res_type = item['res_type']
        res_id = item['res_id']
        if res_type == BaseConfig.TYPE_USER:
            item['attention_status'] = get_user_attention_status(
                user_id, res_id)

    res = http_util.make_page_response(res, total, page, per_page)

    if not res['items']:
        res['recommends'] = Resource.get_hot_items()

    return http_util.return_model(res)
Ejemplo n.º 17
0
def search_key():
    '''搜索'''
    args = request.args
    q = args.get('q')
    page = http_util.get_param_int(args, 'page', BaseConfig.DEFAULT_PAGE)
    per_page = http_util.get_param_int(args, 'per_page',
                                       BaseConfig.DEFAULT_PER_PAGE)
    q = 'name:{}'.format(q)

    doc_type = "{},{},{},{},{}".format(BaseConfig.ES_TYPE_USER,
                                       BaseConfig.ES_TYPE_ARTICLE,
                                       BaseConfig.ES_TYPE_COLLECTION,
                                       BaseConfig.ES_TYPE_VIDEO,
                                       BaseConfig.ES_TYPE_AUDIO)

    res, total = es.search(index=BaseConfig.ES_INDEX,
                           doc_type=doc_type,
                           q=q,
                           sort='{}:desc'.format(BaseConfig.ES_PARAMS_WEIGHT),
                           _source_include=['name'])

    res = http_util.make_page_response(res, total, page, per_page)

    return http_util.return_model(res)
Ejemplo n.º 18
0
def resource_delete_json():
    '''首页列表'''
    args = request.form

    res_id = http_util.get_param(args, 'res_id', None)
    res_type = http_util.get_param_int(args, 'res_type', 0)

    if not res_id or not res_type:
        return http_util.return_forbidden('res_id or res_type is error')

    check_use = Resource.check_resource_use_status(res_id, res_type)
    if check_use:
        return http_util.return_forbidden("{},不能删除".format(check_use))

    res = Resource.delete_resource(res_id, res_type)

    if res:
        return return_model()
    else:
        return http_util.return_internal_server_error()
Ejemplo n.º 19
0
def resource_detail():
    """资源详情"""
    args = request.args
    key = http_util.check_params(args, 'res_id', 'res_type')
    if key:
        return http_util.return_param_not_found(key)

    login_user_id = http_util.get_login_user_id(request)

    res_id = http_util.get_param(args, 'res_id')
    res_type = http_util.get_param_int(args, 'res_type')

    try:
        detail = Resource.get_resource_detail(
            res_id=res_id,
            res_type=res_type,
            source_include=['comments', 'related_items', 'view_count',
                            'like_count', 'items',
                            'comment_count'],
            login_user_id=login_user_id
        )

        if not detail:
            return http_util.return_404('res_id not found')

        # 记录用户行为
        Action.create_action(
            user_id=login_user_id,
            type=BaseConfig.TYPE_ACTION_VIEW,
            res_id=res_id,
            res_type=res_type
        )

        return http_util.return_model(
            data=detail
        )
    except BaseException as e:
        app.logger.error(e)
        return http_util.return_internal_server_error()