Django access classes for Fedora Commons 4
Installation:
cd /tmp
virtualenv testfedora-venv -p python3
. /tmp/testfedora-venv/bin/activate
pip install django
pip install git+https://github.com/mesemus/fedoralink.git
django-admin startproject testfedora
INSTALLED_APPS += [
'fedoralink'
]
DATABASES['repository'] = {
'ENGINE' : 'fedoralink.engine',
'SEARCH_ENGINE' : 'fedoralink.indexer.SOLRIndexer',
'REPO_URL' : 'http://127.0.0.1:8080/fcrepo/rest',
'SEARCH_URL' : 'http://127.0.0.1:8891/solr/collection1'
}
bash:
export DJANGO_SETTINGS_MODULE=testfedora.settings
python3
inside python:
from fedoralink.models import FedoraObject
# empty pk is the root of the repository
list(FedoraObject.objects.filter(pk=''))
INFO:fedoralink.connection:Requesting url http://127.0.0.1:8080/fcrepo/rest/
INFO:requests.packages.urllib3.connectionpool:Starting new HTTP connection (1): 127.0.0.1
[<fedoralink.type_manager.FedoraObject_bound object at 0x7f36effcf6a0>]
root = FedoraObject.objects.get(pk='')
Pass a parameter "slug" to influence the URL of the created subcollection
test = root.create_subcollection('test', slug='test')
# can set metadata here, not saved until .save() is called
test.save()
from rdflib import Literal
from rdflib.namespace import DC
test[DC.title] = (
Literal('Pokusný repozitář', lang='cs'),
Literal('Test repository', lang='en'),
)
# changes are saved after this method is called
test.save()
from fedoralink.common_namespaces.dc import DCObject
child = collection.create_child('name, will be copied to DC.title', flavour=DCObject)
child.title = 'Can use plain string as well as tuple with Literal.'
child.creator = 'ms'
child.save()
# untyped
for child in collection.children:
print("listing, child: ", child[DC.title])
# typed
for child in collection.children:
print("listing, child: ", type(child), child.title)