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>”
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