示例#1
0
def dashboard(topic_theme):
    db = g.db
    page_limit = 8
    theme = db.session.query(Theme).filter(Theme.url == topic_theme).one()
    try:
        if request.values.get('method'):
            method = request.values.get('method')
        else:
            method = 'all'
    except:
        method = 'all'
    try:
        if request.values.get('page'):
            page = int(request.values.get('page'))
        else:
            page = 1
    except:
        page = 1
    try:
        if method == 'followed':
            query = g.user.followed_posts().filter(Post.theme == theme.id)
        elif method == 'hot':
            query = db.session.query(Post).filter(
                Post.theme == theme.id).order_by(Post.comment_count.desc())
        else:
            query = db.session.query(Post).filter(
                Post.theme == theme.id).order_by(Post.time_update.desc())
        post_len = query.count()
        posts = query.offset(0 + (page_limit *
                                  (page - 1))).limit(page_limit).all()
    except:
        posts = []
        post_len = 0
    page_info = paginate(page, page_limit, post_len)
    return render_template('dashboard.html',
                           posts=posts,
                           theme=theme,
                           page_info=page_info,
                           method=method)
示例#2
0
def topic(topic_id):
    db = g.db
    try:
        if request.values.get('page'):
            page = int(request.values.get('page'))
        else:
            page = 1
    except:
        page = 1
    commentform = forms.CommentForm()
    comment(commentform)
    p = db.session.query(Post).filter(Post.id == topic_id).one()
    page_limit = 10
    if 'logged_in' in session:
        p.read(g.user)
    try:
        comments_len = p.comments.count()
        comments = p.comments.order_by(
            Comment.id.desc()).offset(0 +
                                      (page_limit *
                                       (page - 1))).limit(page_limit).all()
    except:
        comments = []
        comments_len = 0
    page_info = paginate(page, page_limit, comments_len)
    body = Markup(
        markdown.markdown(
            p.body, ['markdown.extensions.extra', 'markdown.extensions.toc']))
    TOC = Markup(toc.markdown_toc(body))
    return render_template('topic.html',
                           body=body,
                           post=p,
                           commentform=commentform,
                           page_info=page_info,
                           comments=comments,
                           page=page,
                           TOC=TOC)
示例#3
0
def daily_list():
    db = g.db
    page_limit = 8
    query = db.session.query(Daily).order_by(Daily.time.desc())
    try:
        if request.values.get('page'):
            page = int(request.values.get('page'))
        else:
            page = 1
    except:
        page = 1

    try:
        daily_len = query.count()
        items = query.offset(0 + (page_limit *
                                  (page - 1))).limit(page_limit).all()
    except:
        items = []
        daily_len = 0
    page_info = paginate(page, page_limit, daily_len)
    return render_template('daily_list.html',
                           page_info=page_info,
                           items=items,
                           page=page)
示例#4
0
def nxb_history():
    db = g.db
    try:
        if request.values.get('day'):
            day = request.values.get('day')
        else:
            day = '10'
    except:
        day = '10'
    try:
        if request.values.get('code'):
            code = request.values.get('code')
        else:
            code = '878004'
    except:
        code = '878004'
    codedict = {
        '878002': '沪深300看涨',
        '878003': '沪深300看跌',
        '878004': '创业看涨',
        '878005': '创业看跌',
        '878006': '上证50看涨',
        '878007': '上证50看跌',
        '878008': '中证500看涨',
        '878009': '中证500看跌'
    }
    name = codedict[code]
    user = g.user
    try:
        p = db.session.query(Post).filter(Post.id == int(code)).one()
    except:
        post = Post(title=name, author_id=0, id=int(code))
        post.save()
        p = db.session.query(Post).filter(Post.id == int(code)).one()
    try:
        if request.values.get('page'):
            page = int(request.values.get('page'))
        else:
            page = 1
    except:
        page = 1
    commentform = forms.CommentForm()
    comment(commentform)
    page_limit = 10
    if 'logged_in' in session:
        p.read(g.user)
    try:
        comments_len = p.comments.count()
        comments = p.comments.order_by(
            Comment.id.desc()).offset(0 +
                                      (page_limit *
                                       (page - 1))).limit(page_limit).all()
    except:
        comments = []
        comments_len = 0
    page_info = paginate(page, page_limit, comments_len)

    return render_template('nxb_history.html',
                           user=user,
                           day=day,
                           code=code,
                           name=name,
                           post=p,
                           commentform=commentform,
                           page_info=page_info,
                           comments=comments,
                           page=page)