endi_base.utils package

Submodules

endi_base.utils.ascii module

Provide common tools for string handling

endi_base.utils.ascii.camel_case_to_name(name)

Used to convert a classname to a lowercase name

endi_base.utils.ascii.force_ascii(value)

Return enforced ascii string éko=>ko

endi_base.utils.ascii.force_filename(val)

Transform a string to a valid filename

endi_base.utils.ascii.force_string(value)

return an utf-8 str

Paramètres:

value (bytes) – The original value to convert

Type renvoyé:

str

endi_base.utils.ascii.force_unicode(value)

return an utf-8 str

Paramètres:

value (bytes) – The original value to convert

Type renvoyé:

str

endi_base.utils.ascii.force_utf8(value)

return a utf-8 byte string

Paramètres:

value (str) –

Type renvoyé:

bytes

endi_base.utils.ascii.gen_random_string(size=15)

Generate random string

size

size of the resulting string

endi_base.utils.ascii.isint(val)

Return True if the result looks like an int

endi_base.utils.ascii.random_tag_id(size=15)

Return a random string supposed to be used as tag id

endi_base.utils.ascii.to_utf8(datas)

Force utf8 string entries in the given datas

endi_base.utils.date module

Date manipulation utilities

endi_base.utils.date.format_date(date, short=True)

return a pretty print version of the date object

endi_base.utils.date.format_datetime(datetime_object, timeonly=False)

format a datetime object

endi_base.utils.date.format_duration(duration, short=True)

return a pretty print version of a duration.

Paramètres:
  • duration ((int,int)) – hours,minutes tuple to convert.

  • short (bool) – if True, hide minutes part when it equals zero.

endi_base.utils.date.format_long_date(date)

return a long printable version of the date obj

endi_base.utils.date.format_short_date(date)

return a short printable version of the date obj

endi_base.utils.date.get_strftime_from_date(date_obj, template_str)

Return the result of date.strftime(template_str) handling exceptions

endi_base.utils.date.str_to_date(str_date, formats=('%d/%m/%Y', '%d-%m-%Y', '%d/%m/%y', '%Y-%m-%d', '%Y%m%d'))

Transform a date string to a date object

Paramètres:
  • str_date (str) – The date string

  • formats (tuple) – List of date format to try when parsing

Renvoie:

A datetime object

Type renvoyé:

datetime.date

endi_base.utils.export module

endi_base.utils.export.format_boolean(value)

Format a boolean value

endi_base.utils.math module

Math utilities used for computing

endi_base.utils.math.amount(value, precision=2)

Convert a float value as an integer amount to store it in a database :param value: float value to convert :param precision: number of dot translation to make

>>> amount(195.65)
19565
endi_base.utils.math.compute_tva(total_ht, tva)

Compute the tva for the given ht total

endi_base.utils.math.convert_to_float(value, default=None)

Try to convert the given value object to a float

endi_base.utils.math.convert_to_int(value, default=None)

try to convert the given value to an int

endi_base.utils.math.dec_round(dec, precision, round_floor=False)

Return a decimal object rounded to precision

Paramètres:
  • precision (int) – the number of decimals we want after the comma

  • round_floor (bool) – Should the data be floor rounded ?

endi_base.utils.math.floor(value, round_floor=False)

floor a float value :param value: float value to be rounded :param bool round_floor: Should the data be floor rounded ? :return: an integer

>>> floor(296.9999999)
297
endi_base.utils.math.floor_to_precision(value, round_floor=False, precision=2, dialect_precision=5)
floor a value in its int representation:
>>> floor_to_precision(296999)
297000

amounts are of the form : value * 10 ** dialect_precision it allows to store dialect_precision numbers after comma for intermediary amounts for totals we want precision numbers

Paramètres:
  • value (int) – The value to floor

  • round_floor (bool) – Should be rounded down ?

  • precision (int) – How much significant numbers we want ?

  • dialect_precision (int) – The number of zeros that are concerning the

floatting part of our value

endi_base.utils.math.integer_to_amount(value, precision=2)

Convert an integer value to a float with precision numbers after comma

endi_base.utils.math.percent(part, total, default=None)

Return the percentage of total represented by part if default is provided, the ZeroDivisionError is handled

endi_base.utils.math.percentage(value, _percent)

Return the value of the « percent » percent of the original « value »

endi_base.utils.math.reverse_tva(total_ttc, tva, float_format=True)

Compute total_ht from total_ttc

Paramètres:
  • total_ttc (float) – ttc value in float format (by default)

  • tva (integer) – the tva value in integer format (tva * 100)

  • float_format (bool) – Is total_ttc in the float format (real ttc value)

Renvoie:

the value in integer format

endi_base.utils.math.round(float_, precision, round_floor=False)

Return a float object rounded to precision :param float float_: the object to round :param int precision: the number of decimals we want after the comma :param bool round_floor: Should the data be floor rounded ?

endi_base.utils.renderers module

endi_base.utils.renderers.configure_export()

Customize sqla_inspect tools

endi_base.utils.renderers.set_export_blacklist()

Globally set an export blacklist

endi_base.utils.renderers.set_export_formatters()

Globally set export formatters in the sqla_inspect registry

endi_base.utils.renderers.set_json_renderer(config)

Customize json renderer to allow datetime rendering

endi_base.utils.renderers.set_xls_formats()

Globally set the xls formats by datatype

endi_base.utils.strings module

endi_base.utils.strings.format_quantity(quantity)

format the quantity

Module contents