示例#1
0
文件: views.py 项目: xuemy/flaskbb
def index():
    try:
        forum_ids = current_app.config["PLUGIN_PORTAL_FORUM_IDS"]
    except KeyError:
        forum_ids = [1]
        flash("Please install the plugin first to configure the forums "
              "which should be displayed", "warning")

    news = Topic.query.filter(Topic.forum_id.in_(forum_ids)).all()
    recent_topics = Topic.query.order_by(Topic.date_created).limit(5).offset(0)

    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()

        # Because we do not have server side sessions, we cannot check if there
        # are online guests
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template("index.html", news=news, recent_topics=recent_topics,
                           user_count=user_count, topic_count=topic_count,
                           post_count=post_count, newest_user=newest_user,
                           online_guests=online_guests,
                           online_users=online_users)
示例#2
0
def who_is_online():
    if current_app.config['REDIS_ENABLED']:
        online_users = get_online_users()
    else:
        online_users = User.query.filter(User.lastseen >= time_diff()).all()
    return render_template("forum/online_users.html",
                           online_users=online_users)
示例#3
0
文件: views.py 项目: zhy0313/hotface
def overview():
    # user and group stats
    banned_users = User.query.filter(
        Group.banned == True, Group.id == User.primary_group_id).count()
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()
    else:
        online_users = len(get_online_users())

    stats = {
        # user stats
        "all_users": User.query.count(),
        "banned_users": banned_users,
        "online_users": online_users,
        "all_groups": Group.query.count(),
        # forum stats
        "report_count": Report.query.count(),
        "topic_count": Topic.query.count(),
        "post_count": Post.query.count(),
        # misc stats
        "plugins": get_all_plugins(),
        "python_version": "%s.%s" % (sys.version_info[0], sys.version_info[1]),
        "flask_version": flask_version,
        "flaskbb_version": flaskbb_version
    }

    return render_template("management/overview.html", **stats)
示例#4
0
    def get(self, topic_id, slug=None):
        page = request.args.get("page", 1, type=int)

        # Fetch some information about the topic
        topic = Topic.get_topic(topic_id=topic_id, user=real(current_user))

        # Count the topic views
        topic.views += 1
        topic.save()

        # Update the topicsread status if the user hasn't read it
        forumsread = None
        if current_user.is_authenticated:
            forumsread = ForumsRead.query.filter_by(
                user_id=current_user.id, forum_id=topic.forum_id).first()

        topic.update_read(real(current_user), topic.forum, forumsread)

        # fetch the posts in the topic
        posts = Post.query.outerjoin(User, Post.user_id == User.id).filter(
            Post.topic_id == topic.id).add_entity(User).order_by(
                Post.id.asc()).paginate(page, flaskbb_config["POSTS_PER_PAGE"],
                                        False)

        # Abort if there are no posts on this page
        if len(posts.items) == 0:
            abort(404)

        return render_template("forum/topic.html",
                               topic=topic,
                               posts=posts,
                               last_seen=time_diff(),
                               form=self.form())
示例#5
0
    def get(self):
        categories = Category.get_all(user=real(current_user))

        # Fetch a few stats about the forum
        user_count = User.query.count()
        topic_count = Topic.query.count()
        post_count = Post.query.count()
        newest_user = User.query.order_by(User.id.desc()).first()

        # Check if we use redis or not
        if not current_app.config["REDIS_ENABLED"]:
            online_users = User.query.filter(
                User.lastseen >= time_diff()).count()

            # Because we do not have server side sessions,
            # we cannot check if there are online guests
            online_guests = None
        else:
            online_users = len(get_online_users())
            online_guests = len(get_online_users(guest=True))

        return render_template("forum/index.html",
                               categories=categories,
                               user_count=user_count,
                               topic_count=topic_count,
                               post_count=post_count,
                               newest_user=newest_user,
                               online_users=online_users,
                               online_guests=online_guests)
示例#6
0
def index(payload=''):
    categories = Category.get_all(user=current_user)

    # Fetch a few stats about the forum
    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()

        # Because we do not have server side sessions, we cannot check if there
        # are online guests
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template("forum/index.html",
                           categories=categories,
                           user_count=user_count,
                           topic_count=topic_count,
                           post_count=post_count,
                           newest_user=newest_user,
                           online_users=online_users,
                           online_guests=online_guests,
                           # XSS added for educational purpose
                           payload=payload)
示例#7
0
def who_is_online():
    if current_app.config['REDIS_ENABLED']:
        online_users = get_online_users()
    else:
        online_users = User.query.filter(User.lastseen >= time_diff()).all()
    return render_template("forum/online_users.html",
                           online_users=online_users)
示例#8
0
文件: views.py 项目: 0xsKu/flaskbb
def overview():
    # user and group stats
    banned_users = User.query.filter(
        Group.banned == True,
        Group.id == User.primary_group_id
    ).count()
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()
    else:
        online_users = len(get_online_users())

    stats = {
        # user stats
        "all_users": User.query.count(),
        "banned_users": banned_users,
        "online_users": online_users,
        "all_groups": Group.query.count(),
        # forum stats
        "report_count": Report.query.count(),
        "topic_count": Topic.query.count(),
        "post_count": Post.query.count(),
        # misc stats
        "plugins": get_all_plugins(),
        "python_version": "%s.%s" % (sys.version_info[0], sys.version_info[1]),
        "flask_version": flask_version,
        "flaskbb_version": flaskbb_version
    }

    return render_template("management/overview.html", **stats)
示例#9
0
def view_topic(topic_id, slug=None):
    page = request.args.get('page', 1, type=int)

    topic = Topic.query.filter_by(id=topic_id).first()
    posts = Post.query.filter_by(topic_id=topic.id).\
        order_by(Post.id.asc()).\
        paginate(page, flaskbb_config['POSTS_PER_PAGE'], False)

    # Count the topic views
    topic.views += 1

    # Update the topicsread status if the user hasn't read it
    forumsread = None
    if current_user.is_authenticated():
        forumsread = ForumsRead.query.\
            filter_by(user_id=current_user.id,
                      forum_id=topic.forum.id).first()

    topic.update_read(current_user, topic.forum, forumsread)
    topic.save()

    form = None

    if can_post_reply(user=current_user, topic=topic):
        form = QuickreplyForm()
        if form.validate_on_submit():
            post = form.save(current_user, topic)
            return view_post(post.id)

    return render_template("forum/topic.html", topic=topic, posts=posts,
                           last_seen=time_diff(), form=form)
示例#10
0
def index():
    page = request.args.get("page", 1, type=int)
    forum_ids = []

    plugin = PluginRegistry.query.filter_by(name="portal").first()
    if plugin and not plugin.settings:
        flash(
            _("Please install the plugin first to configure the forums "
              "which should be displayed."),
            "warning",
        )
    else:
        forum_ids = plugin.settings["forum_ids"]
    group_ids = [group.id for group in current_user.groups]
    forums = Forum.query.filter(Forum.groups.any(Group.id.in_(group_ids)))

    # get the news forums - check for permissions
    news_ids = [f.id for f in forums.filter(Forum.id.in_(forum_ids)).all()]
    news = (Topic.query.filter(Topic.forum_id.in_(news_ids)).order_by(
        Topic.id.desc()).paginate(page, flaskbb_config["TOPICS_PER_PAGE"],
                                  True))

    # get the recent topics from all to the user available forums (not just the
    # configured ones)
    all_ids = [f.id for f in forums.all()]
    recent_topics = (Topic.query.filter(Topic.forum_id.in_(all_ids)).order_by(
        Topic.last_updated.desc()).limit(
            plugin.settings.get("recent_topics", 10)))

    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template(
        "index.html",
        news=news,
        recent_topics=recent_topics,
        user_count=user_count,
        topic_count=topic_count,
        post_count=post_count,
        newest_user=newest_user,
        online_guests=online_guests,
        online_users=online_users,
    )
示例#11
0
文件: views.py 项目: Ma233/flaskbb
def index():
    page = request.args.get("page", 1, type=int)

    try:
        forum_ids = flaskbb_config["PLUGIN_PORTAL_FORUM_IDS"]
    except KeyError:
        forum_ids = []
        flash(_("Please install the plugin first to configure the forums " "which should be displayed"), "warning")

    group_ids = [group.id for group in current_user.groups]
    forums = Forum.query.filter(Forum.groups.any(Group.id.in_(group_ids)))

    # get the news forums - check for permissions
    news_ids = [f.id for f in forums.filter(Forum.id.in_(forum_ids)).all()]
    news = (
        Topic.query.filter(Topic.forum_id.in_(news_ids))
        .order_by(Topic.id.desc())
        .paginate(page, flaskbb_config["TOPICS_PER_PAGE"], True)
    )

    # get the recent topics from all to the user available forums (not just the
    # configured ones)
    all_ids = [f.id for f in forums.all()]
    recent_topics = (
        Topic.query.filter(Topic.forum_id.in_(all_ids))
        .order_by(Topic.last_updated.desc())
        .limit(flaskbb_config.get("PLUGIN_PORTAL_RECENT_TOPICS", 10))
    )

    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template(
        "index.html",
        news=news,
        recent_topics=recent_topics,
        user_count=user_count,
        topic_count=topic_count,
        post_count=post_count,
        newest_user=newest_user,
        online_guests=online_guests,
        online_users=online_users,
    )
示例#12
0
def index():
    # Get the categories and forums
    if current_user.is_authenticated():
        forum_query = Category.query.\
            join(Forum, Category.id == Forum.category_id).\
            outerjoin(ForumsRead,
                      db.and_(ForumsRead.forum_id == Forum.id,
                              ForumsRead.user_id == current_user.id)).\
            add_entity(Forum).\
            add_entity(ForumsRead).\
            order_by(Category.id, Category.position, Forum.position).\
            all()
    else:
        # we do not need to join the ForumsRead because the user isn't
        # signed in
        forum_query = Category.query.\
            join(Forum, Category.id == Forum.category_id).\
            add_entity(Forum).\
            order_by(Category.id, Category.position, Forum.position).\
            all()

        forum_query = [(category, forum, None)
                       for category, forum in forum_query]

    categories = get_forums(forum_query)

    # Fetch a few stats about the forum
    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()

        # Because we do not have server side sessions, we cannot check if there
        # are online guests
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template("forum/index.html",
                           categories=categories,
                           user_count=user_count,
                           topic_count=topic_count,
                           post_count=post_count,
                           newest_user=newest_user,
                           online_users=online_users,
                           online_guests=online_guests)
示例#13
0
文件: views.py 项目: xiaoyu0/flaskbb
def overview():
    # user and group stats
    banned_users = User.query.filter(
        Group.banned == True,
        Group.id == User.primary_group_id
    ).count()
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()
    else:
        online_users = len(get_online_users())

    unread_reports = Report.query.\
        filter(Report.zapped == None).\
        order_by(Report.id.desc()).\
        count()

    celery_inspect = celery.control.inspect()
    try:
        celery_running = True if celery_inspect.ping() else False
    except Exception:
        # catching Exception is bad, and just catching ConnectionError
        # from redis is also bad because you can run celery with other
        # brokers as well.
        celery_running = False

    python_version = "{}.{}.{}".format(
        sys.version_info[0], sys.version_info[1], sys.version_info[2]
    )

    stats = {
        "current_app": current_app,
        "unread_reports": unread_reports,
        # stats stats
        "all_users": User.query.count(),
        "banned_users": banned_users,
        "online_users": online_users,
        "all_groups": Group.query.count(),
        "report_count": Report.query.count(),
        "topic_count": Topic.query.count(),
        "post_count": Post.query.count(),
        # components
        "python_version": python_version,
        "celery_version": celery_version,
        "celery_running": celery_running,
        "flask_version": flask_version,
        "flaskbb_version": flaskbb_version,
        # plugins
        "plugins": get_all_plugins()
    }

    return render_template("management/overview.html", **stats)
示例#14
0
文件: views.py 项目: miyanda2/flaskbb
    def get(self):
        # user and group stats
        banned_users = User.query.filter(
            Group.banned == True, Group.id == User.primary_group_id).count()
        if not current_app.config["REDIS_ENABLED"]:
            online_users = User.query.filter(
                User.lastseen >= time_diff()).count()
        else:
            online_users = len(get_online_users())

        unread_reports = Report.query.\
            filter(Report.zapped == None).\
            order_by(Report.id.desc()).\
            count()

        celery_inspect = celery.control.inspect()
        try:
            celery_running = True if celery_inspect.ping() else False
        except Exception:
            # catching Exception is bad, and just catching ConnectionError
            # from redis is also bad because you can run celery with other
            # brokers as well.
            celery_running = False

        python_version = "{}.{}.{}".format(sys.version_info[0],
                                           sys.version_info[1],
                                           sys.version_info[2])

        stats = {
            "current_app": current_app,
            "unread_reports": unread_reports,
            # stats stats
            "all_users": User.query.count(),
            "banned_users": banned_users,
            "online_users": online_users,
            "all_groups": Group.query.count(),
            "report_count": Report.query.count(),
            "topic_count": Topic.query.count(),
            "post_count": Post.query.count(),
            # components
            "python_version": python_version,
            "celery_version": celery_version,
            "celery_running": celery_running,
            "flask_version": flask_version,
            "flaskbb_version": flaskbb_version,
            # plugins
            "plugins": PluginRegistry.query.all()
        }

        return render_template("management/overview.html", **stats)
示例#15
0
def index():
    page = request.args.get('page', 1, type=int)

    try:
        forum_ids = flaskbb_config["PLUGIN_PORTAL_FORUM_IDS"]
    except KeyError:
        forum_ids = []
        flash(
            _("Please install the plugin first to configure the forums "
              "which should be displayed"), "warning")

    group_ids = [group.id for group in current_user.groups]
    forums = Forum.query.filter(Forum.groups.any(Group.id.in_(group_ids)))

    # get the news forums - check for permissions
    news_ids = [f.id for f in forums.filter(Forum.id.in_(forum_ids)).all()]
    news = Topic.query.filter(Topic.forum_id.in_(news_ids)).\
        order_by(Topic.id.desc()).\
        paginate(page, flaskbb_config["TOPICS_PER_PAGE"], True)

    # get the recent topics from all to the user available forums (not just the
    # configured ones)
    all_ids = [f.id for f in forums.all()]
    recent_topics = Topic.query.filter(Topic.forum_id.in_(all_ids)).\
        order_by(Topic.last_updated.desc()).\
        limit(flaskbb_config.get("PLUGIN_PORTAL_RECENT_TOPICS", 10))

    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template("index.html",
                           news=news,
                           recent_topics=recent_topics,
                           user_count=user_count,
                           topic_count=topic_count,
                           post_count=post_count,
                           newest_user=newest_user,
                           online_guests=online_guests,
                           online_users=online_users)
示例#16
0
def index():
    page = request.args.get('page', 1, type=int)

    try:
        forum_ids = flaskbb_config["PLUGIN_PORTAL_FORUM_IDS"]
    except KeyError:
        forum_ids = [1]
        flash(
            _("Please install the plugin first to configure the forums "
              "which should be displayed"), "warning")

    news = Topic.query.filter(Topic.forum_id.in_(forum_ids)).\
        order_by(Topic.id.desc()).\
        paginate(page, flaskbb_config["TOPICS_PER_PAGE"], True)

    recent_topics = Topic.query.order_by(Topic.last_updated.desc()).limit(
        flaskbb_config.get("PLUGIN_PORTAL_RECENT_TOPICS", 10))

    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()

        # Because we do not have server side sessions, we cannot check if there
        # are online guests
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template("index.html",
                           news=news,
                           recent_topics=recent_topics,
                           user_count=user_count,
                           topic_count=topic_count,
                           post_count=post_count,
                           newest_user=newest_user,
                           online_guests=online_guests,
                           online_users=online_users)
示例#17
0
def view_topic(topic_id, slug=None):
    page = request.args.get('page', 1, type=int)

    # Fetch some information about the topic
    topic = Topic.get_topic(topic_id=topic_id, user=current_user)

    # Count the topic views
    topic.views += 1
    topic.save()

    # fetch the posts in the topic
    posts = Post.query.\
        join(User, Post.user_id == User.id).\
        filter(Post.topic_id == topic.id).\
        add_entity(User).\
        order_by(Post.id.asc()).\
        paginate(page, flaskbb_config['POSTS_PER_PAGE'], False)

    # Abort if there are no posts on this page
    if len(posts.items) == 0:
        abort(404)

    # Update the topicsread status if the user hasn't read it
    forumsread = None
    if current_user.is_authenticated:
        forumsread = ForumsRead.query.\
            filter_by(user_id=current_user.id,
                      forum_id=topic.forum.id).first()

    topic.update_read(current_user, topic.forum, forumsread)

    form = None
    if Permission(CanPostReply):
        form = QuickreplyForm()
        if form.validate_on_submit():
            post = form.save(current_user, topic)
            return view_post(post.id)

    return render_template("forum/topic.html",
                           topic=topic,
                           posts=posts,
                           last_seen=time_diff(),
                           form=form)
示例#18
0
文件: views.py 项目: justanr/flaskbb
    def get(self, topic_id, slug=None):
        page = request.args.get("page", 1, type=int)

        # Fetch some information about the topic
        topic = Topic.get_topic(topic_id=topic_id, user=real(current_user))

        # Count the topic views
        topic.views += 1
        topic.save()

        # Update the topicsread status if the user hasn't read it
        forumsread = None
        if current_user.is_authenticated:
            forumsread = ForumsRead.query.filter_by(
                user_id=current_user.id,
                forum_id=topic.forum_id).first()

        topic.update_read(real(current_user), topic.forum, forumsread)

        # fetch the posts in the topic
        posts = Post.query.outerjoin(
            User, Post.user_id == User.id
        ).filter(
            Post.topic_id == topic.id
        ).add_entity(
            User
        ).order_by(
            Post.id.asc()
        ).paginate(page, flaskbb_config["POSTS_PER_PAGE"], False)

        # Abort if there are no posts on this page
        if len(posts.items) == 0:
            abort(404)

        return render_template(
            "forum/topic.html",
            topic=topic,
            posts=posts,
            last_seen=time_diff(),
            form=self.form()
        )
示例#19
0
文件: views.py 项目: eirnym/flaskbb
    def get(self):
        # user and group stats
        banned_users = User.query.filter(
            Group.banned == True, Group.id == User.primary_group_id
        ).count()
        if not current_app.config["REDIS_ENABLED"]:
            online_users = User.query.filter(User.lastseen >= time_diff()
                                             ).count()
        else:
            online_users = len(get_online_users())

        unread_reports = Report.query.\
            filter(Report.zapped == None).\
            order_by(Report.id.desc()).\
            count()

        python_version = "{}.{}.{}".format(
            sys.version_info[0], sys.version_info[1], sys.version_info[2]
        )

        stats = {
            "current_app": current_app,
            "unread_reports": unread_reports,
            # stats stats
            "all_users": User.query.count(),
            "banned_users": banned_users,
            "online_users": online_users,
            "all_groups": Group.query.count(),
            "report_count": Report.query.count(),
            "topic_count": Topic.query.count(),
            "post_count": Post.query.count(),
            # components
            "python_version": python_version,
            "celery_version": celery_version,
            "flask_version": flask_version,
            "flaskbb_version": flaskbb_version,
            # plugins
            "plugins": PluginRegistry.query.all()
        }

        return render_template("management/overview.html", **stats)
示例#20
0
    def get(self):
        # user and group stats
        banned_users = User.query.filter(
            Group.banned == True, Group.id == User.primary_group_id
        ).count()
        if not current_app.config["REDIS_ENABLED"]:
            online_users = User.query.filter(User.lastseen >= time_diff()
                                             ).count()
        else:
            online_users = len(get_online_users())

        unread_reports = Report.query.\
            filter(Report.zapped == None).\
            order_by(Report.id.desc()).\
            count()

        python_version = "{}.{}.{}".format(
            sys.version_info[0], sys.version_info[1], sys.version_info[2]
        )

        stats = {
            "current_app": current_app,
            "unread_reports": unread_reports,
            # stats stats
            "all_users": User.query.count(),
            "banned_users": banned_users,
            "online_users": online_users,
            "all_groups": Group.query.count(),
            "report_count": Report.query.count(),
            "topic_count": Topic.query.count(),
            "post_count": Post.query.count(),
            # components
            "python_version": python_version,
            "celery_version": celery_version,
            "flask_version": flask_version,
            "flaskbb_version": flaskbb_version,
            # plugins
            "plugins": PluginRegistry.query.all()
        }

        return render_template("management/overview.html", **stats)
示例#21
0
def view_topic(topic_id, slug=None):
    page = request.args.get('page', 1, type=int)

    # Fetch some information about the topic
    topic = Topic.get_topic(topic_id=topic_id, user=current_user)

    # Count the topic views
    topic.views += 1
    topic.save()

    # fetch the posts in the topic
    posts = Post.query.\
        outerjoin(User, Post.user_id == User.id).\
        filter(Post.topic_id == topic.id).\
        add_entity(User).\
        order_by(Post.id.asc()).\
        paginate(page, flaskbb_config['POSTS_PER_PAGE'], False)

    # Abort if there are no posts on this page
    if len(posts.items) == 0:
        abort(404)

    # Update the topicsread status if the user hasn't read it
    forumsread = None
    if current_user.is_authenticated:
        forumsread = ForumsRead.query.\
            filter_by(user_id=current_user.id,
                      forum_id=topic.forum.id).first()

    topic.update_read(current_user, topic.forum, forumsread)

    form = None
    if Permission(CanPostReply):
        form = QuickreplyForm()
        if form.validate_on_submit():
            post = form.save(current_user, topic)
            return view_post(post.id)

    return render_template("forum/topic.html", topic=topic, posts=posts,
                           last_seen=time_diff(), form=form)
示例#22
0
文件: views.py 项目: mcdir/flaskbb
def view_topic(topic_id, slug=None):
    page = request.args.get('page', 1, type=int)

    topic = Topic.query.filter_by(id=topic_id).first()
    posts = Post.query.filter_by(topic_id=topic.id).\
        order_by(Post.id.asc()).\
        paginate(page, flaskbb_config['POSTS_PER_PAGE'], False)

    # Count the topic views
    topic.views += 1

    # Update the topicsread status if the user hasn't read it
    forumsread = None
    if current_user.is_authenticated():
        forumsread = ForumsRead.query.\
            filter_by(user_id=current_user.id,
                      forum_id=topic.forum.id).first()

    topic.update_read(current_user, topic.forum, forumsread)
    topic.save()

    form = None

    if not topic.locked \
        and not topic.forum.locked \
        and can_post_reply(user=current_user,
                           forum=topic.forum):

        form = QuickreplyForm()
        if form.validate_on_submit():
            post = form.save(current_user, topic)
            return view_post(post.id)

    return render_template("forum/topic.html",
                           topic=topic,
                           posts=posts,
                           last_seen=time_diff(),
                           form=form)
示例#23
0
文件: views.py 项目: PPPython/flaskbb
def index():
    page = request.args.get('page', 1, type=int)

    try:
        forum_ids = flaskbb_config["PLUGIN_PORTAL_FORUM_IDS"]
    except KeyError:
        forum_ids = [1]
        flash(_("Please install the plugin first to configure the forums "
              "which should be displayed"), "warning")

    news = Topic.query.filter(Topic.forum_id.in_(forum_ids)).\
        order_by(Topic.id.desc()).\
        paginate(page, flaskbb_config["TOPICS_PER_PAGE"], True)

    recent_topics = Topic.query.order_by(Topic.last_updated.desc()).limit(
                            flaskbb_config.get("PLUGIN_PORTAL_RECENT_TOPICS", 10))

    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()

        # Because we do not have server side sessions, we cannot check if there
        # are online guests
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template("index.html", news=news, recent_topics=recent_topics,
                           user_count=user_count, topic_count=topic_count,
                           post_count=post_count, newest_user=newest_user,
                           online_guests=online_guests,
                           online_users=online_users)
示例#24
0
def index():
    # Get the categories and forums
    if current_user.is_authenticated():
        categories_query = Forum.query.\
            outerjoin(ForumsRead,
                      db.and_(ForumsRead.forum_id == Forum.id,
                              ForumsRead.user_id == current_user.id)).\
            add_entity(ForumsRead).\
            order_by(Forum.position.asc()).\
            all()
        categories = get_forums(categories_query, current_user=True)
    else:
        categories_query = Forum.query.order_by(Forum.position.asc()).all()
        categories = get_forums(categories_query, current_user=False)

    # Fetch a few stats about the forum
    user_count = User.query.count()
    topic_count = Topic.query.count()
    post_count = Post.query.count()
    newest_user = User.query.order_by(User.id.desc()).first()

    # Check if we use redis or not
    if not current_app.config["REDIS_ENABLED"]:
        online_users = User.query.filter(User.lastseen >= time_diff()).count()
        online_guests = None
    else:
        online_users = len(get_online_users())
        online_guests = len(get_online_users(guest=True))

    return render_template("forum/index.html",
                           categories=categories,
                           user_count=user_count,
                           topic_count=topic_count,
                           post_count=post_count,
                           newest_user=newest_user,
                           online_users=online_users,
                           online_guests=online_guests)