metadata_registration_api package¶
Subpackages¶
- metadata_registration_api.api package
- Submodules
- metadata_registration_api.api.api_ctrl_voc module
- metadata_registration_api.api.api_form module
- metadata_registration_api.api.api_props module
- metadata_registration_api.api.api_study module
- metadata_registration_api.api.api_user module
- metadata_registration_api.api.api_utils module
- metadata_registration_api.api.decorators module
- Module contents
Submodules¶
metadata_registration_api.app module¶
-
metadata_registration_api.app.clear_environmental_variables()¶
-
metadata_registration_api.app.config_app(app, credentials)¶
-
metadata_registration_api.app.create_app(config='DEVELOPMENT')¶
metadata_registration_api.errors module¶
-
exception
metadata_registration_api.errors.ApiBaseException¶ Bases:
Exception
-
exception
metadata_registration_api.errors.IdenticalPropertyException¶
-
exception
metadata_registration_api.errors.RequestBodyException¶
-
exception
metadata_registration_api.errors.TokenException¶
metadata_registration_api.model module¶
-
class
metadata_registration_api.model.ControlledVocabulary(*args, **values)¶ Bases:
metadata_registration_api.model.TopLevelDocumentModel for a controlled vocabulary.
A controlled vocabulary contains a list of possible items. See
Property.-
exception
DoesNotExist¶ Bases:
mongoengine.errors.DoesNotExist
-
exception
MultipleObjectsReturned¶ Bases:
mongoengine.errors.MultipleObjectsReturned
-
description¶ A unicode string field.
-
id¶ A field wrapper around MongoDB’s ObjectIds.
-
items¶ A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.
If using with ReferenceFields see: one-to-many-with-listfields
Note
Required means it cannot be empty - as the default for ListFields is []
-
objects¶ The default QuerySet Manager.
Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a
Documentclass as its first argument, and aQuerySetas its second argument.The method function should return a
QuerySet, probably the same one that was passed in, but modified in some way.
-
exception
-
class
metadata_registration_api.model.CvItem(*args, **kwargs)¶ Bases:
mongoengine.document.EmbeddedDocumentAn item in the list of controlled vocabularies
-
description¶ A unicode string field.
-
label¶ A unicode string field.
-
name¶ A unicode string field.
-
synonyms¶ A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.
If using with ReferenceFields see: one-to-many-with-listfields
Note
Required means it cannot be empty - as the default for ListFields is []
-
-
class
metadata_registration_api.model.DataObject(*args, **kwargs)¶ Bases:
mongoengine.document.EmbeddedDocument-
args¶ A dictionary field that wraps a standard Python dictionary. This is similar to an embedded document, but the structure is not defined.
Note
Required means it cannot be empty - as the default for DictFields is {}
New in version 0.3.
Changed in version 0.5: - Can now handle complex / varying types of data
-
class_name¶ A unicode string field.
-
fields¶ A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.
If using with ReferenceFields see: one-to-many-with-listfields
Note
Required means it cannot be empty - as the default for ListFields is []
-
kwargs¶ A dictionary field that wraps a standard Python dictionary. This is similar to an embedded document, but the structure is not defined.
Note
Required means it cannot be empty - as the default for DictFields is {}
New in version 0.3.
Changed in version 0.5: - Can now handle complex / varying types of data
-
property¶ A reference to a document that will be automatically dereferenced on access (lazily).
Note this means you will get a database I/O access everytime you access this field. This is necessary because the field returns a
Documentwhich precise type can depend of the value of the _cls field present in the document in database. In short, using this type of field can lead to poor performances (especially if you access this field only to retrieve it pk field which is already known before dereference). To solve this you should consider using theLazyReferenceField.Use the reverse_delete_rule to handle what should happen if the document the field is referencing is deleted. EmbeddedDocuments, DictFields and MapFields does not support reverse_delete_rule and an InvalidDocumentError will be raised if trying to set on one of these Document / Field types.
The options are:
DO_NOTHING (0) - don’t do anything (default).
NULLIFY (1) - Updates the reference to null.
CASCADE (2) - Deletes the documents associated with the reference.
DENY (3) - Prevent the deletion of the reference object.
PULL (4) - Pull the reference from a
ListFieldof references
Alternative syntax for registering delete rules (useful when implementing bi-directional delete rules)
class Org(Document): owner = ReferenceField('User') class User(Document): org = ReferenceField('Org', reverse_delete_rule=CASCADE) User.register_delete_rule(Org, 'owner', DENY)
Changed in version 0.5: added reverse_delete_rule
-
-
class
metadata_registration_api.model.DataObjects(*args, **kwargs)¶ Bases:
mongoengine.document.EmbeddedDocument-
objects¶ A
ListFielddesigned specially to hold a list of embedded documents to provide additional query helpers.Note
The only valid list values are subclasses of
EmbeddedDocument.New in version 0.9.
-
-
class
metadata_registration_api.model.Form(*args, **values)¶ Bases:
metadata_registration_api.model.TopLevelDocumentMongoDB representation of a FlaskForm
The form contains multiple fields.
-
exception
DoesNotExist¶ Bases:
mongoengine.errors.DoesNotExist
-
exception
MultipleObjectsReturned¶ Bases:
mongoengine.errors.MultipleObjectsReturned
-
description¶ A unicode string field.
-
fields¶ A
ListFielddesigned specially to hold a list of embedded documents to provide additional query helpers.Note
The only valid list values are subclasses of
EmbeddedDocument.New in version 0.9.
-
id¶ A field wrapper around MongoDB’s ObjectIds.
-
objects¶ The default QuerySet Manager.
Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a
Documentclass as its first argument, and aQuerySetas its second argument.The method function should return a
QuerySet, probably the same one that was passed in, but modified in some way.
-
exception
-
class
metadata_registration_api.model.FormField(*args, **kwargs)¶ Bases:
mongoengine.document.EmbeddedDocument-
args¶ A generic embedded document field - allows any
EmbeddedDocumentto be stored.Only valid values are subclasses of
EmbeddedDocument.Note
You can use the choices param to limit the acceptable EmbeddedDocument types
-
class_name¶ A unicode string field.
-
clean()¶ Hook for doing document level data cleaning before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
-
description¶ A unicode string field.
-
fields¶ A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.
If using with ReferenceFields see: one-to-many-with-listfields
Note
Required means it cannot be empty - as the default for ListFields is []
-
kwargs¶ A dictionary field that wraps a standard Python dictionary. This is similar to an embedded document, but the structure is not defined.
Note
Required means it cannot be empty - as the default for DictFields is {}
New in version 0.3.
Changed in version 0.5: - Can now handle complex / varying types of data
-
label¶ A unicode string field.
-
name¶ A unicode string field.
-
property¶ A reference to a document that will be automatically dereferenced on access (lazily).
Note this means you will get a database I/O access everytime you access this field. This is necessary because the field returns a
Documentwhich precise type can depend of the value of the _cls field present in the document in database. In short, using this type of field can lead to poor performances (especially if you access this field only to retrieve it pk field which is already known before dereference). To solve this you should consider using theLazyReferenceField.Use the reverse_delete_rule to handle what should happen if the document the field is referencing is deleted. EmbeddedDocuments, DictFields and MapFields does not support reverse_delete_rule and an InvalidDocumentError will be raised if trying to set on one of these Document / Field types.
The options are:
DO_NOTHING (0) - don’t do anything (default).
NULLIFY (1) - Updates the reference to null.
CASCADE (2) - Deletes the documents associated with the reference.
DENY (3) - Prevent the deletion of the reference object.
PULL (4) - Pull the reference from a
ListFieldof references
Alternative syntax for registering delete rules (useful when implementing bi-directional delete rules)
class Org(Document): owner = ReferenceField('User') class User(Document): org = ReferenceField('Org', reverse_delete_rule=CASCADE) User.register_delete_rule(Org, 'owner', DENY)
Changed in version 0.5: added reverse_delete_rule
-
-
class
metadata_registration_api.model.History(*args, **kwargs)¶ Bases:
mongoengine.document.EmbeddedDocument-
action¶ A unicode string field.
-
manual_user¶ A unicode string field.
-
timestamp¶ Datetime field.
Uses the python-dateutil library if available alternatively use time.strptime to parse the dates. Note: python-dateutil’s parser is fully featured and when installed you can utilise it to convert varying types of date formats into valid python datetime objects.
Note: To default the field to the current datetime, use: DateTimeField(default=datetime.utcnow)
- Note: Microseconds are rounded to the nearest millisecond.
Pre UTC microsecond support is effectively broken. Use
ComplexDateTimeFieldif you need accurate microsecond support.
-
user_id¶ A reference to a document that will be automatically dereferenced on access (lazily).
Note this means you will get a database I/O access everytime you access this field. This is necessary because the field returns a
Documentwhich precise type can depend of the value of the _cls field present in the document in database. In short, using this type of field can lead to poor performances (especially if you access this field only to retrieve it pk field which is already known before dereference). To solve this you should consider using theLazyReferenceField.Use the reverse_delete_rule to handle what should happen if the document the field is referencing is deleted. EmbeddedDocuments, DictFields and MapFields does not support reverse_delete_rule and an InvalidDocumentError will be raised if trying to set on one of these Document / Field types.
The options are:
DO_NOTHING (0) - don’t do anything (default).
NULLIFY (1) - Updates the reference to null.
CASCADE (2) - Deletes the documents associated with the reference.
DENY (3) - Prevent the deletion of the reference object.
PULL (4) - Pull the reference from a
ListFieldof references
Alternative syntax for registering delete rules (useful when implementing bi-directional delete rules)
class Org(Document): owner = ReferenceField('User') class User(Document): org = ReferenceField('Org', reverse_delete_rule=CASCADE) User.register_delete_rule(Org, 'owner', DENY)
Changed in version 0.5: added reverse_delete_rule
-
-
class
metadata_registration_api.model.MetaInformation(*args, **kwargs)¶ Bases:
mongoengine.document.EmbeddedDocument-
change_log¶ A
ListFielddesigned specially to hold a list of embedded documents to provide additional query helpers.Note
The only valid list values are subclasses of
EmbeddedDocument.New in version 0.9.
-
deprecated¶ Boolean field type.
New in version 0.1.2.
-
state¶ A unicode string field.
-
-
class
metadata_registration_api.model.Property(*args, **values)¶ Bases:
metadata_registration_api.model.TopLevelDocumentModel for a property
A property is assigned to a level.
-
exception
DoesNotExist¶ Bases:
mongoengine.errors.DoesNotExist
-
exception
MultipleObjectsReturned¶ Bases:
mongoengine.errors.MultipleObjectsReturned
-
clean()¶ Hook for doing document level data cleaning before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
-
description¶ A unicode string field.
-
id¶ A field wrapper around MongoDB’s ObjectIds.
-
level¶ A unicode string field.
-
objects¶ The default QuerySet Manager.
Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a
Documentclass as its first argument, and aQuerySetas its second argument.The method function should return a
QuerySet, probably the same one that was passed in, but modified in some way.
-
synonyms¶ A list field that wraps a standard field, allowing multiple instances of the field to be used as a list in the database.
If using with ReferenceFields see: one-to-many-with-listfields
Note
Required means it cannot be empty - as the default for ListFields is []
-
value_type¶ An embedded document field - with a declared document_type. Only valid values are subclasses of
EmbeddedDocument.
-
exception
-
class
metadata_registration_api.model.Study(*args, **values)¶ Bases:
mongoengine.document.Document-
exception
DoesNotExist¶ Bases:
mongoengine.errors.DoesNotExist
-
exception
MultipleObjectsReturned¶ Bases:
mongoengine.errors.MultipleObjectsReturned
-
entries¶ A
ListFielddesigned specially to hold a list of embedded documents to provide additional query helpers.Note
The only valid list values are subclasses of
EmbeddedDocument.New in version 0.9.
-
id¶ A field wrapper around MongoDB’s ObjectIds.
-
meta_information¶ An embedded document field - with a declared document_type. Only valid values are subclasses of
EmbeddedDocument.
-
objects¶ The default QuerySet Manager.
Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a
Documentclass as its first argument, and aQuerySetas its second argument.The method function should return a
QuerySet, probably the same one that was passed in, but modified in some way.
-
exception
-
class
metadata_registration_api.model.StudyEntry(*args, **kwargs)¶ Bases:
mongoengine.document.EmbeddedDocument-
property¶ A reference to a document that will be automatically dereferenced on access (lazily).
Note this means you will get a database I/O access everytime you access this field. This is necessary because the field returns a
Documentwhich precise type can depend of the value of the _cls field present in the document in database. In short, using this type of field can lead to poor performances (especially if you access this field only to retrieve it pk field which is already known before dereference). To solve this you should consider using theLazyReferenceField.Use the reverse_delete_rule to handle what should happen if the document the field is referencing is deleted. EmbeddedDocuments, DictFields and MapFields does not support reverse_delete_rule and an InvalidDocumentError will be raised if trying to set on one of these Document / Field types.
The options are:
DO_NOTHING (0) - don’t do anything (default).
NULLIFY (1) - Updates the reference to null.
CASCADE (2) - Deletes the documents associated with the reference.
DENY (3) - Prevent the deletion of the reference object.
PULL (4) - Pull the reference from a
ListFieldof references
Alternative syntax for registering delete rules (useful when implementing bi-directional delete rules)
class Org(Document): owner = ReferenceField('User') class User(Document): org = ReferenceField('Org', reverse_delete_rule=CASCADE) User.register_delete_rule(Org, 'owner', DENY)
Changed in version 0.5: added reverse_delete_rule
-
value¶ A truly dynamic field type capable of handling different and varying types of data.
Used by
DynamicDocumentto handle dynamic data
-
-
class
metadata_registration_api.model.TopLevelDocument(*args, **values)¶ Bases:
mongoengine.document.DocumentBase class for all top level documents
All top level documents have a label, a name and a deprecated flag. The label is for displaying to the end user (external representation) and the name is used by the machine (internal representation). The name is expected to be unique for the model. To ensures that the name is converted to snake case before it is inserted into the database. The deprecated flag indicates if a document is no longer needed (alternative to delete it)
-
clean()¶ Hook for doing document level data cleaning before validation is run.
Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.
-
deprecated¶ Boolean field type.
New in version 0.1.2.
-
label¶ A unicode string field.
-
name¶ A unicode string field.
-
-
class
metadata_registration_api.model.User(*args, **values)¶ Bases:
mongoengine.document.Document-
exception
DoesNotExist¶ Bases:
mongoengine.errors.DoesNotExist
-
exception
MultipleObjectsReturned¶ Bases:
mongoengine.errors.MultipleObjectsReturned
-
clean()¶ Called before data is inserted into the database
-
email¶ A field that validates input as an email address.
New in version 0.4.
-
firstname¶ A unicode string field.
-
id¶ A field wrapper around MongoDB’s ObjectIds.
-
is_active¶ Boolean field type.
New in version 0.1.2.
-
lastname¶ A unicode string field.
-
objects¶ The default QuerySet Manager.
Custom QuerySet Manager functions can extend this class and users can add extra queryset functionality. Any custom manager methods must accept a
Documentclass as its first argument, and aQuerySetas its second argument.The method function should return a
QuerySet, probably the same one that was passed in, but modified in some way.
-
password¶ A unicode string field.
-
exception
-
class
metadata_registration_api.model.VocabularyType(*args, **kwargs)¶ Bases:
mongoengine.document.EmbeddedDocumentModel which defines the allowed vocabulary.
It is used to validate user input. If the data type is ctrl_voc, only the items of
ControlledVocabularyare allowed.-
controlled_vocabulary¶ A reference to a document that will be automatically dereferenced on access (lazily).
Note this means you will get a database I/O access everytime you access this field. This is necessary because the field returns a
Documentwhich precise type can depend of the value of the _cls field present in the document in database. In short, using this type of field can lead to poor performances (especially if you access this field only to retrieve it pk field which is already known before dereference). To solve this you should consider using theLazyReferenceField.Use the reverse_delete_rule to handle what should happen if the document the field is referencing is deleted. EmbeddedDocuments, DictFields and MapFields does not support reverse_delete_rule and an InvalidDocumentError will be raised if trying to set on one of these Document / Field types.
The options are:
DO_NOTHING (0) - don’t do anything (default).
NULLIFY (1) - Updates the reference to null.
CASCADE (2) - Deletes the documents associated with the reference.
DENY (3) - Prevent the deletion of the reference object.
PULL (4) - Pull the reference from a
ListFieldof references
Alternative syntax for registering delete rules (useful when implementing bi-directional delete rules)
class Org(Document): owner = ReferenceField('User') class User(Document): org = ReferenceField('Org', reverse_delete_rule=CASCADE) User.register_delete_rule(Org, 'owner', DENY)
Changed in version 0.5: added reverse_delete_rule
-
data_type¶ A unicode string field.
-
-
metadata_registration_api.model.to_snake_case(name)¶ Convert a string into an internal representation (no leading and trailing whitespace, and intermediate whitespace replaced with underscore)
- Parameters
name – a given name
- Returns
name in snake_case or None
metadata_registration_api.my_utils module¶
-
metadata_registration_api.my_utils.load_credentials(filename='.credentials.yaml')¶ ” Load credential from file.
-
metadata_registration_api.my_utils.map_key_value(url, key='id', value='name')¶ Call API at url endpoint and create a dict which maps key to value
If the response contains identical keys, only the last value is stored for this key. The mapping only works for fields in the top level (no nested fields).
- Parameters
url (str) – API endpoint to call
key (str) – The key by which the value will be found
value (str) – The value to which the key will map
… :return: A dict with maps key -> value :rtype: dict