def test_model_featured_community(app):
    """Test the featured community model and actions."""
    with app.app_context():
        # Create a user and two communities
        t1 = datetime.now()
        user1 = create_test_user()
        comm1 = Community(id='comm1', id_user=user1.id)
        comm2 = Community(id='comm2', id_user=user1.id)
        db.session.add(comm1)
        db.session.add(comm2)
        db.session.commit()

        # Create two community featurings starting at different times
        fc1 = FeaturedCommunity(id_community=comm1.id,
                                start_date=t1 + timedelta(days=1))
        fc2 = FeaturedCommunity(id_community=comm2.id,
                                start_date=t1 + timedelta(days=3))
        db.session.add(fc1)
        db.session.add(fc2)
        # Check the featured community at three different points in time
        assert FeaturedCommunity.get_featured_or_none(start_date=t1) is None
        assert FeaturedCommunity.get_featured_or_none(
            start_date=t1 + timedelta(days=2)) is comm1
        assert FeaturedCommunity.get_featured_or_none(
            start_date=t1 + timedelta(days=4)) is comm2
예제 #2
0
def index():
    """Index page with uploader and list of existing depositions."""
    ctx = mycommunities_ctx()

    p = request.args.get('p', type=str)
    so = request.args.get('so', type=str)
    page = request.args.get('page', type=int, default=1)

    so = so or current_app.config.get('COMMUNITIES_DEFAULT_SORTING_OPTION')

    communities = Community.filter_communities(p, so).all()
    communities = [c for c in communities
                   if _get_permission("communities-read", c).can()
                   or DynamicPermission(ActionNeed('admin-access')).can()]
    featured_community = FeaturedCommunity.get_featured_or_none()
    form = SearchForm(p=p)
    per_page = 10
    page = max(page, 1)
    p = Pagination(page, per_page, len(communities))

    ctx.update({
        'r_from': max(p.per_page * (p.page - 1), 0),
        'r_to': min(p.per_page * p.page, p.total_count),
        'r_total': p.total_count,
        'pagination': p,
        'form': form,
        'title': _('Communities'),
        'communities': communities[per_page * (page - 1):per_page * page],
        'featured_community': featured_community
    })

    return render_template(
        "invenio_communities/index.html",
        **ctx
    )
예제 #3
0
def index():
    """Index page with uploader and list of existing depositions."""
    ctx = mycommunities_ctx()

    p = request.args.get('p', type=str)
    so = request.args.get('so', type=str)
    page = request.args.get('page', type=int, default=1)

    so = so or current_app.config.get('COMMUNITIES_DEFAULT_SORTING_OPTION')

    communities = Community.filter_communities(p, so)
    featured_community = FeaturedCommunity.get_featured_or_none()
    form = SearchForm(p=p)
    per_page = 10
    page = max(page, 1)
    p = Pagination(page, per_page, communities.count())

    ctx.update({
        'r_from': max(p.per_page * (p.page - 1), 0),
        'r_to': min(p.per_page * p.page, p.total_count),
        'r_total': p.total_count,
        'pagination': p,
        'form': form,
        'title': _('Communities'),
        'communities': communities.slice(
            per_page * (page - 1), per_page * page).all(),
        'featured_community': featured_community,
    })

    return render_template(
        "invenio_communities/index.html",
        **ctx
    )
예제 #4
0
파일: ui.py 프로젝트: kaorisakai/weko
def index():
    """Index page with uploader and list of existing depositions."""
    ctx = mycommunities_ctx()

    p = request.args.get('p', type=str)
    so = request.args.get('so', type=str)
    page = request.args.get('page', type=int, default=1)

    so = so or current_app.config.get('COMMUNITIES_DEFAULT_SORTING_OPTION')

    communities = Community.filter_communities(p, so)
    featured_community = FeaturedCommunity.get_featured_or_none()
    form = SearchForm(p=p)
    per_page = 10
    page = max(page, 1)
    p = Pagination(page, per_page, communities.count())

    ctx.update({
        'r_from': max(p.per_page * (p.page - 1), 0),
        'r_to': min(p.per_page * p.page, p.total_count),
        'r_total': p.total_count,
        'pagination': p,
        'form': form,
        'title': _('Communities'),
        'communities': communities.slice(
            per_page * (page - 1), per_page * page).all(),
        'featured_community': featured_community,
    })

    return render_template(
        current_app.config['COMMUNITIES_INDEX_TEMPLATE'], **ctx)
def test_model_featured_community(app, db, communities):
    """Test the featured community model and actions."""
    (comm1, comm2, comm3) = communities
    t1 = datetime.now()

    # Create two community featurings starting at different times
    fc1 = FeaturedCommunity(id_community=comm1.id,
                            start_date=t1 + timedelta(days=1))
    fc2 = FeaturedCommunity(id_community=comm2.id,
                            start_date=t1 + timedelta(days=3))
    db.session.add(fc1)
    db.session.add(fc2)
    # Check the featured community at three different points in time
    assert FeaturedCommunity.get_featured_or_none(start_date=t1) is None
    assert FeaturedCommunity.get_featured_or_none(start_date=t1 +
                                                  timedelta(days=2)) is comm1
    assert FeaturedCommunity.get_featured_or_none(start_date=t1 +
                                                  timedelta(days=4)) is comm2
def test_model_featured_community(app, db, communities):
    """Test the featured community model and actions."""
    (comm1, comm2, comm3) = communities
    t1 = datetime.now()

    # Create two community featurings starting at different times
    fc1 = FeaturedCommunity(id_community=comm1.id,
                            start_date=t1 + timedelta(days=1))
    fc2 = FeaturedCommunity(id_community=comm2.id,
                            start_date=t1 + timedelta(days=3))
    db_.session.add(fc1)
    db_.session.add(fc2)
    # Check the featured community at three different points in time
    assert FeaturedCommunity.get_featured_or_none(start_date=t1) is None
    assert FeaturedCommunity.get_featured_or_none(
        start_date=t1 + timedelta(days=2)) is comm1
    assert FeaturedCommunity.get_featured_or_none(
        start_date=t1 + timedelta(days=4)) is comm2
예제 #7
0
def load_featured(data):
    """Load community featuring from data dump.

    :param data: Dictionary containing community featuring data.
    :type data: dict
    """
    obj = FeaturedCommunity(id=data['id'],
                            id_community=data['id_community'],
                            start_date=iso2dt(data['start_date']))
    db.session.add(obj)
    db.session.commit()
예제 #8
0
파일: ui.py 프로젝트: weko3-dev35/weko
def community_list():
    """Index page with uploader and list of existing depositions."""
    ctx = mycommunities_ctx()
    from weko_theme.utils import get_design_layout
    # Get the design for widget rendering
    render_page, render_widgets = get_design_layout(
        current_app.config['WEKO_THEME_DEFAULT_COMMUNITY'])
    p = request.args.get('p', type=str)
    so = request.args.get('so', type=str)
    page = request.args.get('page', type=int, default=1)

    so = so or current_app.config.get('COMMUNITIES_DEFAULT_SORTING_OPTION')

    communities = Community.filter_communities(p, so)
    featured_community = FeaturedCommunity.get_featured_or_none()
    form = SearchForm(p=p)
    per_page = 10
    page = max(page, 1)
    p = Pagination(page, per_page, communities.count())

    ctx.update({
        'r_from':
        max(p.per_page * (p.page - 1), 0),
        'r_to':
        min(p.per_page * p.page, p.total_count),
        'r_total':
        p.total_count,
        'pagination':
        p,
        'form':
        form,
        'title':
        _('Communities'),
        'communities':
        communities.slice(per_page * (page - 1), per_page * page).all(),
        'featured_community':
        featured_community,
    })

    return render_template('invenio_communities/communities_list.html',
                           page=render_page,
                           render_widgets=render_widgets,
                           **ctx)