Ejemplo n.º 1
0
def top(page, sort_by, filter_worth_by):
    query = Repo.filter_by_args(Repo.query, request.args).filter(Repo.mature.is_(True))
    sorts = {
        'wanted': [Repo.worth.desc(), Repo.stargazers_count.desc()],
        'stars': [Repo.stargazers_count.desc()]
    }

    if filter_worth_by not in ('rising', 'solid'):
        filter_worth_by = 'solid'

    query = query.filter(
        (Repo.worth >= app.config['REPOSITORY_WORTH_SOLID']) if filter_worth_by == 'solid' else (
            (Repo.worth > app.config['REPOSITORY_WORTH_DEFAULT']) &
            (Repo.worth < app.config['REPOSITORY_WORTH_SOLID'])
        )
    )

    for f in [sort for sort in (sorts['wanted'] if sort_by not in sorts else sorts[sort_by])]:
        query = query.order_by(f)

    if not g.user:
        query = query.add_columns(db.null())
    else:
        query = UserAttitude.join_by_user_and_repo(query, g.user.id, Repo.id)\
            .add_columns(UserAttitude.attitude)

    entries = query.paginate(page if page > 0 else 1, per_page=20, error_out=False)
    if entries.pages and entries.pages < entries.page:
        return top(entries.pages, sort_by, filter_worth_by)

    return render_template(
        'repository/top.html', languages=Repo.language_distinct(),
        repos=entries, page=page, sort_by=sort_by, filter_worth_by=filter_worth_by
    )
Ejemplo n.º 2
0
def top(sort_by, page):
    query = Repo.filter_by_args(Repo.query,
                                request.args).filter(Repo.worth > 4)
    sorts = {
        'wanted': [Repo.worth.desc(),
                   Repo.stargazers_count.desc()],
        'stars': [Repo.stargazers_count.desc()]
    }

    for f in [
            sort for sort in (
                sorts['wanted'] if sort_by not in sorts else sorts[sort_by])
    ]:
        query = query.order_by(f)

    if not g.user:
        query = query.add_columns(db.null())
    else:
        query = UserAttitude.join_by_user_and_repo(query, g.user.id, Repo.id)\
            .add_columns(UserAttitude.attitude)

    entries = query.paginate(page if page > 0 else 1,
                             per_page=20,
                             error_out=False)
    if entries.pages and entries.pages < entries.page:
        return top(sort_by, entries.pages)

    return render_template('repository/top.html',
                           languages=Repo.language_distinct(),
                           repos=entries,
                           page=page,
                           sort_by=sort_by)
Ejemplo n.º 3
0
def list_by_range(rng):
    map_list = {'day': 'ReportAllDaily', 'week': 'ReportAllWeekly', 'month': 'ReportAllMonthly'}
    model = getattr(report, map_list.get(rng, map_list.get('day')))

    query = Repo.filter_by_args(model.query, request.args)\
        .join(Repo)\
        .order_by(model.cnt_watch.desc())

    if not g.user:
        query = query.add_columns(db.null())
    else:
        query = UserAttitude.join_by_user_and_repo(query, g.user.id, Repo.id)\
            .add_columns(UserAttitude.attitude)

    return render_template('index.html', entries=query, languages=Repo.language_distinct())
Ejemplo n.º 4
0
def list_by_attitude(attitude, page):
    q = UserAttitude.join_by_user_and_repo(Repo.query, g.user.id, Repo.id)\
        .add_columns(UserAttitude.attitude if attitude else db.null())\
        .filter(UserAttitude.attitude == attitude)

    q = Repo.filter_by_args(q, request.args)

    entries = q.paginate(page if page > 0 else 1, per_page=20, error_out=False)
    if entries.pages and entries.pages < entries.page:
        return list_by_attitude(attitude, entries.pages)

    return render_template(
        'repository/attitude.html', repos=entries, attitude=attitude,
        languages=Repo.language_distinct()
    )
Ejemplo n.º 5
0
def list_by_range(rng):
    map_list = {'day': 'ReportAllDaily', 'week': 'ReportAllWeekly', 'month': 'ReportAllMonthly'}
    model = getattr(report, map_list.get(rng, map_list.get('day')))

    query = Repo.filter_by_args(model.query, request.args)\
        .join(Repo)\
        .order_by(model.cnt_watch.desc())

    if not g.user:
        query = query.add_columns(db.null())
    else:
        query = UserAttitude.join_by_user_and_repo(query, g.user.id, Repo.id)\
            .add_columns(UserAttitude.attitude)

    return render_template('index.html', entries=query, languages=Repo.language_distinct())
Ejemplo n.º 6
0
def list_by_attitude(attitude, page):
    q = UserAttitude.join_by_user_and_repo(Repo.query, g.user.id, Repo.id)\
        .add_columns(UserAttitude.attitude if attitude else db.null())\
        .filter(UserAttitude.attitude == attitude)

    q = Repo.filter_by_args(q, request.args)

    entries = q.paginate(page if page > 0 else 1, per_page=20, error_out=False)
    if entries.pages and entries.pages < entries.page:
        return list_by_attitude(attitude, entries.pages)

    return render_template('repository/attitude.html',
                           repos=entries,
                           attitude=attitude,
                           languages=Repo.language_distinct())
Ejemplo n.º 7
0
def top(page):
    q = Repo.filter_by_args(Repo.query, request.args)\
        .filter(Repo.worth > 4)\
        .order_by(Repo.worth.desc())\
        .order_by(Repo.created_at.asc())

    if not g.user:
        q = q.add_columns(db.null())
    else:
        q = UserAttitude.join_by_user_and_repo(q, g.user.id, Repo.id)\
            .add_columns(UserAttitude.attitude)

    entries = q.paginate(page if page > 0 else 1, per_page=20, error_out=False)
    if entries.pages and entries.pages < entries.page:
        return top(entries.pages)

    return render_template(
        'repository/top.html', repos=entries, page=page, languages=Repo.language_distinct()
    )
Ejemplo n.º 8
0
def top(page, sort_by, filter_worth_by):
    query = Repo.filter_by_args(Repo.query,
                                request.args).filter(Repo.mature.is_(True))
    sorts = {
        'wanted': [Repo.worth.desc(),
                   Repo.stargazers_count.desc()],
        'stars': [Repo.stargazers_count.desc()]
    }

    if filter_worth_by not in ('rising', 'solid'):
        filter_worth_by = 'solid'

    query = query.filter((
        Repo.worth >= app.config['REPOSITORY_WORTH_SOLID']
    ) if filter_worth_by == 'solid' else (
        (Repo.worth > app.config['REPOSITORY_WORTH_DEFAULT'])
        & (Repo.worth < app.config['REPOSITORY_WORTH_SOLID'])))

    for f in [
            sort for sort in (
                sorts['wanted'] if sort_by not in sorts else sorts[sort_by])
    ]:
        query = query.order_by(f)

    if not g.user:
        query = query.add_columns(db.null())
    else:
        query = UserAttitude.join_by_user_and_repo(query, g.user.id, Repo.id)\
            .add_columns(UserAttitude.attitude)

    entries = query.paginate(page if page > 0 else 1,
                             per_page=20,
                             error_out=False)
    if entries.pages and entries.pages < entries.page:
        return top(entries.pages, sort_by, filter_worth_by)

    return render_template('repository/top.html',
                           languages=Repo.language_distinct(),
                           repos=entries,
                           page=page,
                           sort_by=sort_by,
                           filter_worth_by=filter_worth_by)
Ejemplo n.º 9
0
def top(page):
    q = Repo.filter_by_args(Repo.query, request.args)\
        .filter(Repo.worth > 6)\
        .order_by(Repo.worth.desc())\
        .order_by(Repo.stargazers_count.desc())

    if not g.user:
        q = q.add_columns(db.null())
    else:
        q = UserAttitude.join_by_user_and_repo(q, g.user.id, Repo.id)\
            .add_columns(UserAttitude.attitude)

    entries = q.paginate(page if page > 0 else 1, per_page=20, error_out=False)
    if entries.pages and entries.pages < entries.page:
        return top(entries.pages)

    return render_template('repository/top.html',
                           repos=entries,
                           page=page,
                           languages=Repo.language_distinct())