本文整理汇总了Python中error.models.Error.error_timestamp_date方法的典型用法代码示例。如果您正苦于以下问题:Python Error.error_timestamp_date方法的具体用法?Python Error.error_timestamp_date怎么用?Python Error.error_timestamp_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类error.models.Error
的用法示例。
在下文中一共展示了Error.error_timestamp_date方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: populate
# 需要导入模块: from error.models import Error [as 别名]
# 或者: from error.models.Error import error_timestamp_date [as 别名]
def populate(incoming):
""" Populate the error table with the incoming error """
# special lookup the account
err = Error()
uid = incoming.get("account", "")
if not settings.ANONYMOUS_POSTING:
if not uid:
raise ValueError, "Missing the required account number."
if str(uid) != settings.ARECIBO_PUBLIC_ACCOUNT_NUMBER:
raise ValueError, "Account number does not match"
# special
if incoming.has_key("url"):
for k, v in break_url(incoming["url"]).items():
setattr(err, k, v)
# check the status codes
if incoming.has_key("status"):
status = str(incoming["status"])
try:
valid_status(status)
err.status = status
except StatusDoesNotExist:
err.errors += "Status does not exist, ignored.\n"
# not utf-8 encoded
for src, dest in [
("ip", "ip"),
("user_agent", "user_agent"),
("uid", "uid"),
]:
actual = incoming.get(src, None)
if actual is not None:
setattr(err, dest, str(actual))
try:
priority = int(incoming.get("priority", 0))
except ValueError:
priority = 0
err.priority = min(priority, 10)
# possibly utf-8 encoding
for src, dest in [
("type", "type"),
("msg", "msg"),
("server", "server"),
("traceback", "traceback"),
("request", "request"),
("username", "username")
]:
actual = incoming.get(src, None)
if actual is not None:
try:
setattr(err, dest, actual.encode("utf-8"))
except UnicodeDecodeError:
err.errors += "Encoding error on the %s field, ignored.\n" % src
# timestamp handling
if incoming.has_key("timestamp"):
tmstmp = incoming["timestamp"].strip()
if tmstmp.endswith("GMT"):
tmstmp = tmstmp[:-3] + "-0000"
tme = parsedate(tmstmp)
if tme:
try:
final = datetime(*tme[:7])
err.error_timestamp = final
err.error_timestamp_date = final.date()
except ValueError, msg:
err.errors += 'Date error on the field "%s", ignored.\n' % msg