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.
26 lines
818 B
26 lines
818 B
# -*- coding: utf-8 -*-
|
|
import datetime
|
|
import traceback
|
|
|
|
from django.core.mail import mail_admins
|
|
|
|
|
|
# convert datetime to json
|
|
dthandler = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime) or isinstance(obj, datetime.date) else None
|
|
|
|
|
|
def safe_int(value, default=None):
|
|
"""Возвращает value, приведенное к типу int, или default, если привести не получается."""
|
|
try:
|
|
return int(value)
|
|
except:
|
|
return default
|
|
|
|
|
|
def only_numerics(value):
|
|
"""Убирает из переданной строки все не цифровые символы."""
|
|
return u''.join(c for c in value if c.isdigit())
|
|
|
|
|
|
def mail_exception(subject, message, e):
|
|
return mail_admins(subject, u'%s\n\n%s' % (message, traceback.format_exc(e),))
|
|
|