Skip to content

Commit

Permalink
cli: replaces invenio records by invenio fixtures
Browse files Browse the repository at this point in the history
* Adds a new cli to manuipulate records.

Co-Authored-by: Aly Badr [email protected]
Co-Authored-by: Peter Weber [email protected]
  • Loading branch information
Aly Badr committed Aug 5, 2019
1 parent 56111da commit a3e40c5
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 93 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ invenio-oaiserver = ">=1.0.3,<1.1.0"
invenio-pidstore = ">=1.0.0,<1.1.0"
invenio-records-rest = ">=1.4.0,<1.5.0"
invenio-records-ui = ">=1.0.1,<1.1.0"
invenio-records = ">=1.2.0"
invenio-records = ">=1.3.0"
Werkzeug = ">=0.15"
# TODO: to be removed
angular-gettext-babel= ">=0.1"
Expand Down
173 changes: 89 additions & 84 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions rero_ils/modules/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from invenio_accounts.cli import commit, users
from invenio_pidstore.models import PersistentIdentifier
from invenio_records.api import Record
from invenio_records_rest.utils import obj_or_import_string
from invenio_search.cli import es_version_check
from invenio_search.proxies import current_search, current_search_client
from werkzeug.local import LocalProxy
Expand Down Expand Up @@ -183,3 +184,35 @@ def init(force):
length=current_search.number_of_indexes) as bar:
for name, response in bar:
bar.label = name


@click.command('create')
@click.option('-v', '--verbose', 'verbose', is_flag=True, default=True)
@click.option('-c', '--dbcommit', 'dbcommit', is_flag=True, default=True)
@click.option('-r', '--reindex', 'reindex', is_flag=True, default=False)
@click.option('--pid_type', default=None)
@click.argument('infile', type=click.File('r'), default=sys.stdin)
@with_appcontext
def create(infile, pid_type, verbose, dbcommit, reindex):
"""Load REROILS record.
infile: Json file
reindex: reindex record by record
dbcommit: commit record to database
pid_type: record type
"""
click.secho('Loading "%s" records.' % pid_type, fg='green')
record_class = obj_or_import_string(
current_app.config
.get('RECORDS_REST_ENDPOINTS')
.get(pid_type).get('record_class', Record))
data = json.load(infile)
for record in data:
rec = record_class.create(record, dbcommit=dbcommit, reindex=reindex)
if verbose:
click.echo(
'{pid_type} created {id}'.format(pid_type=pid_type, id=rec.id)
)


fixtures.add_command(create)
Loading

0 comments on commit a3e40c5

Please sign in to comment.