Ejemplo n.º 1
0
def comment():
    if request.method == 'POST':
        comment_id = request.form.get('id')
        comment = Comment.query.get(comment_id)
        if comment:
            db.session.delete(comment)
            db.session.commit()
            return restful.success()
        else:
            return restful.params_error('这条评论不存在')

    if request.method == 'GET':
        page = request.args.get(get_parameter('p'), type=int, default=1)
        start = (page - 1) * 10
        end = start + 10
        total = Comment.query.count()
        comments = Comment.query.slice(start, end)
        pagination = Pagination(page_parameter="p",
                                p=page,
                                bs_version=3,
                                total=total,
                                outer_window=0)
        return render_template("cms/cms_comment.html",
                               comments=comments,
                               pagination=pagination)
Ejemplo n.º 2
0
def actor_list(category):
    if category == 'actor':
        cat = '演员大全'
        query = {'type': 'actor'}
    elif category == 'director':
        cat = '导演大全'
        # 注意: 由于scrapy地去重机制,相当多的导演只有演员页或者导演页
        # 此错误已经修复,暂时未经测试
        query = {'type': 'director'}
    else:
        abort(404)
    page = request.args.get(get_parameter(), type=int, default=1)
    # 每页显示几个
    per_page = 20
    start = (page - 1) * per_page
    end = page * per_page

    # 获取演员列表
    actors = db.actors.find(query).sort([('latest_product_year', -1)
                                         ])[start:end]
    pagination = Pagination(css_framework='bootstrap4',
                            page=page,
                            total=db.actors.count_documents(query),
                            per_page=per_page,
                            record_name='actors')
    return render_template('actor_list.html',
                           actors=actors,
                           pagination=pagination,
                           category=cat)
Ejemplo n.º 3
0
def movie_list(category):
    # 获取类别,生成mongo查询语句
    if category == 'all':
        query = {}
        cat = '全部影视'
    elif category == 'hot':
        query = {'title': {'$in': hot_movies}}
        cat = '热门电影'
    else:
        query = {'info.类型': {'$regex': '.*%s.*' % category}}
        cat = category

    page = request.args.get(get_parameter(), type=int, default=1)
    # 每页显示几个
    per_page = 20
    start = (page - 1) * per_page
    end = page * per_page

    # 获取作品列表
    movies = db.movies.find(query).sort([('year', -1)])[start:end]
    pagination = Pagination(
        css_framework='bootstrap4',
        page=page,
        total=db.movies.count_documents(query),
        per_page=per_page,
        record_name='movies',
        alignment='center',
        inner_window=6,
        outer_window=3,
    )
    return render_template('movie_list.html',
                           movies=movies,
                           pagination=pagination,
                           category=cat)
Ejemplo n.º 4
0
def post():
    page = request.args.get(get_parameter('p'), type=int, default=1)
    start = (page - 1) * 10
    end = start + 10
    total = Post.query.count()
    posts = Post.query.order_by(Post.create_time.asc()).slice(start, end)
    pagination = Pagination(page_parameter="p",
                            p=page,
                            bs_version=3,
                            total=total,
                            outer_window=0)
    return render_template("cms/cms_post.html",
                           posts=posts,
                           pagination=pagination)
Ejemplo n.º 5
0
def posts():
    """帖子管理"""
    page = request.args.get(get_parameter(), type=int, default=1)

    start = (page - 1) * config.POST_PER_PAGE
    end = start + config.POST_PER_PAGE
    post_query = Posts.query.order_by(Posts.create_time.desc())
    paginator = Pagination(bs_version=3,
                           page=page,
                           total=post_query.count(),
                           per_page=config.POST_PER_PAGE,
                           outer_window=0)
    posts_list = post_query.slice(start, end)

    context = {'posts': posts_list, 'pagination': paginator}
    return render_template('cms/posts.html', **context)
Ejemplo n.º 6
0
def job(keyword):
    page = request.args.get(get_parameter(), type=int, default=1)
    per_page = 20
    start = (page - 1) * per_page
    end = page * per_page
    jobs_all = get_jobs_by_keyword(keyword)
    jobs = jobs_all[start:end]
    pagination = Pagination(
        css_framework='bootstrap4',
        page=page,
        total=len(jobs_all),
        per_page=per_page,
        record_name='jobs')
    return render_template('job_list.html',
                           jobs=jobs,
                           pagination=pagination,
                           keyword=keyword)
Ejemplo n.º 7
0
def director_detail(name):
    actor = db.actors.find_one({'name': name, 'type': 'director'})
    if not actor:
        msg = '数据库中没有导演"{}"的信息!'.format(name)
        flash(msg)
        return redirect(request.referrer)
    # 获取人物关系
    relations = actor.get('relations')
    new_relations = []
    for relation in relations:
        person = db.actors.find_one({'name': relation[0]})
        if not person:
            continue
        new_relation = (person, relation[1])
        new_relations.append(new_relation)
    # 获取当前作品页码
    page = request.args.get(get_parameter(), type=int, default=1)
    # 获取作品列表

    # 每页显示几个
    per_page = 20
    start = (page - 1) * per_page
    end = page * per_page
    query = {'info.导演': {'$regex': '.*%s.*' % name}}
    movies = db.movies.find(query)[start:end]
    pagination = Pagination(css_framework='bootstrap4',
                            page=page,
                            total=db.movies.count_documents(query),
                            per_page=per_page,
                            record_name='movies')

    show_movie = False
    referer_url = request.referrer
    if referer_url:
        referer_name = referer_url.split('/')[-1].split('?')[0]
        request_name = request.url.split('/')[-1].split('?')[0]
        if referer_name == quote(request_name):
            show_movie = True

    return render_template('actor_detail.html',
                           actor=actor,
                           relations=new_relations,
                           movies=movies,
                           pagination=pagination,
                           show_movie=show_movie)
Ejemplo n.º 8
0
def index():
    banners = Banner.query.order_by(Banner.priority.desc()).limit(4)
    plates = Plate().query.all()
    posts_top = Post.query.filter(Post.top.is_(True))
    page = request.args.get(get_parameter('p'), type=int, default=1)
    plate_id = request.args.get('plate', type=int, default=None)
    sort = request.args.get('sort', type=str, default="new")
    start = (page - 1) * 10
    end = start + 10
    query_obj = Post.query
    if sort == "new":
        query_obj = Post.query.order_by(Post.create_time.desc())
    elif sort == 'hot':
        query_obj = Post.query.order_by(Post.read_num.desc())
    elif sort == 'like':
        pass
    elif sort == 'reply':
        query_obj = db.session.query(Post).outerjoin(Comment).group_by(
            Post.id).order_by(func.count(Comment.id).desc())
    if plate_id:
        query = query_obj.filter(Post.plate_id == plate_id)
        posts = query.slice(start, end)
        total = query.count()
    else:
        query = query_obj.filter(Post.recommend.is_(True))
        posts = query.slice(start, end)
        total = query.count()
    pagination = Pagination(page_parameter="p",
                            bs_version=3,
                            p=page,
                            total=total,
                            outer_window=0)
    context = {
        "banners": banners,
        "plates": plates,
        "posts": posts,
        "posts_top": posts_top,
        "pagination": pagination,
        'select_plate': plate_id,
        'select_sort': sort,
    }
    return render_template('front/index.html', **context)
Ejemplo n.º 9
0
def search():
    type = request.args.get('type')
    category = request.args.get('category')
    search_text = request.args.get('search_text')
    if type == 'movie':
        if category and category != '全部':
            query = {
                'info.类型': {
                    '$regex': '.*%s.*' % category
                },
                'title': {
                    '$regex': '.*%s.*' % search_text.strip()
                }
            }
            page = request.args.get(get_parameter(), type=int, default=1)
            cat = '在类型"{}"中搜索电影"{}"的结果'.format(category, search_text)
        else:
            query = {'title': {'$regex': '.*%s.*' % search_text.strip()}}
            page = request.args.get(get_parameter(), type=int, default=1)
            cat = '搜索电影"%s"的结果' % search_text
        # 每页显示几个
        per_page = 20
        start = (page - 1) * per_page
        end = page * per_page

        # 获取作品列表
        movies = db.movies.find(query)[start:end]
        pagination = Pagination(css_framework='bootstrap4',
                                page=page,
                                total=db.movies.count_documents(query),
                                per_page=per_page,
                                record_name='movies')
        return render_template('movie_list.html',
                               movies=movies,
                               pagination=pagination,
                               category=cat)
    elif type == 'actor':
        query = {
            'name': {
                '$regex': '.*%s.*' % search_text.strip()
            },
            'type': 'actor'
        }
        page = request.args.get(get_parameter(), type=int, default=1)
        cat = '搜索演员"%s"的结果' % search_text
        # 每页显示几个
        per_page = 20
        start = (page - 1) * per_page
        end = page * per_page

        # 获取作品列表
        actors = db.actors.find(query)[start:end]
        pagination = Pagination(css_framework='bootstrap4',
                                page=page,
                                total=db.actors.count_documents(query),
                                per_page=per_page,
                                record_name='actors')
        return render_template('actor_list.html',
                               actors=actors,
                               pagination=pagination,
                               category=cat)
    elif type == 'director':
        query = {
            'name': {
                '$regex': '.*%s.*' % search_text.strip()
            },
            'type': 'director'
        }
        page = request.args.get(get_parameter(), type=int, default=1)
        cat = '搜索导演"%s"的结果' % search_text
        # 每页显示几个
        per_page = 20
        start = (page - 1) * per_page
        end = page * per_page

        # 获取作品列表
        actors = db.actors.find(query)[start:end]
        # 有一些的导演地类型被错误地爬为'actor',用下面地方法当作workaround
        # 此错误已经修复,但未经过测试,测试完应把下面的三行删除!
        # if not actors.count():
        #     query = {'name': {'$regex': '.*%s.*' % search_text.strip()}, 'type': 'actor'}
        #     actors = db.actors.find(query)[start:end]

        pagination = Pagination(css_framework='bootstrap4',
                                page=page,
                                total=db.actors.count_documents(query),
                                per_page=per_page,
                                record_name='actors')
        return render_template('actor_list.html',
                               actors=actors,
                               pagination=pagination,
                               category=cat,
                               type=type)