示例#1
0
def format_timedelta(delta, **kwargs):
    """Wrapper around babel's format_timedelta to make it user language
    aware.
    """
    locale = flaskbb_config.get("DEFAULT_LANGUAGE", "en")
    if current_user.is_authenticated and current_user.language is not None:
        locale = current_user.language

    return babel_format_timedelta(delta, locale=locale, **kwargs)
示例#2
0
def format_timedelta(delta, **kwargs):
    """Wrapper around babel's format_timedelta to make it user language
    aware.
    """
    locale = flaskbb_config.get("DEFAULT_LANGUAGE", "en")
    if current_user.is_authenticated and current_user.language is not None:
        locale = current_user.language

    return babel_format_timedelta(delta, locale=locale, **kwargs)
示例#3
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,
    )
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
0
def _get_user_locale():
    locale = flaskbb_config.get("DEFAULT_LANGUAGE", "en")
    if current_user.is_authenticated and current_user.language is not None:
        locale = current_user.language
    return locale
示例#8
0
文件: helpers.py 项目: eirnym/flaskbb
def _get_user_locale():
    locale = flaskbb_config.get("DEFAULT_LANGUAGE", "en")
    if current_user.is_authenticated and current_user.language is not None:
        locale = current_user.language
    return locale