Skip to content

Instantly share code, notes, and snippets.

@lnielsen
Last active November 9, 2015 14:14
Show Gist options
  • Save lnielsen/982d3ea51d2d69983bce to your computer and use it in GitHub Desktop.
Save lnielsen/982d3ea51d2d69983bce to your computer and use it in GitHub Desktop.
mkvirtualenv invenio3test
cd ~/src
pip install invenio[full]
inveniomanage startproject mysite
cd mysite
CWD=`pwd`
python manage.py bower
cdvirtualenv var/mysite-instance/
bower install
cd $CWD
python manage.py collect -v
python manage.py assets build
python manage.py db init
python manage.py db create
# Create user
python manage.py users create -e info@inveniosoftware.org -a
# Run a celery worker (in a new window so it's running for coming commands)
celery worker -A mysite.celery -l INFO
# Create a record
echo '{"title":"Invenio 3 Rocks", "recid": 1}' | python manage.py records create
# Create a pid for the record (temporary)
python manage.py shell
from invenio_db import db
from invenio_pidstore.models import PersistentIdentifier
pid = PersistentIdentifier.create('recid', '1', 'recid')
pid.assign('rec', '1')
pid.register()
db.session.commit()
# Run the webserver
python manage.py --debug run
# UI
http://localhost:5000/records/1
# REST API
curl -i -H "Accept: application/json" http://localhost:5000/api/records/1
# Login (will redirect you to frontpage which currently returns 404)
http://localhost:5000/login
# Change password
http://localhost:5000/change
# Reset password
http://localhost:5000/reset
curl -XPOST http://localhost:5000/api/records/ -H "Content-Type:application/json" --data '{"title": "Invenio 3 Rocks"}'
curl -XPUT http://localhost:5000/api/records/1 -H "Content-Type:application/json" --data '{"title": "Invenio 3 Rocks"}'
# 500
curl -XPATCH http://localhost:5000/api/records/1 -H "Content-Type:application/json-patch+json" --data '{"op": "add", "path": "/french_title", "value": "Invenio 3 c'est de la bombe"}'
@nharraud
Copy link

nharraud commented Nov 3, 2015

can you replace the PATCH request with:

curl -XPATCH http://localhost:5000/api/records/1 -H "Content-Type:application/json-patch+json" --data '[{"op": "add", "path": "/software", "value": "Invenio"}]'

The current one has a quote issue and the json-patch is not valid (missing [ and ]).

@tiborsimko
Copy link

Works for me, except for @nharraud's PATCH that does not seem to propagate changes to the DB yet?

Here are some cosmetic observations:

  • line 3 (cd ~/src): I'd suggest to do cdvirtualenv && mkdir src && cd src
  • line 7 (CWD=...) can be deleted and line 12 (cd $CWD) can be changed to cd - that should work in most good shells (BTW note also git checkout - that I'm using at times for jumping around)
  • python manage.py shell: would be nice to start ipython if present
  • /login is OK, but /change is too generic for an endpoint name (change what? one can change so many things on an invenio installation... we should express clearly that it's related to user account password change); ditto /reset

@tiborsimko
Copy link

except for @nharraud's PATCH that does not seem to propagate changes to the DB yet?

Working now for a new test record that I created and amended. Hmm, could this have been related to the "stoppage" effect you observed in inveniosoftware/invenio#3550 (comment)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment