apis_core.utils package
Submodules
apis_core.utils.DateParser module
- apis_core.utils.DateParser.get_date_help_text_from_dates(single_date, single_start_date, single_end_date, single_date_written)[source]
function for creating string help text from parsed dates, to provide feedback to the user about the parsing status of a given date field.
- Parameters:
single_date – datetime : the individual date point
single_start_date – datetime : the start range of a date
single_end_date – datetime : the endrange of a date
single_date_written – str : the textual user entry of a date field (needed to check if empty or not)
- Return help_text:
str : The text to be displayed underneath a date field, informing the user about the parsing result
- apis_core.utils.DateParser.parse_date(date_string: str) -> (<class 'datetime.datetime'>, <class 'datetime.datetime'>, <class 'datetime.datetime'>)[source]
function to parse a string date field of an entity
- :param date_stringstr :
the field value passed by a user
- :return date_singledatetime :
single date which represents either the precise date given by user or median in between a range.
- :return date_abdatetime :
starting date of a range if user passed a range value either implicit or explicit.
- :return date_bisdatetime :
ending date of a range if user passed a range value either implicit or explicit.
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>”
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 = []
- 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.
- 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.
- 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
- 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.
apis_core.utils.filters module
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_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.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.normalize module
apis_core.utils.rdf module
- apis_core.utils.rdf.get_definition_and_attributes_from_uri(uri: str, model: object) Tuple[dict, dict] [source]
This function looks for .toml files in the rdfimport app directories and loads all the files it can parse. For every file that contains a superclass key it checks if it is a superclass of model. It uses the first file that matches to extract attributes from the RDF endpoint and then returns both the parsed file contents and the extracted attributes. The reason we are also returning the parsed file contents is, that you then can define a model in the file and then use this function to iterate over a list of URIs and you can use the matched definition to choose which model to create. The dict containing the parsed file contents also contains the filename, to make debugging a bit easier.
apis_core.utils.settings module
apis_core.utils.test_DateParser module
apis_core.utils.test_helpers module
apis_core.utils.test_normalize module
apis_core.utils.test_rdf module
- class apis_core.utils.test_rdf.Institution(id, label)[source]
Bases:
E74_Group
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- label
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- class apis_core.utils.test_rdf.Person(id, forename, surname, gender, date_of_birth, date_of_death)[source]
Bases:
E21_Person
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- date_of_birth
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- date_of_death
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- forename
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- gender
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- surname
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- class apis_core.utils.test_rdf.Place(id, label, longitude, latitude)[source]
Bases:
E53_Place
- exception DoesNotExist
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Bases:
MultipleObjectsReturned
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- label
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- latitude
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- longitude
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>