示例#1
0
文件: views.py 项目: ygxing/flaskbbs
def bbs_index():
    options = {}
    page = request.args.get('page', 0, type=int)

    sort = request.args.get('sort', 0, type=int)
    if sort:
        options["sort"] = sort
    else:
        options["sort"] = 0

    query = Topic.query.all_topics(sort)
    count, num_pages, topics = get_page_query(query,
                                              page,
                                              page_size=DEFAULT_PAGE_SIZE)

    def pager_url(p, options):
        return generate_url('.bbs_index', page=p, **options)

    def filter_url(orig_options, **args):
        options = deepcopy(orig_options)
        for k, v in args.items():
            options[k] = v
        return generate_url(".bbs_index", **options)

    sections = Section.query.get_all_sections()
    return render_template("node_index.html",
                           topics=topics,
                           options=options,
                           count=count,
                           pager_url=pager_url,
                           filter_url=filter_url,
                           num_pages=num_pages,
                           page=page,
                           sections=sections,
                           node=None)
示例#2
0
def bbs_index():
    options = {}
    page = request.args.get('page', 0, type=int)

    sort = request.args.get('sort', 0, type=int)
    if sort:
        options["sort"]=sort
    else:
        options["sort"] = 0

    query = Topic.query.all_topics(sort)
    count, num_pages, topics = get_page_query(query, page, page_size=DEFAULT_PAGE_SIZE)

    def pager_url(p, options):
        return generate_url('.bbs_index', page=p, **options)

    def filter_url(orig_options, **args):
        options = deepcopy(orig_options)
        for k,v in args.items():
            options[k] = v
        return generate_url(".bbs_index", **options)

    sections = Section.query.get_all_sections()
    return render_template("node_index.html",
                                topics=topics,
                                options=options,
                                count=count,
                                pager_url=pager_url,
                                filter_url=filter_url,
                                num_pages=num_pages,
                                page=page,
                                sections=sections,
                                node=None
                            )
示例#3
0
def bbs_topic(id):
    options = {"id": id}
    page = request.args.get('page', 0, type=int)
    topic = Topic.query.get(id)
    if not topic:
        return render_template("topic_not_found.html")

    count, num_pages, replies = get_page_query(Reply.query.replies_at_topic(topic.id), page, page_size=DEFAULT_PAGE_REPLIES)
    def pager_url(p, options):
        return generate_url(".bbs_topic", page=p, **options)

    if current_user.is_anonymous():
        form = None
    else:
        form = ReplyForm(request.form)

    if request.method == "POST":
        if current_user.is_anonymous():
            return redirect(url_for("auth.login", next=request.path) or "/")
        if form.validate():
            reply = Reply(section=topic.section, node=topic.node, user=current_user, topic=topic,
                content=form.data["content"], created=datetime.now(), floor=topic.reply_count+1)
            topic.last_reply_by = current_user.username
            topic.last_reply_at = datetime.now()
            topic.reply_count += 1
            current_user.profile.replies += 1
            node = topic.node
            node.reply_count += 1
            section = topic.section
            section.reply_count += 1
            db.session.add_all([reply, topic, current_user.profile, node, section])
            db.session.commit()

            return redirect(pager_url((reply.floor-1)/DEFAULT_PAGE_REPLIES, options))

        return render_template("topic.html", topic=topic, options=options, count=count, pager_url=pager_url,
                                num_pages=num_pages, page=page, replies=replies, form=form)

    topic.hits += 1
    db.session.commit()

    markdowner = Markdown()
    topic.content = markdowner.convert(topic.content)
    for r in replies:
        r.content = markdowner.convert(r.content)

    return render_template("topic.html", topic=topic,
                                            options=options,
                                            count=count,
                                            pager_url=pager_url,
                                            num_pages=num_pages,
                                            page=page,
                                            replies=replies,
                                            form=form
                            )
示例#4
0
def index():
    page = request.args.get("page", 0, type=int)
    query = Message.query.messages(current_user.id)
    count, num_pages, messages = get_page_query(query, page, page_size=10)

    def pager_url(p):
        return generate_url(".index", p)

    return render_template(
        "message.html", messages=messages, count=count, pager_url=pager_url, num_pages=num_pages, page=page
    )
示例#5
0
文件: views.py 项目: ygxing/flaskbbs
def index():
    page = request.args.get('page', 0, type=int)
    query = Message.query.messages(current_user.id)
    count, num_pages, messages = get_page_query(query, page, page_size=10)

    def pager_url(p):
        return generate_url('.index', p)

    return render_template("message.html",
                           messages=messages,
                           count=count,
                           pager_url=pager_url,
                           num_pages=num_pages,
                           page=page)
示例#6
0
文件: views.py 项目: ygxing/flaskbbs
def bbs_node(node_name):
    name = urllib.unquote(node_name).strip()
    node = Node.query.filter(Node.name == name).first()
    if not node:
        return render_template("node_not_found.html", name=name)

    options = {"node_name": node_name}
    page = request.args.get('page', 0, type=int)

    sort = request.args.get('sort', 0, type=int)
    if sort:
        options["sort"] = sort
    else:
        options["sort"] = 0

    query = Topic.query.filter(Topic.node == node).all_topics(sort)
    count, num_pages, topics = get_page_query(query,
                                              page,
                                              page_size=DEFAULT_PAGE_SIZE)

    def pager_url(p, options):
        return generate_url('.bbs_node', page=p, **options)

    def filter_url(orig_options, **args):
        options = deepcopy(orig_options)
        for k, v in args.items():
            options[k] = v
        return generate_url(".bbs_node", **options)

    sections = Section.query.all()
    return render_template("node_index.html",
                           topics=topics,
                           options=options,
                           count=count,
                           pager_url=pager_url,
                           filter_url=filter_url,
                           num_pages=num_pages,
                           page=page,
                           sections=sections,
                           node=node)
示例#7
0
def bbs_node(node_name):
    name = urllib.unquote(node_name).strip()
    node = Node.query.filter(Node.name==name).first()
    if not node:
        return render_template("node_not_found.html", name=name)

    options = {"node_name": node_name}
    page = request.args.get('page', 0, type=int)

    sort = request.args.get('sort', 0, type=int)
    if sort:
        options["sort"]=sort
    else:
        options["sort"] = 0

    query = Topic.query.filter(Topic.node==node).all_topics(sort)
    count, num_pages, topics = get_page_query(query, page, page_size=DEFAULT_PAGE_SIZE)

    def pager_url(p, options):
        return generate_url('.bbs_node', page=p, **options)

    def filter_url(orig_options, **args):
        options = deepcopy(orig_options)
        for k,v in args.items():
            options[k] = v
        return generate_url(".bbs_node", **options)

    sections = Section.query.all()
    return render_template("node_index.html",
        topics=topics,
        options=options,
        count=count,
        pager_url=pager_url,
        filter_url=filter_url,
        num_pages=num_pages,
        page=page,
        sections=sections,
        node=node
    )
示例#8
0
文件: views.py 项目: ygxing/flaskbbs
def bbs_topic(id):
    options = {"id": id}
    page = request.args.get('page', 0, type=int)
    topic = Topic.query.get(id)
    if not topic:
        return render_template("topic_not_found.html")

    count, num_pages, replies = get_page_query(Reply.query.replies_at_topic(
        topic.id),
                                               page,
                                               page_size=DEFAULT_PAGE_REPLIES)

    def pager_url(p, options):
        return generate_url(".bbs_topic", page=p, **options)

    if current_user.is_anonymous():
        form = None
    else:
        form = ReplyForm(request.form)

    if request.method == "POST":
        if current_user.is_anonymous():
            return redirect(url_for("auth.login", next=request.path) or "/")
        if form.validate():
            reply = Reply(section=topic.section,
                          node=topic.node,
                          user=current_user,
                          topic=topic,
                          content=form.data["content"],
                          created=datetime.now(),
                          floor=topic.reply_count + 1)
            topic.last_reply_by = current_user.username
            topic.last_reply_at = datetime.now()
            topic.reply_count += 1
            current_user.profile.replies += 1
            node = topic.node
            node.reply_count += 1
            section = topic.section
            section.reply_count += 1
            db.session.add_all(
                [reply, topic, current_user.profile, node, section])
            db.session.commit()

            return redirect(
                pager_url((reply.floor - 1) / DEFAULT_PAGE_REPLIES, options))

        return render_template("topic.html",
                               topic=topic,
                               options=options,
                               count=count,
                               pager_url=pager_url,
                               num_pages=num_pages,
                               page=page,
                               replies=replies,
                               form=form)

    topic.hits += 1
    db.session.commit()

    markdowner = Markdown()
    topic.content = markdowner.convert(topic.content)
    for r in replies:
        r.content = markdowner.convert(r.content)

    return render_template("topic.html",
                           topic=topic,
                           options=options,
                           count=count,
                           pager_url=pager_url,
                           num_pages=num_pages,
                           page=page,
                           replies=replies,
                           form=form)