Ejemplo n.º 1
0
def get_all_series_category():
    result = {'response': 'ok', 'meta': '', 'data_list': []}
    search = request.args.get('search')
    limit = request.args.get('limit', 10)
    page = request.args.get('page', 1)
    with get_session() as db_session:
        query = db_session.query(ImageSeriesCategory).order_by(
            -ImageSeriesCategory.modified_date)

        if search:
            query = query.filter(
                ImageSeriesCategory.name.like('%%%s%%' % search))

        paginator = SQLAlchemyPaginator(query, limit)
        page = paginator.get_validate_page(page)

        _data_list = list()

        for series_category in paginator.page(page):
            series_category_dict = series_category.to_dict()
            _data_list.append(series_category_dict)

        result['data_list'] = _data_list
        result.update({
            'meta': {
                'cur_page': page,
                'all_page': paginator.max_page,
                'count': paginator.count
            }
        })
    return jsonify(result)
Ejemplo n.º 2
0
def get_article_list():
    result = {
        'response': 'ok',
        'meta': {},
        'article_list': []
    }
    try:
        page = request.args.get('page', 1)
        limit = 10
        with get_session() as db_session:
            query = db_session.query(Article)
            paginator = SQLAlchemyPaginator(query, limit)
            page = paginator.get_validate_page(page)
            for article in paginator.page(page):
                article_dict = article.to_dict()
                result['article_list'].append(article_dict)
            result.update({
                'meta': {
                    'cur_page': page,
                    'all_page': paginator.max_page,
                    'count': paginator.count
                }
            })
            return jsonify(result)
    except Exception as e:
        print traceback.format_exc(e)
Ejemplo n.º 3
0
def get_all_article():
    result = {'response': 'ok', 'meta': '', 'data_list': []}
    search = request.args.get('search')
    limit = request.args.get('limit', 10)
    page = request.args.get('page', 1)
    with get_session() as db_session:
        query = db_session.query(Article).filter(
            Article.status == Article.STATUS_PUBLISH).order_by(
                -Article.modified_date)

        if search:
            query = query.filter(Article.name.like('%%%s%%' % search))

        paginator = SQLAlchemyPaginator(query, limit)
        page = paginator.get_validate_page(page)

        _data_list = list()

        for article in paginator.page(page):
            article_dict = article.to_dict()
            _data_list.append(article_dict)

        result['data_list'] = _data_list
        result.update({
            'meta': {
                'cur_page': page,
                'all_page': paginator.max_page,
                'count': paginator.count
            }
        })
    return jsonify(result)
Ejemplo n.º 4
0
def user_series_collect():
    result = {'response': 'ok', 'info': '', 'image_series_list': []}
    page = request.args.get('page', 1)
    try:
        with get_session() as db_session:
            limit = 20
            query = db_session.query(ImageSeries).join(
                CustomerCollect,
                ImageSeries.id == CustomerCollect.collect_id).filter(
                    CustomerCollect.customer_id == current_user.id,
                    CustomerCollect.type == CustomerCollect.TYPE_SERIES)
            paginator = SQLAlchemyPaginator(query, limit)
            page = paginator.get_validate_page(page)
            for image_series in paginator.page(page):
                image_series_dict = image_series.to_dict()
                result['image_series_list'].append(image_series_dict)
            result.update({
                'meta': {
                    'cur_page': page,
                    'all_page': paginator.max_page,
                    'count': paginator.count
                }
            })
            return jsonify(result)
    except Exception as e:
        print e
Ejemplo n.º 5
0
def image_list():
    result = {
        'response': 'ok',
        'image_list': [],
        'meta': {}
    }
    limit = 40
    page = request.args.get('page', 1)
    start_date = request.args.get('startDate', None)
    end_date = request.args.get('endDate', None)
    try:
        with get_session() as db_session:
            query = db_session.query(Img)

            if start_date and end_date:
                _start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d')
                _end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d')
                query = query.filter(
                    Img.created_date >= _start_date,
                    Img.created_date <= _end_date
                )

            query = query.order_by(-Img.created_date)

            paginator = SQLAlchemyPaginator(query, limit)
            page = paginator.get_validate_page(page)

            _img_list = list()
            for img in paginator.page(page):
                img_dict = img.to_dict()
                img_series_obj = db_session.query(ImageSeriesRel).filter(
                    ImageSeriesRel.image_id == img.id
                ).all()
                img_series_name = [image_series.image_series_name for image_series in img_series_obj]
                img_dict['image_series'] = img_series_name if img_series_name else [u'无']
                image_tag_obj = db_session.query(ImageTagsRel).filter(
                    ImageTagsRel.image_id == img.id
                ).all()
                img_tag_name = [image_tag.tag_name for image_tag in image_tag_obj]
                img_dict['image_tag'] = img_tag_name if img_tag_name else [u'无']
                _img_list.append(img_dict)

            result.update({
                'image_list': _img_list
            })

            result.update({
                'meta': {
                    'cur_page': page,
                    'all_page': paginator.max_page,
                    'count': paginator.count
                }
            })

            return jsonify(result)
    except Exception as e:
        print e
        abort(400)
Ejemplo n.º 6
0
def tag_image_list():
    result = {
        'response': 'ok',
        'image_list': [],
        'meta': {}
    }
    limit = 40
    page = request.args.get('page', 1)
    tag_id = request.args.get('tag_id')
    try:
        with get_session() as db_session:
            query = db_session.query(Img).join(
                ImageTagsRel, Img.id == ImageTagsRel.image_id
            ).filter(
                ImageTagsRel.tag_id == tag_id
            )

            tag = db_session.query(ImageTags).get(tag_id)
            if tag:
                paginator = SQLAlchemyPaginator(query, limit)
                page = paginator.get_validate_page(page)

                _img_list = list()
                for img in paginator.page(page):
                    img_dict = img.to_dict()
                    img_series_obj = db_session.query(ImageSeriesRel).filter(
                        ImageSeriesRel.image_id == img.id
                    ).all()
                    img_series_name = [image_series.image_series_name for image_series in img_series_obj]
                    img_dict['image_series'] = img_series_name if img_series_name else [u'无']
                    img_dict['image_tag'] = [tag.name]
                    _img_list.append(img_dict)

                result.update({
                    'image_list': _img_list
                })

                result.update({
                    'meta': {
                        'cur_page': page,
                        'all_page': paginator.max_page,
                        'count': paginator.count
                    }
                })
            else:
                result['response'] = 'fail'
                result['info'] = u'当前标签不存在'

            return jsonify(result)
    except Exception as e:
        print e.message
        abort(400)
Ejemplo n.º 7
0
def get_image_list_page():
    result = {'response': 'ok', 'image_series': '', 'image_list': []}
    # 当前connect_id为专题id
    connect_id = request.args.get('id')
    page = request.args.get('page', 1)
    limit = 20
    try:
        with get_session() as db_session:
            image_series = db_session.query(ImageSeries).get(connect_id)
            if image_series:
                image_series.view_count += 1
                db_session.commit()
                image_series_dict = image_series.to_dict()
                image_series_dict['is_collected'] = 0
                result['image_series'] = image_series_dict
                if current_user.is_authenticated():
                    image_collect = db_session.query(CustomerCollect).filter(
                        CustomerCollect.collect_id == image_series.id,
                        CustomerCollect.customer_id == current_user.id,
                        CustomerCollect.type ==
                        CustomerCollect.TYPE_SERIES).first()
                    if image_collect:
                        image_series_dict['is_collected'] = 1

                query = db_session.query(ImageSeriesRel).join(
                    ImageSeries,
                    ImageSeries.id == ImageSeriesRel.image_series_id).filter(
                        ImageSeries.id == connect_id).all()

                image_ids = [image_rel.image_id for image_rel in query]
                query = db_session.query(Image).filter(
                    Image.id.in_(image_ids)).order_by(-Image.created_date)

                paginator = SQLAlchemyPaginator(query, limit)
                page = paginator.get_validate_page(page)

                _image_list = list()
                for image in paginator.page(page):
                    image_dict = image.to_dict()
                    _image_list.append(image_dict)
                result['image_list'] = _image_list
                result.update({
                    'meta': {
                        'cur_page': page,
                        'all_page': paginator.max_page,
                        'count': paginator.count
                    }
                })
        return jsonify(result)
    except Exception as e:
        print e
Ejemplo n.º 8
0
def get_series_list_page():
    result = {'response': 'ok', 'series_category': '', 'series_list': []}
    # 当前connect_id为专题分类id
    connect_id = request.args.get('id')
    page = request.args.get('page', 1)
    limit = 12
    try:
        with get_session() as db_session:
            image_series_category = db_session.query(ImageSeriesCategory).get(
                connect_id)
            image_series_category_dict = image_series_category.to_dict()
            result['series_category'] = image_series_category_dict

            query = db_session.query(ImageSeriesCategoryRel).join(
                ImageSeriesCategory, ImageSeriesCategory.id ==
                ImageSeriesCategoryRel.category_id).filter(
                    ImageSeriesCategory.id == connect_id).all()
            image_series_ids = [
                image_series_category_rel.series_id
                for image_series_category_rel in query
            ]
            query = db_session.query(ImageSeries).filter(
                ImageSeries.id.in_(image_series_ids)).order_by(
                    -ImageSeries.created_date)

            paginator = SQLAlchemyPaginator(query, limit)
            page = paginator.get_validate_page(page)

            _image_series_list = list()
            for image_series in paginator.page(page):
                image_series_dict = image_series.to_dict()
                image_series_dict['is_collected'] = False
                width, height = image_series.get_cover_img_info()
                image_series_dict['width'] = width
                image_series_dict['height'] = height
                _image_series_list.append(image_series_dict)
            result['series_list'] = _image_series_list
            result.update({
                'meta': {
                    'cur_page': page,
                    'all_page': paginator.max_page,
                    'count': paginator.count
                }
            })
        return jsonify(result)
    except Exception as e:
        print e
Ejemplo n.º 9
0
def image_tag_list():
    result = {
        'response': 'ok',
        'image_tag_list': [],
        'info': '',
        'meta': {}
    }
    try:
        limit = 20
        page = request.args.get('page', 1)
        with get_session() as db_session:
            all_image_tag = db_session.query(ImageTags)
            paginator = SQLAlchemyPaginator(all_image_tag, limit)
            page = paginator.get_validate_page(page)

            _image_tag_list = list()
            for image_tag in paginator.page(page):
                image_tag_dict = image_tag.to_dict()
                all_association_tag = image_tag.all_association_tag
                all_association_tag_list = list()
                for association_tag in all_association_tag:
                    association_tag_dict = association_tag.to_dict()
                    all_association_tag_list.append(association_tag_dict)
                image_tag_dict['all_association_tag'] = all_association_tag_list

                _image_tag_list.append(image_tag_dict)
            result['image_tag_list'] = _image_tag_list

            result.update({
                'meta': {
                    'cur_page': page,
                    'all_page': paginator.max_page,
                    'count': paginator.count
                }
            })
        return jsonify(result)
    except Exception as e:
        print e
        abort(400)
Ejemplo n.º 10
0
def get_column_all_series():
    result = {'response': 'ok', 'meta': '', 'data_list': []}
    search = request.args.get('search')
    limit = request.args.get('limit', 10)
    page = request.args.get('page', 1)
    column_id = request.args.get('column_id')
    with get_session() as db_session:
        query = db_session.query(ImageSeries).order_by(
            -ImageSeries.modified_date)

        has_series_list = list()
        all_series = db_session.query(WebsiteColumnSeriesRel).filter(
            WebsiteColumnSeriesRel.column_id == column_id).all()
        for series in all_series:
            has_series_list.append(series.series_id)
        query = query.filter(ImageSeries.id.notin_(has_series_list))

        if search:
            query = query.filter(ImageSeries.name.like('%%%s%%' % search))

        paginator = SQLAlchemyPaginator(query, limit)
        page = paginator.get_validate_page(page)

        _data_list = list()

        for series in paginator.page(page):
            series_dict = series.to_dict()
            _data_list.append(series_dict)

        result['data_list'] = _data_list
        result.update({
            'meta': {
                'cur_page': page,
                'all_page': paginator.max_page,
                'count': paginator.count
            }
        })
    return jsonify(result)
Ejemplo n.º 11
0
def get_filter_image_list():
    result = {
        'response': 'ok',
        'info': '',
        'image_list': [],
        'all_image_format': [],
        'recommend_tag_list': []
    }
    # 搜索条件是按照标签进行搜索
    search = request.args.get('search', '')
    page = request.args.get('page', 1)
    image_format = request.args.get('format', u'all')
    selected_sort = request.args.get('sort', u'created_date')
    color = request.args.get('color', u"0")
    limit = 20
    try:
        all_selected_images = list()
        all_image_format = Image.all_image_format()
        all_image_sort_dict = Image.all_image_sort()
        all_image_sort = [sort for sort in all_image_sort_dict]
        all_image_sort_str = [
            sort_str for sort_str in all_image_sort_dict.values()
        ]
        result.update({
            'search': search,
            'search_count': 0,
            'all_image_format': all_image_format,
            'all_image_sort': all_image_sort,
            'all_image_sort_str': all_image_sort_str,
            'meta': {
                'cur_page': 1,
                'all_page': 1,
                'count': 0
            }
        })
        with get_session() as db_session:
            # 根据用户搜索条件查询推荐标签分组
            recommend_tag_list = list()
            association_tag = db_session.query(ImageAssociationTag).filter(
                ImageAssociationTag.name.like('%' + search + '%')).first()
            main_tag = db_session.query(ImageTags).filter(
                ImageTags.name.like('%' + search + '%')).first()
            if association_tag or main_tag:
                tag_id = main_tag.id if main_tag else association_tag.id
                # 推荐标签组
                recommend_tags = db_session.query(
                    ImageRecommendTagsRel).filter(
                        ImageRecommendTagsRel.tag_id == tag_id).all()
                for recommend_tag in recommend_tags:
                    recommend_another_tags = db_session.query(ImageTags).join(
                        ImageRecommendTagsRel,
                        ImageRecommendTagsRel.tag_id == ImageTags.id).filter(
                            ImageRecommendTagsRel.recommend_tag_id ==
                            recommend_tag.recommend_tag_id).all()
                    for recommend_another_tag in recommend_another_tags:
                        if recommend_another_tag.name not in recommend_tag_list:
                            recommend_tag_list.append(
                                recommend_another_tag.name)

                image_query = db_session.query(ImageTagsRel).filter(
                    ImageTagsRel.tag_id == tag_id).all()

                # 搜索关键词
                tag = db_session.query(ImageTags).filter(
                    ImageTags.id == tag_id).first()
                if tag:
                    tag.view_count += 1
                db_session.commit()

                image_ids = [image_tag.image_id for image_tag in image_query]
                query = db_session.query(Image).filter(Image.id.in_(image_ids))
                # 图片格式
                if image_format != u'all':
                    query = query.filter(Image.format == image_format)
                # 图片排序
                if selected_sort == u'created_date':
                    query = query.order_by(-Image.created_date)
                elif selected_sort == u'recommend':
                    query = query.filter(Image.is_recommend == True).order_by(
                        -Image.created_date)
                elif selected_sort == u'download':
                    query = query.order_by(-Image.download_count)
                elif selected_sort == u'view':
                    query = query.order_by(-Image.view_count)

                # 选择颜色
                if int(color) == 1:
                    query = query.filter(Image.color == Image.RED)
                elif int(color) == 2:
                    query = query.filter(Image.color == Image.ORANGE)
                elif int(color) == 3:
                    query = query.filter(Image.color == Image.YELLOW)
                elif int(color) == 4:
                    query = query.filter(Image.color == Image.GREEN)
                elif int(color) == 5:
                    query = query.filter(Image.color == Image.BLUE)
                elif int(color) == 11:
                    query = query.filter(Image.color == Image.CYAN)
                elif int(color) == 6:
                    query = query.filter(Image.color == Image.PURPLE)
                elif int(color) == 7:
                    query = query.filter(Image.color == Image.PINK)
                elif int(color) == 8:
                    query = query.filter(Image.color == Image.BROWN)
                elif int(color) == 9:
                    query = query.filter(Image.color == Image.WHITE)
                elif int(color) == 10:
                    query = query.filter(Image.color == Image.BLACK)

                search_count = query.count() if query.count() else 0
                paginator = SQLAlchemyPaginator(query, limit)
                page = paginator.get_validate_page(page)

                for tag_image in paginator.page(page):
                    tag_image_dict = tag_image.to_dict()
                    all_selected_images.append(tag_image_dict)
                result.update({
                    'image_list': all_selected_images,
                    'search': search,
                    'search_count': search_count,
                    'all_image_format': all_image_format,
                    'all_image_sort': all_image_sort,
                    'all_image_sort_str': all_image_sort_str,
                    'recommend_tag_list': recommend_tag_list,
                    'meta': {
                        'cur_page': page,
                        'all_page': paginator.max_page,
                        'count': paginator.count
                    }
                })
        return jsonify(result)
    except Exception as e:
        print e