You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

# -*- coding: utf-8 -*-
# © 2016 Danimar Ribeiro, Trustcode
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from __future__ import division
from builtins import str
from past.utils import old_div
from decimal import Decimal
from datetime import date
from datetime import datetime
from unicodedata import normalize
def normalize_str(string):
"""
Remove special characters and return the ascii string
"""
if string:
if not isinstance(string, str):
string = str(string, 'utf-8', 'replace')
string = string.encode('utf-8')
return normalize(
'NFKD', string.decode('utf-8')).encode('ASCII', 'ignore')
return ''
def format_percent(value):
if value:
return old_div(Decimal(value), 100)
def format_datetime(value):
"""
Format datetime
"""
dt_format = '%Y-%m-%dT%H:%M:%I'
if isinstance(value, datetime):
return value.strftime(dt_format)
return value
def format_date(value):
"""
Format date
"""
dt_format = '%Y-%m-%d'
if isinstance(value, date):
return value.strftime(dt_format)
return value