API Documentation¶
atramhasis.data¶
atramhasis.data.datamanagers¶
This module adds DataManagers for Atramhasis. These are service layer objects that abstract all interactions with the database away from the views.
versionadded: | 0.4.1 |
---|
-
class
atramhasis.data.datamanagers.
AuditManager
(session)[source]¶ A data manager for logging the visit.
-
get_most_popular_concepts_for_conceptscheme
(conceptscheme_id, max=5, period='last_month')[source]¶ get the most popular concepts for a conceptscheme :param conceptscheme_id: id of the conceptscheme :param max: maximum number of results, default 5 :param period: ‘last_day’ or ‘last_week’ or ‘last_month’ or ‘last_year’, default ‘last_month’ :return: List of the most popular concepts of a conceptscheme over a certain period
-
-
class
atramhasis.data.datamanagers.
ConceptSchemeManager
(session)[source]¶ A
DataManager
forConceptSchemes <skosprovider_sqlalchemy.models.ConceptScheme>.
-
find
(conceptscheme_id, query)[source]¶ Find concepts and collections in this concept scheme.
Parameters: - conceptscheme_id – a concepscheme id
- query – A python dictionary containing query parameters.
Returns: A
list
ofskosprovider_sqlalchemy.models.Thing
instances.
-
get
(conceptscheme_id)[source]¶ Parameters: conceptscheme_id – a concepscheme id Returns: the concepscheme for the given id
-
get_all
(conceptscheme_id)[source]¶ Get all concepts and collections in this concept scheme.
Parameters: conceptscheme_id – a concepscheme id Returns: A list
ofskosprovider_sqlalchemy.models.Thing
instances.
-
get_collections_for_scheme_tree
(conceptscheme_id)[source]¶ Parameters: conceptscheme_id – a concepscheme id Returns: all collections for the scheme_tree
-
-
class
atramhasis.data.datamanagers.
CountsManager
(session)[source]¶ A data manager that deals with triple counts.
-
class
atramhasis.data.datamanagers.
DataManager
(session)[source]¶ A DataManager abstracts all interactions with the database for a certain model.
-
class
atramhasis.data.datamanagers.
LanguagesManager
(session)[source]¶ A
DataManager
forLanguages <skosprovider_sqlalchemy.models.Language>.
-
class
atramhasis.data.datamanagers.
SkosManager
(session)[source]¶ A
DataManager
forConcepts and Collections <skosprovider_sqlalchemy.models.Thing>.
-
get_by_list_type
(list_type)[source]¶ Parameters: list_type – a specific list type Returns: all results for the specific list type
-
atramhasis.data.db¶
Module that sets up the datamanagers and the database connections.
-
atramhasis.data.db.
data_managers
(request)[source]¶ Generate a datamanager with a database session and register a cleanup handler.
Parameters: request (pyramid.request.Request) – The request this db session will be tied to. Returns: A dictionary containing different datamanagers
.
-
atramhasis.data.db.
includeme
(config)[source]¶ Set up SQLAlchemy.
Parameters: config (pyramid.config.Configurator) – Pyramid configuration.
atramhasis.errors¶
Module containing errors generated by Atramhasis.
-
exception
atramhasis.errors.
ConceptNotFoundException
(c_id)[source]¶ A Concept or Collection could not be found.
-
exception
atramhasis.errors.
ConceptSchemeNotFoundException
(scheme_id)[source]¶ A ConceptScheme could not be found.
-
exception
atramhasis.errors.
DbNotFoundException
(value='No database found, please check your application setup')[source]¶ Atramhasis could not find a database.
-
exception
atramhasis.errors.
LanguageNotFoundException
(scheme_id)[source]¶ A Language could not be found.
atramhasis.mappers¶
Module containing mapping functions used by Atramhasis.
-
atramhasis.mappers.
is_html
(value)[source]¶ Check if a value has html inside. Only tags checked <strong> <em> <a>.
Parameters: value – a string Returns: a boolean (True, HTML present | False, no HTML present)
-
atramhasis.mappers.
map_concept
(concept, concept_json, skos_manager)[source]¶ Map a concept from json to the database.
Parameters: - concept (skosprovider_sqlalchemy.models.Thing) – A concept or collection as known to the database.
- concept_json (dict) – A dict representing the json sent to our REST service.
- skos_manager – A skos_manager to acces db operations
Returns: The
skosprovider_sqlalchemy.models.Thing
enhanced with the information from the json object.
-
atramhasis.mappers.
map_conceptscheme
(conceptscheme, conceptscheme_json)[source]¶ Map a conceptscheme from json to the database.
Parameters: - conceptscheme (skosprovider_sqlalchemy.models.ConceptScheme) – A conceptscheme as known to the database.
- conceptscheme_json (dict) – A dict representing the json sent to our REST service.
Returns: The
skosprovider_sqlalchemy.models.ConceptScheme
enhanced with the information from the json object.
atramhasis.protected_resources¶
-
class
atramhasis.protected_resources.
ProtectedResourceEvent
(uri, request)[source]¶ Event triggered when calling a protected operation on a resource
atramhasis.routes¶
Routes for the Atramhasis views.
New in version 0.4.4.
-
atramhasis.routes.
includeme
(config)[source]¶ Setup the routing for Atramhasis.
Parameters: config (pyramid.config.Configurator) – The application config.
atramhasis.utils¶
Module containing utility functions used by Atramhasis.
-
atramhasis.utils.
from_thing
(thing)[source]¶ Map a
skosprovider_sqlalchemy.models.Thing
to askosprovider.skos.Concept
or askosprovider.skos.Collection
, depending on the type.Parameters: thing (skosprovider_sqlalchemy.models.Thing) – Thing to map. Return type: Concept
orCollection
.
-
atramhasis.utils.
internal_providers_only
(fn)[source]¶ aspect oriented way to check if provider is internal when calling the decorated function
Parameters: fn – the decorated function Returns: around advice Raises: pyramid.httpexceptions.HTTPMethodNotAllowed – when provider is not internal
atramhasis.validators¶
Module that validates incoming JSON.
-
atramhasis.validators.
broader_hierarchy_rule
(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]¶ Checks that the broader concepts of a concepts are not alreadt narrower concepts of that concept.
-
atramhasis.validators.
collection_members_unique_rule
(errors, node_location, members)[source]¶ Checks that a collection has no duplicate members.
-
atramhasis.validators.
collection_type_rule
(errors, node_location, skos_manager, conceptscheme_id, members)[source]¶ Checks that the targets of member_of are collections and not concepts.
-
atramhasis.validators.
concept_matches_rule
(errors, node_location, matches, concept_type)[source]¶ Checks that only concepts have matches.
-
atramhasis.validators.
concept_matches_unique_rule
(errors, node_location, matches)[source]¶ Checks that a concept has not duplicate matches.
This means that a concept can only have one match (no matter what the type) with another concept. We don’t allow eg. a concept that has both a broadMatch and a relatedMatch with the same concept.
-
atramhasis.validators.
concept_relations_rule
(errors, node_location, relations, concept_type)[source]¶ Checks that only concepts have narrower, broader and related relations.
-
atramhasis.validators.
concept_schema_validator
(node, cstruct)[source]¶ This validator validates an incoming concept or collection
This validator will run a list of rules against the concept or collection to see that there are no validation rules being broken.
Parameters: - node (colander.SchemaNode) – The schema that’s being used while validating.
- cstruct – The concept or collection being validated.
-
atramhasis.validators.
concept_type_rule
(errors, node_location, skos_manager, conceptscheme_id, items)[source]¶ Checks that the targets of narrower, broader and related are concepts and not collections.
-
atramhasis.validators.
conceptscheme_schema_validator
(node, cstruct)[source]¶ This validator validates the incoming conceptscheme labels
Parameters: - node (colander.SchemaNode) – The schema that’s being used while validating.
- cstruct – The conceptscheme being validated.
-
atramhasis.validators.
hierarchy_rule
(errors, node_location, skos_manager, conceptscheme_id, cstruct, property1, property2, property2_list_name, concept_type, error_message)[source]¶ Checks that the property1 of a concept are not already in property2 hierarchy
-
atramhasis.validators.
html_preparer
(value)[source]¶ Prepare the value by stripping all html except certain tags.
Parameters: value – The value to be cleaned. Return type: str
-
atramhasis.validators.
label_lang_rule
(errors, node, languages_manager, labels)[source]¶ Checks that languages of a label are valid.
Checks that they are valid IANA language tags. If the language tag was not already present in the database, it adds them.
-
atramhasis.validators.
label_type_rule
(errors, node, skos_manager, labels)[source]¶ Checks that a label has the correct type.
-
atramhasis.validators.
languagetag_checkduplicate
(node, language_tag, languages_manager, errors)[source]¶ Check that a languagetag isn’t duplicated.
-
atramhasis.validators.
languagetag_isvalid_rule
(node, language_tag, errors)[source]¶ Check that a languagetag is a valid IANA language tag.
-
atramhasis.validators.
languagetag_validator
(node, cstruct)[source]¶ This validator validates a languagetag.
The validator will check if a tag is a valid IANA language tag. The the validator is informed that this should be a new language tag, it will also check if the tag doesn’t already exist.
Parameters: - node (colander.SchemaNode) – The schema that’s being used while validating.
- cstruct – The value being validated.
-
atramhasis.validators.
max_preflabels_rule
(errors, node, labels)[source]¶ Checks that there’s only one prefLabel for a certain language.
-
atramhasis.validators.
members_hierarchy_rule
(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]¶ Checks that a collection does not have members that are in themselves already “parents” of that collection.
-
atramhasis.validators.
members_only_in_collection_rule
(errors, node, concept_type, members)[source]¶ Checks that only collections have members.
-
atramhasis.validators.
min_labels_rule
(errors, node, cstruct)[source]¶ Checks that a label or collection always has a least one label.
-
atramhasis.validators.
narrower_hierarchy_rule
(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]¶ Checks that the narrower concepts of a concept are not already broader concepts of that concept.
-
atramhasis.validators.
semantic_relations_rule
(errors, node_location, skos_manager, conceptscheme_id, members, collection_id)[source]¶ Checks that the elements in a group of concepts or collections are not the the group itself, that they actually exist and are within the same conceptscheme.
-
atramhasis.validators.
subordinate_arrays_hierarchy_rule
(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]¶ Checks that the subordinate arrays of a concept are not themselves parents of that concept.
-
atramhasis.validators.
subordinate_arrays_only_in_concept_rule
(errors, node, concept_type, subordinate_arrays)[source]¶ Checks that only a concept has subordinate arrays.
-
atramhasis.validators.
subordinate_arrays_type_rule
(errors, node_location, skos_manager, conceptscheme_id, subordinate_arrays)[source]¶ Checks that subordinate arrays are always collections.
-
atramhasis.validators.
superordinates_hierarchy_rule
(errors, node_location, skos_manager, conceptscheme_id, cstruct)[source]¶ Checks that the superordinate concepts of a collection are not themselves members of that collection.
atramhasis.views¶
atramhasis.views.views¶
-
class
atramhasis.views.views.
AtramhasisAdminView
(request)[source]¶ This object groups HTML views part of the admin user interface.
-
class
atramhasis.views.views.
AtramhasisListView
(request)[source]¶ This object groups list views part for the user interface.
atramhasis.views.crud¶
Module containing views related to the REST service.
-
class
atramhasis.views.crud.
AtramhasisCrud
(context, request)[source]¶ This object groups CRUD REST views part of the private user interface.
-
edit_conceptscheme
()[source]¶ Edit an existing concept
Raises: atramhasis.errors.ValidationError – If the provided json can’t be validated
-
atramhasis.views.exception_views¶
Module containing error views.
-
atramhasis.views.exception_views.
data_integrity
(exc, request)[source]¶ View invoked when IntegrityError was raised.
-
atramhasis.views.exception_views.
failed
(exc, request)[source]¶ View invoked when bad data was submitted to Atramhasis.
-
atramhasis.views.exception_views.
failed_not_found
(exc, request)[source]¶ View invoked when a resource could not be found.
-
atramhasis.views.exception_views.
failed_not_method_not_allowed
(exc, request)[source]¶ View invoked when a method is not allowed.
-
atramhasis.views.exception_views.
failed_skos
(exc, request)[source]¶ View invoked when Atramhasis can’t find a SKOS registry.
-
atramhasis.views.exception_views.
failed_validation
(exc, request)[source]¶ View invoked when bad data was submitted to Atramhasis.
-
atramhasis.views.exception_views.
protected
(exc, request)[source]¶ when a protected operation is called on a resource that is still referenced
View invoked when ProviderUnavailableException was raised.