apis_core.utils.helpers#

Module Contents#

Functions#

datadump_get_objects

datadump_get_queryset

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

datadump_serializer

get_html_diff

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

construct_lookup

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.

flatten_if_single

API#

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.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.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.flatten_if_single(value: list)[source]#