Exemplo n.º 1
0
def communities(db, users):
    """Create communities."""
    comm_data = [
        {
            'id': 'c1',
            'user_id': users[1]['id']
        },
        {
            'id': 'c2',
            'user_id': users[1]['id']
        },
        {
            'id': 'c3',
            'user_id': users[0]['id']
        },
        {
            'id': 'c4',
            'user_id': users[0]['id']
        },
        {
            'id': 'zenodo',
            'user_id': users[2]['id']
        },
        {
            'id': 'ecfunded',
            'user_id': users[2]['id']
        },
    ]
    for c in comm_data:
        Community.create(c['id'], user_id=c['user_id'])
    db.session.commit()
    return comm_data
Exemplo n.º 2
0
def communities_for_filtering(app, db, user):
    """Create some example communities."""
    user1 = db_.session.merge(user)

    index = Index()
    db.session.add(index)
    db.session.commit()
    comm0 = Community.create(community_id='comm1',
                             user_id=user1.id,
                             title='Test1',
                             description=('Beautiful is better than ugly. '
                                          'Explicit is better than implicit.'),
                             root_node_id=index.id)
    comm1 = Community.create(community_id='comm2',
                             user_id=user1.id,
                             title='Testing case 2',
                             description=('Flat is better than nested. '
                                          'Sparse is better than dense.'),
                             root_node_id=index.id)
    comm2 = Community.create(community_id='oth3',
                             user_id=user1.id,
                             title='A word about testing',
                             description=('Errors should never pass silently. '
                                          'Unless explicitly silenced.'),
                             root_node_id=index.id)
    return comm0, comm1, comm2
Exemplo n.º 3
0
def communities(app, db, user):
    """Create some example communities."""
    user1 = db_.session.merge(user)

    comm0 = Community.create(community_id="comm1", user_id=user1.id, title="Title1", description="Description1")
    comm1 = Community.create(community_id="comm2", user_id=user1.id, title="A")
    comm2 = Community.create(community_id="oth3", user_id=user1.id)
    return comm0, comm1, comm2
def communities(app, db, user):
    """Create some example communities."""
    user1 = db_.session.merge(user)

    comm0 = Community.create(community_id='comm1', user_id=user1.id,
                             title='Title1', description='Description1')
    comm1 = Community.create(community_id='comm2', user_id=user1.id, title='A')
    comm2 = Community.create(community_id='oth3', user_id=user1.id)
    return comm0, comm1, comm2
Exemplo n.º 5
0
def communities(app, db, user):
    """Create some example communities."""
    user1 = db_.session.merge(user)

    comm0 = Community.create(community_id='comm1',
                             user_id=user1.id,
                             title='Title1',
                             description='Description1')
    comm1 = Community.create(community_id='comm2', user_id=user1.id, title='A')
    comm2 = Community.create(community_id='oth3', user_id=user1.id)
    return comm0, comm1, comm2
Exemplo n.º 6
0
def communities(db, users):
    """Create communities."""
    comm_data = [
        {'id': 'c1', 'user_id': users[1]['id']},
        {'id': 'c2', 'user_id': users[1]['id']},
        {'id': 'c3', 'user_id': users[0]['id']},
        {'id': 'c4', 'user_id': users[0]['id']},
    ]
    for c in comm_data:
        Community.create(c['id'], user_id=c['user_id'])
    db.session.commit()
    return comm_data
Exemplo n.º 7
0
def loadcommunities(owner_email):
    """Load the Zenodo communities fixture.

    Create extra PID if license is to be mapped and already exists, otherwise
    create a new license record and a PID.
    """
    data = read_json('data/communities.json')
    owner = User.query.filter_by(email=owner_email).one()

    for comm_data in data:
        community_id = comm_data.pop('id')
        user_id = owner.id
        Community.create(community_id, user_id, **comm_data)
    db.session.commit()
Exemplo n.º 8
0
def loadcommunities(owner_email):
    """Load the Zenodo communities fixture.

    Create extra PID if license is to be mapped and already exists, otherwise
    create a new license record and a PID.
    """
    data = read_json('data/communities.json')
    owner = User.query.filter_by(email=owner_email).one()

    for comm_data in data:
        community_id = comm_data.pop('id')
        user_id = owner.id
        Community.create(community_id, user_id, **comm_data)
    db.session.commit()
def communities_for_filtering(app, db, user):
    """Create some example communities."""
    user1 = db_.session.merge(user)

    comm0 = Community.create(community_id='comm1', user_id=user1.id,
                             title='Test1',
                             description=('Beautiful is better than ugly. '
                                          'Explicit is better than implicit.'))
    comm1 = Community.create(community_id='comm2', user_id=user1.id,
                             title='Testing case 2',
                             description=('Flat is better than nested. '
                                          'Sparse is better than dense.'))
    comm2 = Community.create(community_id='oth3', user_id=user1.id,
                             title='A word about testing',
                             description=('Errors should never pass silently. '
                                          'Unless explicitly silenced.'))
    return comm0, comm1, comm2
Exemplo n.º 10
0
def communities(app, db, user):
    """Create some example communities."""
    user1 = db_.session.merge(user)

    index = Index()
    db.session.add(index)
    db.session.commit()
    comm0 = Community.create(community_id='comm1',
                             user_id=user1.id,
                             title='Title1',
                             description='Description1',
                             root_node_id=index.id)
    comm1 = Community.create(community_id='comm2',
                             user_id=user1.id,
                             title='A',
                             root_node_id=index.id)
    comm2 = Community.create(community_id='oth3',
                             user_id=user1.id,
                             root_node_id=index.id)
    return comm0, comm1, comm2
Exemplo n.º 11
0
def loadcommunity(comm_data):
    """Load the Zenodo communities fixture."""
    logo_path = comm_data.pop('logo', None)
    community_id = comm_data.pop('id')
    owner_email = comm_data.pop('owner_email')
    owner_id = User.query.filter_by(email=owner_email).one().id
    c = Community.create(community_id, owner_id, **comm_data)
    if logo_path:
        logo = file_stream(logo_path)
        ext = save_and_validate_logo(logo, logo.name, community_id)
        c.logo_ext = ext
    db.session.commit()
Exemplo n.º 12
0
def loadcommunity(comm_data):
    """Load the Zenodo communities fixture."""
    logo_path = comm_data.pop('logo', None)
    community_id = comm_data.pop('id')
    owner_email = comm_data.pop('owner_email')
    owner_id = User.query.filter_by(email=owner_email).one().id
    c = Community.create(community_id, owner_id, **comm_data)
    if logo_path:
        logo = file_stream(logo_path)
        ext = save_and_validate_logo(logo, logo.name, community_id)
        c.logo_ext = ext
    db.session.commit()
Exemplo n.º 13
0
def new():
    """Create a new community."""
    form = CommunityForm(request.values)

    ctx = mycommunities_ctx()
    ctx.update({
        'form': form,
        'is_new': True,
        'community': None,
    })

    if form.validate_on_submit():
        data = copy.deepcopy(form.data)

        community_id = data.pop('identifier')
        del data['logo']

        community = Community.create(
            community_id, current_user.get_id(), **data)

        file = request.files.get('logo', None)
        if file:
            if not community.save_logo(file.stream, file.filename):
                form.logo.errors.append(_(
                    'Cannot add this file as a logo. Supported formats: '
                    'PNG, JPG and SVG. Max file size: 1.5 MB.'))
                db.session.rollback()
                community = None

        if community:
            permissions = _get_permissions()
            for permission in permissions:
                db.session.add(ActionUsers(action=permission,
                               user=current_user,
                               argument=community_id))
            db.session.commit()
            flash("{} was successfully created.".format(
                    current_app.config["COMMUNITIES_NAME"].capitalize()),
                  category='success')
            return redirect(url_for('.edit', community_id=community.id))

    return render_template(
        "/invenio_communities/new.html",
        community_form=form,
        **ctx
    )
Exemplo n.º 14
0
def new():
    """Create a new community."""
    form = CommunityForm(request.values)

    ctx = mycommunities_ctx()
    ctx.update({
        'form': form,
        'is_new': True,
        'community': None,
    })

    if form.validate_on_submit():
        data = copy.deepcopy(form.data)

        community_id = data.pop('identifier')
        del data['logo']

        community = Community.create(community_id, current_user.get_id(),
                                     **data)

        file = request.files.get('logo', None)
        if file:
            if not community.save_logo(file.stream, file.filename):
                form.logo.errors.append(
                    _('Cannot add this file as a logo. Supported formats: '
                      '  png and jpg. Max file size: 1.5MB.'))
                db.session.rollback()
                community = None

        if community:
            db.session.commit()
            flash("Community was successfully created.", category='success')
            return redirect(url_for('.edit', community_id=community.id))

    return render_template("/invenio_communities/new.html",
                           community_form=form,
                           **ctx)
Exemplo n.º 15
0
def test_oai_set_correspondence(db, users, oai_communities, oai_sets,
                                missing_oai_set, missing_community):
    for c in oai_communities:
        with db.session.begin_nested():
            new_comm = Community.create(community_id=c, user_id=1)
        db.session.commit()

        # Delete the automatically created OAI Set id required by test case
        if new_comm.oaiset_spec not in oai_sets:
            with db.session.begin_nested():
                db.session.delete(new_comm.oaiset)
            db.session.commit()

    for s in oai_sets:
        if not OAISet.query.filter_by(spec=s).one_or_none():
            with db.session.begin_nested():
                db.session.add(OAISet(spec=s))
            db.session.commit()
    check = OAICorrespondenceCheck()
    check.perform()

    assert set(check.issues.get('missing_oai_set', [])) == set(missing_oai_set)
    assert set(check.issues.get('missing_community', [])) == \
        set(missing_community)
Exemplo n.º 16
0
def test_oai_set_correspondence(db, users, oai_communities, oai_sets,
                                missing_oai_set, missing_community):
    for c in oai_communities:
        with db.session.begin_nested():
            new_comm = Community.create(community_id=c, user_id=1)
        db.session.commit()

        # Delete the automatically created OAI Set id required by test case
        if new_comm.oaiset_spec not in oai_sets:
            with db.session.begin_nested():
                db.session.delete(new_comm.oaiset)
            db.session.commit()

    for s in oai_sets:
        if not OAISet.query.filter_by(spec=s).one_or_none():
            with db.session.begin_nested():
                db.session.add(OAISet(spec=s))
            db.session.commit()
    check = OAICorrespondenceCheck()
    check.perform()

    assert set(check.issues.get('missing_oai_set', [])) == set(missing_oai_set)
    assert set(check.issues.get('missing_community', [])) == \
        set(missing_community)
Exemplo n.º 17
0
def new():
    """Create a new community."""
    form = CommunityForm(formdata=request.values)

    ctx = mycommunities_ctx()
    ctx.update({
        'form': form,
        'is_new': True,
        'community': None,
    })

    if form.validate_on_submit():

        data = copy.deepcopy(form.data)

        community_id = data.pop('identifier')

        root_index_id = data.pop('index_checked_nodeId')

        del data['logo']

        community = Community.create(community_id, current_user.get_id(),
                                     root_index_id, **data)

        # Default color
        community.color_bg1 = request.form.get('color_bg1', '#ffffff')
        community.color_bg2 = request.form.get('color_bg2', '#ffffff')
        community.color_frame = request.form.get('color_frame', '#dddddd')
        community.color_header = request.form.get('color_header', '#0d5f89')
        community.color_footer = request.form.get('color_footer', '#0d5f89')

        # Create scss
        fn = community_id + '.scss'
        scss_file = os.path.join(current_app.static_folder,
                                 'scss/invenio_communities/communities/' + fn)
        # Write scss
        lines = []
        lines.append('$' + community_id + '-community-body-bg: ' +
                     community.color_bg1 + ';')
        lines.append('$' + community_id + '-community-panel-bg: ' +
                     community.color_bg2 + ';')
        lines.append('$' + community_id + '-community-panel-border: ' +
                     community.color_frame + ';')
        lines.append('$' + community_id + '-community-header-bg: ' +
                     community.color_header + ';')
        lines.append('$' + community_id + '-community-footer-bg: ' +
                     community.color_footer + ';')

        lines.append('.communities {.' + community.id +
                     '-body {background-color: $' + community_id +
                     '-community-body-bg;}}')
        lines.append('.communities {.' + community.id +
                     '-panel {background-color: $' + community_id +
                     '-community-panel-bg;}}')
        lines.append('.communities {.' + community.id +
                     '-panel {border-color: $' + community_id +
                     '-community-panel-border;}}')
        lines.append('.communities {.' + community.id +
                     '-header {background-color: $' + community_id +
                     '-community-header-bg;}}')
        lines.append('.communities {.' + community.id +
                     '-footer {background-color: $' + community_id +
                     '-community-footer-bg;}}')

        with open(scss_file, 'w', encoding='utf-8') as fp:
            fp.writelines('\n'.join(lines))

        # Add to variables
        var_file = os.path.join(current_app.static_folder,
                                'scss/invenio_communities/variables.scss')
        with open(var_file, 'a', encoding='utf-8') as fp:
            str = '@import "communities/' + community_id + '";'
            fp.writelines(str + '\n')

        file = request.files.get('logo', None)
        if file:
            if not community.save_logo(file.stream, file.filename):
                form.logo.errors.append(
                    _('Cannot add this file as a logo. Supported formats: '
                      'PNG, JPG and SVG. Max file size: 1.5 MB.'))
                db.session.rollback()
                community = None

        if community:
            db.session.commit()
            flash("Community was successfully created.", category='success')
            return redirect(url_for('.edit', community_id=community.id))

    return render_template(current_app.config['COMMUNITIES_NEW_TEMPLATE'],
                           community_form=form,
                           **ctx)