def load_community(data, logos_dir):
    """Load community from data dump.

    :param data: Dictionary containing community data.
    :type data: dict
    :param logos_dir: Path to a local directory with community logos.
    :type logos_dir: str
    """
    from invenio_communities.models import Community
    from invenio_communities.utils import save_and_validate_logo
    logo_ext_washed = logo_ext_wash(data['logo_ext'])
    c = Community(
        id=data['id'],
        id_user=data['id_user'],
        title=data['title'],
        description=data['description'],
        page=data['page'],
        curation_policy=data['curation_policy'],
        last_record_accepted=iso2dt_or_none(data['last_record_accepted']),
        logo_ext=logo_ext_washed,
        ranking=data['ranking'],
        fixed_points=data['fixed_points'],
        created=iso2dt(data['created']),
        updated=iso2dt(data['last_modified']),
    )
    logo_path = join(logos_dir, "{0}.{1}".format(c.id, logo_ext_washed))
    db.session.add(c)
    if isfile(logo_path):
        with open(logo_path, 'rb') as fp:
            save_and_validate_logo(fp, logo_path, c.id)
    db.session.commit()
Example #2
0
def load_community(data, logos_dir):
    """Load community from data dump.

    :param data: Dictionary containing community data.
    :type data: dict
    :param logos_dir: Path to a local directory with community logos.
    :type logos_dir: str
    """
    from invenio_communities.models import Community
    from invenio_communities.utils import save_and_validate_logo
    logo_ext_washed = logo_ext_wash(data['logo_ext'])
    c = Community(
        id=data['id'],
        id_user=data['id_user'],
        title=data['title'],
        description=data['description'],
        page=data['page'],
        curation_policy=data['curation_policy'],
        last_record_accepted=iso2dt_or_none(data['last_record_accepted']),
        logo_ext=logo_ext_washed,
        ranking=data['ranking'],
        fixed_points=data['fixed_points'],
        created=iso2dt(data['created']),
        updated=iso2dt(data['last_modified']),
    )
    logo_path = join(logos_dir, "{0}.{1}".format(c.id, logo_ext_washed))
    db.session.add(c)
    if isfile(logo_path):
        with open(logo_path, 'rb') as fp:
            save_and_validate_logo(fp, logo_path, c.id)
    db.session.commit()
Example #3
0
def load_communities_logos(logos_dir):
    """Load communities."""
    from invenio_communities.models import Community
    from invenio_communities.utils import save_and_validate_logo
    from os.path import join, isfile
    for c in Community.query.all():
        logo_path = join(logos_dir, "{0}.{1}".format(c.id, c.logo_ext))
        if isfile(logo_path):
            with open(logo_path, 'rb') as fp:
                save_and_validate_logo(fp, logo_path, c.id)
    db.session.commit()
Example #4
0
def load_communities_logos(logos_dir):
    """Load communities."""
    from invenio_communities.models import Community
    from invenio_communities.utils import save_and_validate_logo
    from os.path import join, isfile
    for c in Community.query.all():
        logo_path = join(logos_dir, "{0}.{1}".format(c.id, c.logo_ext))
        if isfile(logo_path):
            with open(logo_path, 'rb') as fp:
                save_and_validate_logo(fp, logo_path, c.id)
    db.session.commit()
Example #5
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()
Example #6
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()