apis_core.utils package

Submodules

apis_core.utils.authentication module

class apis_core.utils.authentication.TokenAuthSupportQueryString[source]

Bases: TokenAuthentication

Extend the TokenAuthentication class to support querystring authentication in the form of “http://www.example.com/?auth_token=<api_key>”

authenticate(request)[source]

Authenticate the request and return a two-tuple of (user, token).

apis_core.utils.autocomplete module

class apis_core.utils.autocomplete.ExternalAutocomplete[source]

Bases: object

This is a helper base class for implementing external autocomplete classes. <Modelname>ExernalAutocomplete classes are expected to have a get_results(self, q) method that returns a list of results usable by the autocomplete view. This base class implements this get_results method in a way that you can inherit from it and just define a list of adapters. Those adapters are then used one by one to add external autocomplete search results.

adapters = []
get_results(q)[source]
session = <requests.sessions.Session object>
class apis_core.utils.autocomplete.ExternalAutocompleteAdapter(*args, **kwargs)[source]

Bases: object

Base class for ExternalAutocompleteAdapters. It provides the methods used for templating the autocomplete results. You can pass a template name to initialization, which is then used to style the results.

default_template(result)[source]
get_result_label(result)[source]
template = None
class apis_core.utils.autocomplete.LobidAutocompleteAdapter(*args, **kwargs)[source]

Bases: ExternalAutocompleteAdapter

This autocomplete adapters queries the lobid autocomplete apis. See https://lobid.org/gnd/api for details You can pass a lobid_params dict which will then be use as GET request parameters.

extract(res)[source]
get_results(q, session=<requests.sessions.Session object>)[source]
params = {}
class apis_core.utils.autocomplete.TypeSenseAutocompleteAdapter(*args, **kwargs)[source]

Bases: ExternalAutocompleteAdapter

This autocomplete adapters queries typesense collections on a typesense server. The collections variable can either be a string or a list - if its a string, that collection is queried directly, if its a list, the adapter uses typesense multi_search endpoint.

collections = None
default_template(result)[source]
extract(res)[source]
get_results(q, session=<requests.sessions.Session object>)[source]
server = None
token = None

apis_core.utils.fields module

class apis_core.utils.fields.NewlineSeparatedListField(*args, db_collation=None, **kwargs)[source]

Bases: TextField

This field is basically a textfield with a custom widget. It uses the NewlineSeparatedListWidget to provide a simply way for users to enter multiple values without having to think about the separator.

formfield(form_class=None, choices_form_class=None, **kwargs)[source]

Return a django.forms.Field instance for this field.

apis_core.utils.filters module

class apis_core.utils.filters.CustomSearchFilter[source]

Bases: SearchFilter

filter_queryset(request, queryset, view)[source]

Return a filtered queryset.

to_html(request, queryset, view)[source]

apis_core.utils.helpers module

apis_core.utils.helpers.construct_lookup(value: str) tuple[str, str][source]

Helper method to parse input values and construct field lookups (https://docs.djangoproject.com/en/4.2/ref/models/querysets/#field-lookups) Parses user input for wildcards and returns a tuple containing the interpreted django lookup string and the trimmed value E.g.

  • example -> ('__icontains', 'example')

  • *example* -> ('__icontains', 'example')

  • *example -> ('__iendswith', 'example')

  • example*-> ('__istartswith', 'example')

  • "example" -> ('__iexact', 'example')

Parameters:

value (str) – text to be parsed for *

Returns:

a tuple containing the lookup type and the value without modifiers

apis_core.utils.helpers.create_object_from_uri(uri: str, model: object, raise_on_fail=False) object[source]
apis_core.utils.helpers.datadump_get_objects(models: list = [], *args, **kwargs)[source]
apis_core.utils.helpers.datadump_get_queryset(additional_app_labels: list = [])[source]

This method is loosely based on the dumpdata admin command. It iterates throug the relevant app models and exports them using a serializer and natural foreign keys. Data exported this way can be reimported into a newly created Django APIS app

apis_core.utils.helpers.datadump_serializer(additional_app_labels: list = [], serialier_format='json')[source]
apis_core.utils.helpers.flatten_if_single(value: list)[source]
apis_core.utils.helpers.get_html_diff(a, b, show_a=True, show_b=True, shorten=0)[source]

Create an colorized html represenation of the difference of two values a and b If show_a is True, colorize deletions in a If show_b is True, colorize insertions in b The value of shorten defines if long parts of strings that contains no change should be shortened

apis_core.utils.helpers.get_importer_for_model(model: object)[source]

apis_core.utils.rdf module

apis_core.utils.rdf.find_matching_config(graph: Graph) dict | None[source]
apis_core.utils.rdf.get_something_from_uri(uri: str) dict | None[source]
apis_core.utils.rdf.get_value_graph(graph: Graph, curies: str | list[str]) list[source]

apis_core.utils.settings module

apis_core.utils.settings.dict_from_toml_directory(directory: str) dict[source]
apis_core.utils.settings.get_entity_settings_by_modelname(entity: str = None) dict[source]

return the settings for a specific entity or the dict for all entities if no entity is given

apis_core.utils.settings.internal_uris() list[str][source]

apis_core.utils.test_helpers module

class apis_core.utils.test_helpers.FilterMethodstest(methodName='runTest')[source]

Bases: TestCase

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_lookup()[source]

apis_core.utils.test_rdf module

class apis_core.utils.test_rdf.RdfTest(methodName='runTest')[source]

Bases: TestCase

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_get_definition_from_dict_institution_from_dnb()[source]
test_get_definition_from_dict_institution_from_dnb2()[source]
test_get_definition_from_dict_person_from_dnb()[source]
test_get_definition_from_dict_place_from_dnb()[source]
test_get_definition_from_dict_place_from_geonames()[source]