33 lines
801 B
Python
33 lines
801 B
Python
def chunk_list(lst, n) -> list:
|
|
for i in range(0, len(lst), n):
|
|
yield lst[i:i + n]
|
|
|
|
|
|
def compile_query_to_plain_sql(query) -> str:
|
|
return query.compile(compile_kwargs={
|
|
'literal_binds': True
|
|
})
|
|
|
|
|
|
def to_locale_number(value):
|
|
return '{:,}'.format(value).replace(',', ' ')
|
|
|
|
|
|
def previous_current_next(iterable):
|
|
"""Make an iterator that yields a (previous, current, next) tuple per element.
|
|
|
|
Returns None if the value does not make sense (i.e. previous before
|
|
first and next after last).
|
|
"""
|
|
iterable = iter(iterable)
|
|
prv = None
|
|
cur = next(iterable)
|
|
try:
|
|
while True:
|
|
nxt = next(iterable)
|
|
yield prv, cur, nxt
|
|
prv = cur
|
|
cur = nxt
|
|
except StopIteration:
|
|
yield prv, cur, None
|